1 /* 2 * Copyright (c) 2024-2025 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_DSCHED_COLLAB_EVENT_H 17 #define OHOS_DSCHED_COLLAB_EVENT_H 18 19 #include <string> 20 21 #include "ability_info.h" 22 #include "caller_info.h" 23 #include "cJSON.h" 24 #include "distributed_sched_interface.h" 25 #include "want.h" 26 27 namespace OHOS { 28 namespace DistributedSchedule { 29 typedef enum { 30 SOURCE_GET_PEER_VERSION_EVENT = 0, 31 SOURCE_GET_VERSION_EVENT, 32 SOURCE_START_EVENT, 33 NOTIFY_RESULT_EVENT, 34 GET_SINK_VERSION_EVENT, 35 START_ABILITY_EVENT, 36 NOTIFY_PREPARE_RESULT_EVENT, 37 ERR_END_EVENT, 38 END_EVENT, 39 ABILITY_REJECT_EVENT, 40 } DSchedCollabEventType; 41 42 typedef enum { 43 MIN_CMD = 0, 44 SINK_GET_VERSION_CMD, 45 SOURCE_GET_VERSION_CMD, 46 SINK_START_CMD, 47 NOTIFY_RESULT_CMD, 48 DISCONNECT_CMD, 49 MAX_CMD, 50 } DSchedCollabCommand; 51 52 class BaseCmd { 53 public: 54 BaseCmd() = default; 55 virtual ~BaseCmd() = default; 56 virtual int32_t Marshal(std::string &jsonStr); 57 virtual int32_t Unmarshal(const std::string &jsonStr); 58 public: 59 bool needSendBigData_ = false; 60 bool needSendStream_ = false; 61 bool needRecvStream_ = false; 62 int32_t collabVersion_ = -1; 63 int32_t dmsVersion_ = -1; 64 int32_t command_ = -1; 65 int32_t srcCollabSessionId_ = -1; 66 int32_t appVersion_ = -1; 67 std::string collabToken_; 68 std::string srcDeviceId_; 69 std::string srcBundleName_; 70 std::string srcAbilityName_; 71 std::string srcModuleName_; 72 std::string srcServerId_; 73 std::string sinkDeviceId_; 74 std::string sinkBundleName_; 75 std::string sinkAbilityName_; 76 std::string sinkModuleName_; 77 std::string sinkServerId_; 78 }; 79 80 class GetSinkCollabVersionCmd : public BaseCmd { 81 public: 82 int32_t Marshal(std::string &jsonStr); 83 int32_t Unmarshal(const std::string &jsonStr); 84 85 public: 86 int32_t srcPid_ = -1; 87 int32_t srcUid_ = -1; 88 int32_t srcAccessToken_ = -1; 89 int32_t sinkCollabVersion_ = -1; 90 }; 91 92 class SinkStartCmd : public BaseCmd { 93 public: 94 int32_t Marshal(std::string &jsonStr); 95 int32_t Unmarshal(const std::string &jsonStr); 96 97 private: 98 int32_t MarshalCallerInfo(std::string &jsonStr); 99 int32_t MarshalAccountInfo(std::string &jsonStr); 100 int32_t UnmarshalParcel(const std::string &jsonStr); 101 int32_t UnmarshalPartParcel(cJSON *rootValue); 102 int32_t UnmarshalOptParams(cJSON *rootValue); 103 int32_t UnmarshalCallerInfo(std::string &jsonStr); 104 int32_t UnmarshalCallerInfoExtra(std::string &jsonStr); 105 int32_t UnmarshalAccountInfo(std::string &jsonStr); 106 107 public: 108 int32_t srcPid_ = -1; 109 int32_t srcUid_ = -1; 110 int32_t srcAccessToken_ = -1; 111 int32_t appVersion_ = -1; 112 CallerInfo callerInfo_; 113 IDistributedSched::AccountInfo accountInfo_; 114 AAFwk::WantParams startParams_; 115 AAFwk::WantParams messageParams_; 116 }; 117 118 class NotifyResultCmd : public BaseCmd { 119 public: 120 int32_t Marshal(std::string &jsonStr); 121 int32_t Unmarshal(const std::string &jsonStr); 122 int32_t UnmarshalSinkInfo(cJSON *rootValue); 123 124 public: 125 int32_t result_ = -1; 126 int32_t sinkCollabSessionId_ = -1; 127 int32_t sinkPid_ = -1; 128 int32_t sinkAccessToken_ = -1; 129 int32_t sinkUserId_ = -1; 130 int32_t sinkAccountId_ = -1; 131 std::string sinkSocketName_; 132 std::string abilityRejectReason_; 133 }; 134 135 class DisconnectCmd : public BaseCmd { 136 public: 137 int32_t Marshal(std::string &jsonStr); 138 int32_t Unmarshal(const std::string &jsonStr); 139 140 public: 141 }; 142 } // namespace DistributedSchedule 143 } // namespace OHOS 144 #endif // OHOS_DSCHED_COLLAB_EVENT_H 145