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 #ifndef LITE_SERVICEIMPL_H
17 #define LITE_SERVICEIMPL_H
18 
19 #include "common.h"
20 #include "iunknown.h"
21 #include "service.h"
22 #include "feature_impl.h"
23 #include "task_manager.h"
24 
25 #ifdef __cplusplus
26 #if __cplusplus
27 extern "C" {
28 #endif
29 #endif
30 
31 enum InitStatus {
32     SVC_INIT = 0,
33     SVC_IDLE,
34     SVC_BUSY,
35 };
36 #ifndef MAX_FEATURE_NUM
37 #define MAX_FEATURE_NUM 0x70
38 #endif
39 typedef struct Operations Operations;
40 struct Operations {
41     uint8 abnormal;
42     uint8 step;
43     uint16 messages;
44     uint32 timestamp;
45 };
46 typedef struct ServiceImpl ServiceImpl;
47 struct ServiceImpl {
48     Service *service;
49     IUnknown *defaultApi;
50     TaskPool *taskPool;
51     Vector features;
52     int16 serviceId;
53     uint8 inited;
54     Operations ops;
55 };
56 
IsInvalidService(Service * service)57 inline static BOOL IsInvalidService(Service *service)
58 {
59     return (service == NULL || service->GetName == NULL || service->Initialize == NULL ||
60             service->GetTaskConfig == NULL || service->MessageHandle == NULL);
61 }
62 
63 int16 DEFAULT_AddFeature(ServiceImpl *serviceImpl, Feature *feature);
64 void DEFAULT_Initialize(ServiceImpl *impl);
65 void DEFAULT_MessageHandle(ServiceImpl *serviceImpl, const Identity *identity, Request *msg);
66 void DEFAULT_StopService(ServiceImpl *service);
67 FeatureImpl *DEFAULT_GetFeature(ServiceImpl *serviceImpl, const char *featureName);
68 Feature *DEFAULT_DeleteFeature(ServiceImpl *serviceImpl, const char *featureName);
69 Identity DEFAULT_GetFeatureId(ServiceImpl *serviceImpl, const char *feature);
70 ServiceImpl *SAMGR_CreateServiceImpl(Service *service, uint8 step);
71 ServiceImpl *SAMGR_GetServiceByID(int16 serviceId);
72 
73 #ifdef __cplusplus
74 #if __cplusplus
75 }
76 #endif
77 #endif
78 #endif // LITE_SERVICEIMPL_H
79