1 /* 2 * Copyright (C) 2021 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_IPC_DBINDER_SESSION_OBJECT_H 17 #define OHOS_IPC_DBINDER_SESSION_OBJECT_H 18 19 #include <string> 20 #include <mutex> 21 #include "nocopyable.h" 22 #include "buffer_object.h" 23 24 #include "rpc_feature_set.h" 25 #include "Session.h" 26 #include "ISessionService.h" 27 28 using Communication::SoftBus::ISessionService; 29 using Communication::SoftBus::Session; 30 31 namespace OHOS { 32 constexpr int DEVICEID_LENGTH = 64; 33 constexpr int SERVICENAME_LENGTH = 200; 34 35 /* struct FlatDBinderSession is for flat DatabusSessionObject to transfer to another device */ 36 struct FlatDBinderSession { 37 uint64_t stubIndex; 38 uint16_t deviceIdLength; 39 uint16_t serviceNameLength; 40 char deviceId[DEVICEID_LENGTH + 1]; 41 char serviceName[SERVICENAME_LENGTH + 1]; 42 }; 43 44 class DBinderSessionObject { 45 public: 46 static uint32_t GetFlatSessionLen(); 47 explicit DBinderSessionObject(std::shared_ptr<Session> session, const std::string &serviceName, 48 const std::string &serverDeviceId); 49 50 ~DBinderSessionObject(); 51 52 void SetBusSession(std::shared_ptr<Session> session); 53 void SetServiceName(const std::string &serviceName); 54 void SetDeviceId(const std::string &serverDeviceId); 55 void SetFeatureSet(std::shared_ptr<FeatureSetData> rpcFeatureSet); 56 std::shared_ptr<BufferObject> GetSessionBuff(); 57 std::shared_ptr<Session> GetBusSession() const; 58 std::string GetServiceName() const; 59 std::string GetDeviceId() const; 60 std::shared_ptr<FeatureSetData> GetFeatureSet() const; 61 uint32_t GetSessionHandle() const; 62 void CloseDatabusSession(); 63 64 private: 65 DISALLOW_COPY_AND_MOVE(DBinderSessionObject); 66 /* Session is defined from softBus session, when import socket driver, we need use interface abstraction */ 67 std::shared_ptr<Session> session_; 68 std::mutex buffMutex_; 69 std::shared_ptr<BufferObject> buff_; 70 std::string serviceName_; 71 std::string serverDeviceId_; 72 std::shared_ptr<FeatureSetData> rpcFeatureSet_; 73 }; 74 } // namespace OHOS 75 #endif // OHOS_IPC_DBINDER_SESSION_OBJECT_H