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 "bundle_ms_host.h"
17
18 #include <pthread.h>
19
20 #include "bundle_inner_interface.h"
21 #include "bundle_manager_service.h"
22 #include "bundle_log.h"
23 #include "ohos_init.h"
24 #include "samgr_lite.h"
25
26 namespace OHOS {
27 const int STACK_SIZE = 0x800;
28 const int QUEUE_SIZE = 20;
29
BundleMsHost()30 BundleMsHost::BundleMsHost() : Service()
31 {
32 this->Service::GetName = BundleMsHost::GetServiceName;
33 this->Service::Initialize = BundleMsHost::ServiceInitialize;
34 this->Service::MessageHandle = BundleMsHost::ServiceMessageHandle;
35 this->Service::GetTaskConfig = BundleMsHost::GetServiceTaskConfig;
36 }
37
Init()38 static void Init()
39 {
40 SamgrLite *sm = SAMGR_GetInstance();
41 if (sm == nullptr) {
42 HILOG_ERROR(HILOG_MODULE_APP, "BundleMS init failed");
43 return;
44 }
45 sm->RegisterService(reinterpret_cast<Service *>(BundleMsHost::GetInstance()));
46 HILOG_DEBUG(HILOG_MODULE_APP, "BundleMS start success");
47 }
48 APP_SERVICE_INIT(Init);
49
GetServiceName(Service * service)50 const char *BundleMsHost::GetServiceName(Service *service)
51 {
52 (void)service;
53 return BMS_SERVICE;
54 }
55
ServiceInitialize(Service * service,Identity identity)56 BOOL BundleMsHost::ServiceInitialize(Service *service, Identity identity)
57 {
58 if (service == nullptr) {
59 return FALSE;
60 }
61
62 BundleMsHost *bundleMsHost = reinterpret_cast<BundleMsHost *>(service);
63 bundleMsHost->identity_ = identity;
64 return TRUE;
65 }
66
ServiceMessageHandle(Service * service,Request * request)67 BOOL BundleMsHost::ServiceMessageHandle(Service *service, Request *request)
68 {
69 if (request == nullptr) {
70 return FALSE;
71 }
72 return TRUE;
73 }
74
GetServiceTaskConfig(Service * service)75 TaskConfig BundleMsHost::GetServiceTaskConfig(Service *service)
76 {
77 TaskConfig config = {LEVEL_HIGH, PRI_NORMAL, STACK_SIZE, QUEUE_SIZE, SINGLE_TASK};
78 return config;
79 }
80 } // namespace OHOS
81