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