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_init.h"
17
18 #include "common.h"
19 #include "iproxy_server.h"
20 #include "mini_service.h"
21 #include "samgr_lite.h"
22 #include "service.h"
23 #include "stdio.h"
24
25 #define MINI_SERVICE "mini_sa_rpc"
26 static const char *GetName(Service *service);
27 static BOOL Initialize(Service *service, Identity identity);
28 static TaskConfig GetTaskConfig(Service *service);
29 static BOOL MessageHandle(Service *service, Request *request);
30 static int32_t FeatureInvoke(IServerProxy *iProxy, int32_t funcId, void *origin, IpcIo *req, IpcIo *reply);
31
32 static MiniService g_miniService = {
33 .GetName = GetName,
34 .Initialize = Initialize,
35 .MessageHandle = MessageHandle,
36 .GetTaskConfig = GetTaskConfig,
37 SERVER_IPROXY_IMPL_BEGIN,
38 .Invoke = FeatureInvoke,
39 IPROXY_END,
40 };
41 extern void CallOnPlayRemote(int32_t data);
FeatureInvoke(IServerProxy * iProxy,int32_t funcId,void * origin,IpcIo * req,IpcIo * reply)42 static int32_t FeatureInvoke(IServerProxy *iProxy, int32_t funcId, void *origin, IpcIo *req, IpcIo *reply)
43 {
44 int32_t data;
45 ReadInt32(req, &data);
46 CallOnPlayRemote(data);
47 return 0;
48 }
49
Init(void)50 static void Init(void)
51 {
52 SAMGR_GetInstance()->RegisterService((Service *)&g_miniService);
53 SAMGR_GetInstance()->RegisterDefaultFeatureApi(MINI_SERVICE, GET_IUNKNOWN(g_miniService));
54 }
55 SYS_SERVICE_INIT(Init);
56
GetName(Service * service)57 static const char *GetName(Service *service)
58 {
59 (void)service;
60 return MINI_SERVICE;
61 }
62
IsDistributed(void)63 static BOOL IsDistributed(void)
64 {
65 return TRUE;
66 }
67
Initialize(Service * service,Identity identity)68 static BOOL Initialize(Service *service, Identity identity)
69 {
70 MiniService *miniSa = NULL;
71
72 if (service == NULL) {
73 return FALSE;
74 }
75 miniSa = (MiniService *)service;
76 miniSa->identity = identity;
77 /* The communication of task can be use after the service is running. */
78 return TRUE;
79 }
80
MessageHandle(Service * service,Request * request)81 static BOOL MessageHandle(Service *service, Request *request)
82 {
83 (void)service;
84 (void)request;
85 return TRUE;
86 }
87
GetTaskConfig(Service * service)88 static TaskConfig GetTaskConfig(Service *service)
89 {
90 (void)service;
91 TaskConfig config = { LEVEL_LOW, PRI_NORMAL, 0x2000, 10, SINGLE_TASK };
92 return config;
93 }
94