1 /*
2 * Copyright (C) 2021-2023 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 "group_manager.h"
17
18 #include "common_defs.h"
19 #include "data_manager.h"
20 #include "group_operation.h"
21 #include "hc_log.h"
22 #include "hitrace_adapter.h"
23
CreateGroupImpl(int32_t osAccountId,int64_t requestId,const char * appId,const char * createParams)24 int32_t CreateGroupImpl(int32_t osAccountId, int64_t requestId, const char *appId, const char *createParams)
25 {
26 SET_LOG_MODE(TRACE_MODE);
27 SET_TRACE_ID(requestId);
28 return IsGroupSupport() ? GetGroupImplInstance()->createGroup(osAccountId, requestId, appId, createParams)
29 : HC_ERR_NOT_SUPPORT;
30 }
31
DeleteGroupImpl(int32_t osAccountId,int64_t requestId,const char * appId,const char * disbandParams)32 int32_t DeleteGroupImpl(int32_t osAccountId, int64_t requestId, const char *appId, const char *disbandParams)
33 {
34 SET_LOG_MODE(TRACE_MODE);
35 SET_TRACE_ID(requestId);
36 return IsGroupSupport() ? GetGroupImplInstance()->deleteGroup(osAccountId, requestId, appId, disbandParams)
37 : HC_ERR_NOT_SUPPORT;
38 }
39
DeleteMemberFromGroupImpl(int32_t osAccountId,int64_t requestId,const char * appId,const char * deleteParams)40 int32_t DeleteMemberFromGroupImpl(int32_t osAccountId, int64_t requestId, const char *appId, const char *deleteParams)
41 {
42 SET_LOG_MODE(TRACE_MODE);
43 SET_TRACE_ID(requestId);
44 return IsGroupSupport() ? GetGroupImplInstance()->deleteMember(osAccountId, requestId, appId, deleteParams)
45 : HC_ERR_NOT_SUPPORT;
46 }
47
AddMultiMembersToGroupImpl(int32_t osAccountId,const char * appId,const char * addParams)48 int32_t AddMultiMembersToGroupImpl(int32_t osAccountId, const char *appId, const char *addParams)
49 {
50 SET_LOG_MODE(NORMAL_MODE);
51 return IsGroupSupport() ? GetGroupImplInstance()->addMultiMembers(osAccountId, appId, addParams)
52 : HC_ERR_NOT_SUPPORT;
53 }
54
DelMultiMembersFromGroupImpl(int32_t osAccountId,const char * appId,const char * deleteParams)55 int32_t DelMultiMembersFromGroupImpl(int32_t osAccountId, const char *appId, const char *deleteParams)
56 {
57 SET_LOG_MODE(NORMAL_MODE);
58 return IsGroupSupport() ? GetGroupImplInstance()->delMultiMembers(osAccountId, appId, deleteParams)
59 : HC_ERR_NOT_SUPPORT;
60 }
61
RegListenerImpl(const char * appId,const DataChangeListener * listener)62 int32_t RegListenerImpl(const char *appId, const DataChangeListener *listener)
63 {
64 SET_LOG_MODE(NORMAL_MODE);
65 return IsGroupSupport() ? GetGroupImplInstance()->regListener(appId, listener) : HC_ERR_NOT_SUPPORT;
66 }
67
UnRegListenerImpl(const char * appId)68 int32_t UnRegListenerImpl(const char *appId)
69 {
70 SET_LOG_MODE(NORMAL_MODE);
71 return IsGroupSupport() ? GetGroupImplInstance()->unRegListener(appId) : HC_ERR_NOT_SUPPORT;
72 }
73
GetRegisterInfoImpl(const char * reqJsonStr,char ** returnRegisterInfo)74 int32_t GetRegisterInfoImpl(const char *reqJsonStr, char **returnRegisterInfo)
75 {
76 SET_LOG_MODE(NORMAL_MODE);
77 return IsGroupSupport() ? GetGroupImplInstance()->getRegisterInfo(reqJsonStr, returnRegisterInfo)
78 : HC_ERR_NOT_SUPPORT;
79 }
80
CheckAccessToGroupImpl(int32_t osAccountId,const char * appId,const char * groupId)81 int32_t CheckAccessToGroupImpl(int32_t osAccountId, const char *appId, const char *groupId)
82 {
83 SET_LOG_MODE(NORMAL_MODE);
84 return IsGroupSupport() ? GetGroupImplInstance()->checkAccessToGroup(osAccountId, appId, groupId)
85 : HC_ERR_NOT_SUPPORT;
86 }
87
GetGroupInfoByIdImpl(int32_t osAccountId,const char * appId,const char * groupId,char ** returnGroupInfo)88 int32_t GetGroupInfoByIdImpl(int32_t osAccountId, const char *appId, const char *groupId, char **returnGroupInfo)
89 {
90 SET_LOG_MODE(NORMAL_MODE);
91 return IsGroupSupport() ? GetGroupImplInstance()->getAccessibleGroupInfoById(osAccountId, appId, groupId,
92 returnGroupInfo) : HC_ERR_NOT_SUPPORT;
93 }
94
GetGroupInfoImpl(int32_t osAccountId,const char * appId,const char * queryParams,char ** returnGroupVec,uint32_t * groupNum)95 int32_t GetGroupInfoImpl(int32_t osAccountId, const char *appId, const char *queryParams,
96 char **returnGroupVec, uint32_t *groupNum)
97 {
98 SET_LOG_MODE(NORMAL_MODE);
99 return IsGroupSupport() ? GetGroupImplInstance()->getAccessibleGroupInfo(osAccountId, appId, queryParams,
100 returnGroupVec, groupNum) : HC_ERR_NOT_SUPPORT;
101 }
102
GetJoinedGroupsImpl(int32_t osAccountId,const char * appId,int groupType,char ** returnGroupVec,uint32_t * groupNum)103 int32_t GetJoinedGroupsImpl(int32_t osAccountId, const char *appId, int groupType,
104 char **returnGroupVec, uint32_t *groupNum)
105 {
106 SET_LOG_MODE(NORMAL_MODE);
107 return IsGroupSupport() ? GetGroupImplInstance()->getAccessibleJoinedGroups(osAccountId, appId, groupType,
108 returnGroupVec, groupNum) : HC_ERR_NOT_SUPPORT;
109 }
110
GetRelatedGroupsImpl(int32_t osAccountId,const char * appId,const char * peerDeviceId,char ** returnGroupVec,uint32_t * groupNum)111 int32_t GetRelatedGroupsImpl(int32_t osAccountId, const char *appId, const char *peerDeviceId,
112 char **returnGroupVec, uint32_t *groupNum)
113 {
114 SET_LOG_MODE(NORMAL_MODE);
115 return IsGroupSupport() ? GetGroupImplInstance()->getAccessibleRelatedGroups(osAccountId, appId, peerDeviceId,
116 false, returnGroupVec, groupNum) : HC_ERR_NOT_SUPPORT;
117 }
118
GetDeviceInfoByIdImpl(int32_t osAccountId,const char * appId,const char * deviceId,const char * groupId,char ** returnDeviceInfo)119 int32_t GetDeviceInfoByIdImpl(int32_t osAccountId, const char *appId, const char *deviceId, const char *groupId,
120 char **returnDeviceInfo)
121 {
122 SET_LOG_MODE(NORMAL_MODE);
123 DeviceQueryParams devQueryParams = { deviceId, false };
124 return IsGroupSupport() ? GetGroupImplInstance()->getAccessibleDeviceInfoById(osAccountId, appId, &devQueryParams,
125 groupId, returnDeviceInfo) : HC_ERR_NOT_SUPPORT;
126 }
127
GetTrustedDevicesImpl(int32_t osAccountId,const char * appId,const char * groupId,char ** returnDevInfoVec,uint32_t * deviceNum)128 int32_t GetTrustedDevicesImpl(int32_t osAccountId, const char *appId, const char *groupId,
129 char **returnDevInfoVec, uint32_t *deviceNum)
130 {
131 SET_LOG_MODE(NORMAL_MODE);
132 return IsGroupSupport() ? GetGroupImplInstance()->getAccessibleTrustedDevices(osAccountId, appId, groupId,
133 returnDevInfoVec, deviceNum) : HC_ERR_NOT_SUPPORT;
134 }
135
IsDeviceInGroupImpl(int32_t osAccountId,const char * appId,const char * groupId,const char * deviceId)136 bool IsDeviceInGroupImpl(int32_t osAccountId, const char *appId, const char *groupId, const char *deviceId)
137 {
138 SET_LOG_MODE(NORMAL_MODE);
139 return IsGroupSupport() ? GetGroupImplInstance()->isDeviceInAccessibleGroup(osAccountId, appId, groupId,
140 deviceId, false) : false;
141 }
142
GetPkInfoListImpl(int32_t osAccountId,const char * appId,const char * queryParams,char ** returnInfoList,uint32_t * returnInfoNum)143 int32_t GetPkInfoListImpl(int32_t osAccountId, const char *appId, const char *queryParams,
144 char **returnInfoList, uint32_t *returnInfoNum)
145 {
146 SET_LOG_MODE(NORMAL_MODE);
147 return IsGroupSupport() ? GetGroupImplInstance()->getPkInfoList(osAccountId, appId, queryParams,
148 returnInfoList, returnInfoNum) : HC_ERR_NOT_SUPPORT;
149 }
150
DestroyInfoImpl(char ** returnInfo)151 void DestroyInfoImpl(char **returnInfo)
152 {
153 if (IsGroupSupport()) {
154 GetGroupImplInstance()->destroyInfo(returnInfo);
155 }
156 }
157
InitGroupManager(void)158 int32_t InitGroupManager(void)
159 {
160 if (InitDatabase() != HC_SUCCESS) {
161 return HC_ERR_SERVICE_NEED_RESTART;
162 }
163 return IsGroupSupport() ? InitGroupRelatedModule() : HC_SUCCESS;
164 }
165
DestroyGroupManager(void)166 void DestroyGroupManager(void)
167 {
168 if (IsGroupSupport()) {
169 DestroyGroupRelatedModule();
170 }
171 DestroyDatabase();
172 }