15e81a82fSopenharmony_ci/* 25e81a82fSopenharmony_ci * Copyright (c) 2024 Huawei Device Co., Ltd. 35e81a82fSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 45e81a82fSopenharmony_ci * you may not use this file except in compliance with the License. 55e81a82fSopenharmony_ci * You may obtain a copy of the License at 65e81a82fSopenharmony_ci * 75e81a82fSopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 85e81a82fSopenharmony_ci * 95e81a82fSopenharmony_ci * Unless required by applicable law or agreed to in writing, software 105e81a82fSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 115e81a82fSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 125e81a82fSopenharmony_ci * See the License for the specific language governing permissions and 135e81a82fSopenharmony_ci * limitations under the License. 145e81a82fSopenharmony_ci * Description: connection class 155e81a82fSopenharmony_ci * Author: sunhong 165e81a82fSopenharmony_ci * Create: 2022-01-19 175e81a82fSopenharmony_ci */ 185e81a82fSopenharmony_ci 195e81a82fSopenharmony_ci#ifndef CONNECTION_H 205e81a82fSopenharmony_ci#define CONNECTION_H 215e81a82fSopenharmony_ci 225e81a82fSopenharmony_ci#include "channel_request.h" 235e81a82fSopenharmony_ci#include "connection_listener.h" 245e81a82fSopenharmony_ci 255e81a82fSopenharmony_cinamespace OHOS { 265e81a82fSopenharmony_cinamespace CastEngine { 275e81a82fSopenharmony_cinamespace CastEngineService { 285e81a82fSopenharmony_ciclass Connection { 295e81a82fSopenharmony_cipublic: 305e81a82fSopenharmony_ci virtual ~Connection() {}; 315e81a82fSopenharmony_ci 325e81a82fSopenharmony_ci virtual void SetConnectionListener(std::shared_ptr<ConnectionListener> listener) 335e81a82fSopenharmony_ci { 345e81a82fSopenharmony_ci listener_ = listener; 355e81a82fSopenharmony_ci } 365e81a82fSopenharmony_ci 375e81a82fSopenharmony_ci // init request when openConnection or startListen 385e81a82fSopenharmony_ci virtual void StashRequest(const ChannelRequest &request) 395e81a82fSopenharmony_ci { 405e81a82fSopenharmony_ci channelRequest_ = request; 415e81a82fSopenharmony_ci } 425e81a82fSopenharmony_ci 435e81a82fSopenharmony_ci // Open the connection asynchronously. 445e81a82fSopenharmony_ci virtual int StartConnection(const ChannelRequest &request, std::shared_ptr<IChannelListener> channelListener) 455e81a82fSopenharmony_ci { 465e81a82fSopenharmony_ci return -1; 475e81a82fSopenharmony_ci } 485e81a82fSopenharmony_ci 495e81a82fSopenharmony_ci /* 505e81a82fSopenharmony_ci * Start listening for device channel connections. 515e81a82fSopenharmony_ci * When the channel type is VTP or TCP, the return value represents the port number, and a negative value 525e81a82fSopenharmony_ci * represents failure. 535e81a82fSopenharmony_ci * When the channel type is softbus, the return value of 0 indicates successful registration and listening, 545e81a82fSopenharmony_ci * and a negative value represents failure. 555e81a82fSopenharmony_ci * 565e81a82fSopenharmony_ci * @param request channel unique ID 575e81a82fSopenharmony_ci * @return Results of starting listening 585e81a82fSopenharmony_ci */ 595e81a82fSopenharmony_ci virtual int StartListen(const ChannelRequest &request, std::shared_ptr<IChannelListener> channelListener) 605e81a82fSopenharmony_ci { 615e81a82fSopenharmony_ci return -1; 625e81a82fSopenharmony_ci } 635e81a82fSopenharmony_ci 645e81a82fSopenharmony_ci // Close connection and all channels 655e81a82fSopenharmony_ci virtual void CloseConnection() {}; 665e81a82fSopenharmony_ci 675e81a82fSopenharmony_ciprotected: 685e81a82fSopenharmony_ci ChannelRequest channelRequest_; 695e81a82fSopenharmony_ci std::shared_ptr<ConnectionListener> listener_; 705e81a82fSopenharmony_ci}; 715e81a82fSopenharmony_ci} // namespace CastEngineService 725e81a82fSopenharmony_ci} // namespace CastEngine 735e81a82fSopenharmony_ci} // namespace OHOS 745e81a82fSopenharmony_ci 755e81a82fSopenharmony_ci 765e81a82fSopenharmony_ci#endif // CONNECTION_H 77