• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "dmslite_feature.h"
17 
18 #include "dmslite_famgr.h"
19 #include "dmslite_log.h"
20 #include "dmslite_session.h"
21 
22 #include "ohos_init.h"
23 #include "samgr_lite.h"
24 #include "securec.h"
25 
26 #define EMPTY_FEATURE_NAME ""
27 
28 static const char *GetName(Feature *feature);
29 static void OnInitialize(Feature *feature, Service *parent, Identity identity);
30 static void OnStop(Feature *feature, Identity identity);
31 static BOOL OnMessage(Feature *feature, Request *request);
32 
33 DmsLite g_dmslite = {
34     /* feature functions */
35     .GetName = GetName,
36     .OnInitialize = OnInitialize,
37     .OnStop = OnStop,
38     .OnMessage = OnMessage,
39     .identity = {-1, -1, NULL},
40     /* dms interface for other subsystems */
41     DEFAULT_IUNKNOWN_ENTRY_BEGIN,
42     .StartRemoteAbility = StartRemoteAbilityInner,
43     DEFAULT_IUNKNOWN_ENTRY_END
44 };
45 
GetDmsLiteFeature()46 DmsLite *GetDmsLiteFeature()
47 {
48     return &g_dmslite;
49 }
50 
GetName(Feature * feature)51 static const char *GetName(Feature *feature)
52 {
53     if (feature == NULL) {
54         return EMPTY_FEATURE_NAME;
55     }
56     return DMSLITE_FEATURE;
57 }
58 
OnInitialize(Feature * feature,Service * parent,Identity identity)59 static void OnInitialize(Feature *feature, Service *parent, Identity identity)
60 {
61     if (feature == NULL || parent == NULL) {
62         return;
63     }
64 
65     ((DmsLite*) feature)->identity = identity;
66 }
67 
OnStop(Feature * feature,Identity identity)68 static void OnStop(Feature *feature, Identity identity)
69 {
70     HILOGD("[Feature stop]");
71 }
72 
OnMessage(Feature * feature,Request * request)73 static BOOL OnMessage(Feature *feature, Request *request)
74 {
75     if (feature == NULL || request == NULL) {
76         return FALSE;
77     }
78 
79     /* process for a specific feature-level msgId can be added below */
80     switch (request->msgId) {
81         case START_REMOTE_ABILITY: {
82             if (request->data == NULL) {
83                 InvokeCallback(NULL, DMS_EC_FAILURE);
84                 HILOGE("[START_REMOTE_ABILITY request is NULL]");
85                 return FALSE;
86             }
87             const RequestData *data = (const RequestData *)request->data;
88             int32_t result = StartRemoteAbility(data->want, data->callerInfo, data->callback);
89             FreeRequestData(data->want, data->callerInfo);
90             if (result != DMS_EC_SUCCESS) {
91                 InvokeCallback(NULL, result);
92             }
93             break;
94         }
95         case SESSION_OPEN:
96             HandleSessionOpened(request->msgValue);
97             break;
98         case SESSION_CLOSE:
99             HandleSessionClosed(request->msgValue);
100             break;
101         case BYTES_RECEIVED:
102             HandleBytesReceived(request->msgValue, request->data, request->len);
103             break;
104         default: {
105             HILOGW("[Unknown msgId = %d]", request->msgId);
106             break;
107         }
108     }
109     return TRUE;
110 }
111 
Init()112 static void Init()
113 {
114     BOOL result = SAMGR_GetInstance()->RegisterFeature(DISTRIBUTED_SCHEDULE_SERVICE, (Feature*) &g_dmslite);
115     if (!result) {
116         HILOGE("[dms register feature failed]");
117     }
118 
119     result = SAMGR_GetInstance()->RegisterFeatureApi(DISTRIBUTED_SCHEDULE_SERVICE,
120         DMSLITE_FEATURE, GET_IUNKNOWN(g_dmslite));
121     if (!result) {
122         HILOGE("[dms register feature api failed]");
123     }
124 }
125 SYS_FEATURE_INIT(Init);
126