1 /*
2  * Copyright (c) 2020-2021 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 
19 #include "feature.h"
20 #include "gfx_utils/graphic_log.h"
21 #include "input_event_client_proxy.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 namespace OHOS {
29 struct DefaultFeatureApi {
30     INHERIT_SERVER_IPROXY;
31 };
32 
33 struct IMSService {
34     INHERIT_SERVICE;
35     INHERIT_IUNKNOWNENTRY(DefaultFeatureApi);
36     Identity identity;
37 };
38 
GetName(Service * service)39 static const char* GetName(Service* service)
40 {
41     (void)service;
42     return IMS_SERVICE_NAME;
43 }
44 
Initialize(Service * service,Identity identity)45 static BOOL Initialize(Service* service, Identity identity)
46 {
47     IMSService* example = reinterpret_cast<IMSService*>(service);
48     example->identity = identity;
49     GRAPHIC_LOGI("Initialize(%s)! Identity<%d, %d, %p>", IMS_SERVICE_NAME,
50         identity.serviceId, identity.featureId, identity.queueId);
51     return TRUE;
52 }
53 
MessageHandle(Service * service,Request * msg)54 static BOOL MessageHandle(Service* service, Request* msg)
55 {
56     GRAPHIC_LOGI("MessageHandle(%s)! Request<%d, %d, %p>",
57         service->GetName(service), msg->msgId, msg->msgValue, msg->data);
58     return FALSE;
59 }
60 
GetTaskConfig(Service * service)61 static TaskConfig GetTaskConfig(Service* service)
62 {
63     (void)service;
64     TaskConfig config = {LEVEL_HIGH, PRI_BELOW_NORMAL, 0x800, 20, SHARED_TASK};
65     return config;
66 }
67 
Invoke(IServerProxy * iProxy,int funcId,void * origin,IpcIo * req,IpcIo * reply)68 static int32 Invoke(IServerProxy* iProxy, int funcId, void* origin, IpcIo* req, IpcIo* reply)
69 {
70     InputEventClientProxy::GetInstance()->ClientRequestHandle(funcId, origin, req, reply);
71     return EC_SUCCESS;
72 }
73 
74 static IMSService g_example = {
75     .GetName = GetName,
76     .Initialize = Initialize,
77     .MessageHandle = MessageHandle,
78     .GetTaskConfig = GetTaskConfig,
79     SERVER_IPROXY_IMPL_BEGIN,
80     .Invoke = Invoke,
81     IPROXY_END,
82 };
83 
Init(void)84 static void Init(void)
85 {
86     BOOL ret = SAMGR_GetInstance()->RegisterService(reinterpret_cast<Service*>(&g_example));
87     if (ret != TRUE) {
88         GRAPHIC_LOGE("regist service failed.");
89         return;
90     }
91     ret = SAMGR_GetInstance()->RegisterDefaultFeatureApi(IMS_SERVICE_NAME, GET_IUNKNOWN(g_example));
92     if (ret != TRUE) {
93         GRAPHIC_LOGE("regist feature failed.");
94         return;
95     }
96 }
97 
98 SYSEX_SERVICE_INIT(Init);
99 } // namespace OHOS