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 #include "ipc_object_proxy.h" 24 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 NOT_SUPPORT_TOKENID_SERVICENAME_LENGTH = 200; 34 constexpr int SUPPORT_TOKENID_SERVICENAME_LENGTH = 64; 35 constexpr int RESERVED_FROM_SERVICENAME_LENGTH = 125; 36 37 /* struct FlatDBinderSession is for flat DatabusSessionObject to transfer to another device */ 38 struct FlatDBinderSession { 39 uint64_t stubIndex; 40 uint16_t deviceIdLength; 41 uint16_t serviceNameLength; 42 char deviceId[DEVICEID_LENGTH + 1]; 43 char serviceName[SUPPORT_TOKENID_SERVICENAME_LENGTH + 1]; 44 uint16_t version; // for alignment 45 uint32_t magic; 46 uint32_t tokenId; 47 char reserved[RESERVED_FROM_SERVICENAME_LENGTH]; 48 // if not support tokenid, this is end of serviceName, which is '\0', this position equal to 49 // NOT_SUPPORT_TOKENID_SERVICENAME_LENGTH = 200 + 1 50 char canNotUse; 51 }; 52 53 class DBinderSessionObject { 54 public: 55 static uint32_t GetFlatSessionLen(); 56 explicit DBinderSessionObject(std::shared_ptr<Session> session, const std::string &serviceName, 57 const std::string &serverDeviceId, uint64_t stubIndex, IPCObjectProxy *proxy, uint32_t tokenId); 58 59 ~DBinderSessionObject(); 60 61 void SetBusSession(std::shared_ptr<Session> session); 62 void SetServiceName(const std::string &serviceName); 63 void SetDeviceId(const std::string &serverDeviceId); 64 void SetProxy(IPCObjectProxy *proxy); 65 std::shared_ptr<BufferObject> GetSessionBuff(); 66 std::shared_ptr<Session> GetBusSession() const; 67 std::string GetServiceName() const; 68 std::string GetDeviceId() const; 69 IPCObjectProxy *GetProxy() const; 70 uint64_t GetStubIndex() const; 71 uint32_t GetSessionHandle() const; 72 void CloseDatabusSession(); 73 uint32_t GetTokenId() const; 74 75 private: 76 DISALLOW_COPY_AND_MOVE(DBinderSessionObject); 77 /* Session is defined from softBus session, when import socket driver, we need use interface abstraction */ 78 std::shared_ptr<Session> session_; 79 std::mutex buffMutex_; 80 std::shared_ptr<BufferObject> buff_; 81 std::string serviceName_; 82 std::string serverDeviceId_; 83 uint64_t stubIndex_; 84 IPCObjectProxy *proxy_; 85 uint32_t tokenId_; 86 }; 87 } // namespace OHOS 88 #endif // OHOS_IPC_DBINDER_SESSION_OBJECT_H