1 /*
2  * Copyright (c) 2020 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include <ohos_errno.h>
17 #include <ohos_init.h>
18 #include <cstdio>
19 
20 #include "feature.h"
21 #include "media_log.h"
22 #include "iproxy_client.h"
23 #include "iproxy_server.h"
24 #include "iunknown.h"
25 #include "samgr_lite.h"
26 #include "service.h"
27 
28 #include "camera_type.h"
29 #include "camera_server.h"
30 
31 namespace OHOS {
32 struct DefaultFeatureApi {
33     INHERIT_SERVER_IPROXY;
34 };
35 
36 struct CameraService {
37     INHERIT_SERVICE;
38     INHERIT_IUNKNOWNENTRY(DefaultFeatureApi);
39     Identity identity;
40 };
41 
GetName(Service * service)42 static const char* GetName(Service* service)
43 {
44     (void)service;
45     return Media::SERVICE_NAME;
46 }
47 
Initialize(Service * service,Identity identity)48 static BOOL Initialize(Service* service, Identity identity)
49 {
50     if (service == nullptr) {
51         return FALSE;
52     }
53     CameraService* example = (CameraService*)service;
54     example->identity = identity;
55     MEDIA_INFO_LOG("Initialize(%s)! Identity<%d, %d>", Media::SERVICE_NAME,
56         identity.serviceId, identity.featureId);
57     return TRUE;
58 }
59 
MessageHandle(Service * service,Request * msg)60 static BOOL MessageHandle(Service* service, Request* msg)
61 {
62     if (service == nullptr || msg == nullptr) {
63         return FALSE;
64     }
65     MEDIA_INFO_LOG("MessageHandle(%s)! Request<%d, %d>",
66         service->GetName(service), msg->msgId, msg->msgValue);
67     return FALSE;
68 }
69 
GetTaskConfig(Service * service)70 static TaskConfig GetTaskConfig(Service* service)
71 {
72     (void)service;
73     TaskConfig config = {LEVEL_HIGH, PRI_BELOW_NORMAL, 0x800, 20, SHARED_TASK};
74     return config;
75 }
76 
Invoke(IServerProxy * iProxy,int funcId,void * origin,IpcIo * req,IpcIo * reply)77 static int32 Invoke(IServerProxy* iProxy, int funcId, void* origin, IpcIo* req, IpcIo* reply)
78 {
79     Media::CameraServer::CameraServerRequestHandle(funcId, origin, req, reply);
80     return EC_SUCCESS;
81 }
82 
83 static CameraService g_example = {
84     .GetName = GetName,
85     .Initialize = Initialize,
86     .MessageHandle = MessageHandle,
87     .GetTaskConfig = GetTaskConfig,
88     SERVER_IPROXY_IMPL_BEGIN,
89     .Invoke = Invoke,
90     IPROXY_END,
91 };
92 
Init(void)93 static void Init(void)
94 {
95     SAMGR_GetInstance()->RegisterService((Service*)&g_example);
96     SAMGR_GetInstance()->RegisterDefaultFeatureApi(Media::SERVICE_NAME, GET_IUNKNOWN(g_example));
97 }
98 
99 SYSEX_SERVICE_INIT(Init);
100 } // namespace OHOS