• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024 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 OHOS_DM_TRANSPORT_MSG_H
17 #define OHOS_DM_TRANSPORT_MSG_H
18 
19 #include <string>
20 #include <cJSON.h>
21 
22 namespace OHOS {
23 namespace DistributedHardware {
24 struct UserIdsMsg {
25     std::vector<uint32_t> foregroundUserIds;
26     std::vector<uint32_t> backgroundUserIds;
27     bool isNewEvent;
UserIdsMsgUserIdsMsg28     UserIdsMsg() : foregroundUserIds({}), backgroundUserIds({}), isNewEvent(false) {}
UserIdsMsgUserIdsMsg29     UserIdsMsg(std::vector<uint32_t> foregroundUserIds, std::vector<uint32_t> backgroundUserIds, bool isNewEvent)
30         : foregroundUserIds(foregroundUserIds), backgroundUserIds(backgroundUserIds), isNewEvent(isNewEvent) {}
31 };
32 
33 void ToJson(cJSON *jsonObject, const UserIdsMsg &userIdsMsg);
34 void FromJson(const cJSON *jsonObject, UserIdsMsg &userIdsMsg);
35 
36 struct CommMsg {
37     int32_t code;
38     std::string msg;
CommMsgCommMsg39     CommMsg() : code(-1), msg("") {}
CommMsgCommMsg40     CommMsg(int32_t code, std::string msg) : code(code), msg(msg) {}
41 };
42 
43 void ToJson(cJSON *jsonObject, const CommMsg &commMsg);
44 void FromJson(const cJSON *jsonObject, CommMsg &commMsg);
45 
46 std::string GetCommMsgString(const CommMsg &commMsg);
47 
48 struct InnerCommMsg {
49     std::string remoteNetworkId;
50     std::shared_ptr<CommMsg> commMsg;
51     int32_t socketId = 0;
InnerCommMsgInnerCommMsg52     InnerCommMsg(std::string remoteNetworkId, std::shared_ptr<CommMsg> commMsg, int32_t socketId)
53         : remoteNetworkId(remoteNetworkId), commMsg(commMsg), socketId(socketId) {}
54 };
55 
56 struct NotifyUserIds {
57     std::string remoteUdid;
58     std::vector<uint32_t> userIds;
NotifyUserIdsNotifyUserIds59     NotifyUserIds() : remoteUdid(""), userIds({}) {}
NotifyUserIdsNotifyUserIds60     NotifyUserIds(std::string remoteUdid, std::vector<uint32_t> userIds)
61         : remoteUdid(remoteUdid), userIds(userIds) {}
62 
63     std::string ToString();
64 };
65 
66 void ToJson(cJSON *jsonObject, const NotifyUserIds &userIds);
67 void FromJson(const cJSON *jsonObject, NotifyUserIds &userIds);
68 
69 struct LogoutAccountMsg {
70     std::string accountId;
71     int32_t userId;
LogoutAccountMsgLogoutAccountMsg72     LogoutAccountMsg() : userId(-1) {}
LogoutAccountMsgLogoutAccountMsg73     LogoutAccountMsg(const std::string &accountId, int32_t userId)
74         : accountId(accountId), userId(userId) {}
75 };
76 
77 void ToJson(cJSON *jsonObject, const LogoutAccountMsg &accountInfo);
78 void FromJson(const cJSON *jsonObject, LogoutAccountMsg &accountInfo);
79 
80 struct UninstAppMsg {
81     int32_t userId_;
82     int32_t tokenId_;
UninstAppMsgUninstAppMsg83     UninstAppMsg() : userId_(-1), tokenId_(-1) {}
UninstAppMsgUninstAppMsg84     UninstAppMsg(int32_t userId, int32_t tokenId)
85         : userId_(userId), tokenId_(tokenId) {}
86 };
87 
88 void ToJson(cJSON *jsonObject, const UninstAppMsg &uninstAppMsg);
89 void FromJson(const cJSON *jsonObject, UninstAppMsg &uninstAppMsg);
90 
91 struct UnBindAppMsg {
92     int32_t userId_;
93     int32_t tokenId_;
94     std::string extra_;
95     std::string udid_;
UnBindAppMsgUnBindAppMsg96     UnBindAppMsg() : userId_(-1), tokenId_(-1), extra_(""), udid_("") {}
UnBindAppMsgUnBindAppMsg97     UnBindAppMsg(int32_t userId, int32_t tokenId, const std::string &extra, const std::string &udid)
98         : userId_(userId), tokenId_(tokenId), extra_(extra), udid_(udid) {}
99 };
100 
101 void ToJson(cJSON *jsonObject, const UnBindAppMsg &unBindAppMsg);
102 void FromJson(const cJSON *jsonObject, UnBindAppMsg &unBindAppMsg);
103 } // DistributedHardware
104 } // OHOS
105 #endif