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 #include "feature.h"
16 #include "iproxy_server.h"
17 #include "media_log.h"
18 #include "recorder_service.h"
19 #include "samgr_lite.h"
20 #include "service.h"
21 #include <ohos_errno.h>
22 #include <ohos_init.h>
23
24 namespace OHOS {
25 namespace Media {
26 struct DefaultFeatureApi {
27 INHERIT_SERVER_IPROXY;
28 };
29
30 typedef struct RecorderService {
31 INHERIT_SERVICE;
32 INHERIT_IUNKNOWNENTRY(DefaultFeatureApi);
33 Identity identity;
34 } RecorderService;
35
GetName(Service * service)36 static const char *GetName(Service *service)
37 {
38 (void)service;
39 return RECORDER_SERVICE_NAME;
40 }
41
Initialize(Service * service,Identity identity)42 static BOOL Initialize(Service *service, Identity identity)
43 {
44 RecorderService *recordSvc = (RecorderService *)service;
45 recordSvc->identity = identity;
46 MEDIA_INFO_LOG("Initialize(%s)! Identity<%d, %d>", RECORDER_SERVICE_NAME, identity.serviceId,
47 identity.featureId);
48 return TRUE;
49 }
50
MessageHandle(Service * service,Request * msg)51 static BOOL MessageHandle(Service *service, Request *msg)
52 {
53 MEDIA_DEBUG_LOG("MessageHandle(%s)! Request<%u, %u>", service->GetName(service), msg->msgId, msg->msgValue);
54 return FALSE;
55 }
56
GetTaskConfig(Service * service)57 static TaskConfig GetTaskConfig(Service *service)
58 {
59 (void)service;
60 TaskConfig config = {LEVEL_HIGH, PRI_BELOW_NORMAL, 0x800, 20, SHARED_TASK};
61 return config;
62 }
63
Invoke(IServerProxy * iProxy,int funcId,void * origin,IpcIo * req,IpcIo * reply)64 static int32 Invoke(IServerProxy *iProxy, int funcId, void *origin, IpcIo *req, IpcIo *reply)
65 {
66 MEDIA_DEBUG_LOG("Service Remote Invoke is called! <%d>", funcId);
67 pid_t pid = GetCallingPid();
68 RecorderClientMng *mng = RecorderClientMng::GetInstance();
69 mng->Dispatch(funcId, pid, req, reply);
70 return EC_SUCCESS;
71 }
72
RecorderServiceReg()73 void RecorderServiceReg()
74 {
75 static RecorderService recorderSvc = {
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 BOOL ret = SAMGR_GetInstance()->RegisterService((Service *)&recorderSvc);
85 if (ret != TRUE) {
86 MEDIA_ERR_LOG("Recorder regist service failed.");
87 return;
88 }
89 ret = SAMGR_GetInstance()->RegisterDefaultFeatureApi(RECORDER_SERVICE_NAME, GET_IUNKNOWN(recorderSvc));
90 if (ret != TRUE) {
91 MEDIA_ERR_LOG("Recorder regist feature failed.");
92 return;
93 }
94 }
95 } // namespace Media
96 } // namespace OHOS