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 #include <ohos_errno.h>
18
19 #include "media_log.h"
20 #include "iproxy_client.h"
21 #include "iproxy_server.h"
22 #include "iunknown.h"
23 #include "samgr_lite.h"
24 #include "feature.h"
25 #include "service.h"
26 #include "player_type.h"
27
28 #include "player_server.h"
29
30 namespace OHOS {
31 struct DefaultFeatureApi {
32 INHERIT_SERVER_IPROXY;
33 };
34
35 struct PlayerService {
36 INHERIT_SERVICE;
37 INHERIT_IUNKNOWNENTRY(DefaultFeatureApi);
38 Identity identity;
39 };
40
GetName(Service * service)41 static const char* GetName(Service* service)
42 {
43 (void)service;
44 return SERVICE_NAME;
45 }
46
Initialize(Service * service,Identity identity)47 static BOOL Initialize(Service* service, Identity identity)
48 {
49 PlayerService* example = (PlayerService*)service;
50 example->identity = identity;
51 MEDIA_INFO_LOG("Initialize(%s)! Identity<%d, %d>\n", SERVICE_NAME, identity.serviceId, identity.featureId);
52 return TRUE;
53 }
54
MessageHandle(Service * service,Request * msg)55 static BOOL MessageHandle(Service* service, Request* msg)
56 {
57 MEDIA_INFO_LOG("MessageHandle(%s)! Request<%u, %u, %s>\n",
58 service->GetName(service), msg->msgId, msg->msgValue, msg->data);
59 return FALSE;
60 }
61
GetTaskConfig(Service * service)62 static TaskConfig GetTaskConfig(Service* service)
63 {
64 (void)service;
65 TaskConfig config = {LEVEL_HIGH, PRI_BELOW_NORMAL, 0x800, 20, SHARED_TASK};
66 return config;
67 }
68
Invoke(IServerProxy * iProxy,int funcId,void * origin,IpcIo * req,IpcIo * reply)69 static int32 Invoke(IServerProxy* iProxy, int funcId, void* origin, IpcIo* req, IpcIo* reply)
70 {
71 Media::PlayerServer::PlayerServerRequestHandle(funcId, origin, req, reply);
72 return EC_SUCCESS;
73 }
74
75 static PlayerService g_example = {
76 .GetName = GetName,
77 .Initialize = Initialize,
78 .MessageHandle = MessageHandle,
79 .GetTaskConfig = GetTaskConfig,
80 SERVER_IPROXY_IMPL_BEGIN,
81 .Invoke = Invoke,
82 IPROXY_END,
83 };
84
Init(void)85 static void Init(void)
86 {
87 SAMGR_GetInstance()->RegisterService((Service*)&g_example);
88 SAMGR_GetInstance()->RegisterDefaultFeatureApi(SERVICE_NAME, GET_IUNKNOWN(g_example));
89 }
90
91 SYSEX_SERVICE_INIT(Init);
92 } // namespace OHOS
93