• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024 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  * Description: connection class
15  * Author: sunhong
16  * Create: 2022-01-19
17  */
18 
19 #ifndef CONNECTION_H
20 #define CONNECTION_H
21 
22 #include "channel_request.h"
23 #include "connection_listener.h"
24 
25 namespace OHOS {
26 namespace CastEngine {
27 namespace CastEngineService {
28 class Connection {
29 public:
~Connection()30     virtual ~Connection() {};
31 
SetConnectionListener(std::shared_ptr<ConnectionListener> listener)32     virtual void SetConnectionListener(std::shared_ptr<ConnectionListener> listener)
33     {
34         listener_ = listener;
35     }
36 
37     // init request when openConnection or startListen
StashRequest(const ChannelRequest & request)38     virtual void StashRequest(const ChannelRequest &request)
39     {
40         channelRequest_ = request;
41     }
42 
43     // Open the connection asynchronously.
StartConnection(const ChannelRequest & request,std::shared_ptr<IChannelListener> channelListener)44     virtual int StartConnection(const ChannelRequest &request, std::shared_ptr<IChannelListener> channelListener)
45     {
46         return -1;
47     }
48 
49     /*
50      * Start listening for device channel connections.
51      * When the channel type is VTP or TCP, the return value represents the port number, and a negative value
52      * represents failure.
53      * When the channel type is softbus, the return value of 0 indicates successful registration and listening,
54      * and a negative value represents failure.
55      *
56      * @param request channel unique ID
57      * @return Results of starting listening
58      */
StartListen(const ChannelRequest & request,std::shared_ptr<IChannelListener> channelListener)59     virtual int StartListen(const ChannelRequest &request, std::shared_ptr<IChannelListener> channelListener)
60     {
61         return -1;
62     }
63 
64     // Close connection and all channels
CloseConnection()65     virtual void CloseConnection() {};
66 
67 protected:
68     ChannelRequest channelRequest_;
69     std::shared_ptr<ConnectionListener> listener_;
70 };
71 } // namespace CastEngineService
72 } // namespace CastEngine
73 } // namespace OHOS
74 
75 
76 #endif // CONNECTION_H
77