• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_REMOTE_LISTENER_H
17 #define OHOS_IPC_DBINDER_REMOTE_LISTENER_H
18 
19 #include <string>
20 #include <map>
21 #include <mutex>
22 
23 #include "dbinder_service.h"
24 #include "ISessionService.h"
25 #include "Session.h"
26 #include "ISessionListener.h"
27 
28 using Communication::SoftBus::ISessionListener;
29 using Communication::SoftBus::ISessionService;
30 using Communication::SoftBus::Session;
31 
32 namespace OHOS {
33 class DBinderRemoteListener : public ISessionListener {
34 public:
35     DBinderRemoteListener(const sptr<DBinderService> &dBinderService);
36     ~DBinderRemoteListener();
37     int OnSessionOpened(std::shared_ptr<Session> session) override;
38     void OnSessionClosed(std::shared_ptr<Session> session) override;
OnMessageReceived(std::shared_ptr<Session> session,const char * data,ssize_t len)39     void OnMessageReceived(std::shared_ptr<Session> session, const char *data, ssize_t len) override {};
40     void OnBytesReceived(std::shared_ptr<Session> session, const char *data, ssize_t len) override;
OnDataAvailable(std::shared_ptr<Session> session,uint32_t status)41     bool OnDataAvailable(std::shared_ptr<Session> session, uint32_t status) override
42     {
43         return true;
44     };
45 
46     bool SendDataToRemote(const std::string &deviceId, const struct DHandleEntryTxRx *msg);
47     bool StartListener(std::shared_ptr<DBinderRemoteListener> &listener);
48     bool StopListener();
49     bool CloseDatabusSession(const std::string &deviceId);
50 
51 private:
52     std::shared_ptr<Session> OpenSoftbusSession(const std::string &deviceId);
53 
54     const std::string OWN_SESSION_NAME = "DBinderService";
55     const std::string PEER_SESSION_NAME = "DBinderService";
56     static constexpr int PACKET_SIZE = 64 * 1024;
57     static constexpr int SEND_MSG_TIMEOUT_MS = 200;
58 
59     DISALLOW_COPY_AND_MOVE(DBinderRemoteListener);
60     std::mutex busManagerMutex_;
61     sptr<DBinderService> dBinderService_;
62 };
63 } // namespace OHOS
64 #endif // OHOS_IPC_DBINDER_REMOTE_LISTENER_H
65