2 * Copyright (c) 2017 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 #ifndef PROXY_INTERNAL_H_
18 #define PROXY_INTERNAL_H_
22 #include <glib-unix.h>
27 #include "fdbroker-internal.h"
28 #include "port-internal.h"
33 class Proxy : public FdBroker::IEventWatcher {
35 explicit Proxy(bool mock = false);
38 class IEventListener {
40 virtual void OnConnected(const std::string& endpoint, Port* port) = 0;
41 virtual void OnDisconnected(const std::string& endpoint) = 0;
42 virtual void OnRejected(const std::string& endpoint, int err_code) = 0;
43 virtual void OnReceived(const std::string& endpoint) = 0;
46 int Connect(std::string appid, std::string port_name, IEventListener* ev);
47 int ConnectSync(std::string appid, std::string port_name, IEventListener* ev);
48 void DisconnectPort();
50 std::shared_ptr<Port> GetPort() const {
54 std::shared_ptr<Port> GetDelegatePort() const {
55 return delegate_port_;
58 const std::string& GetPortName() {
63 class ProxyPort : public Port {
65 ProxyPort(Proxy* parent, int fd, const std::string& id, bool receive = true);
67 void SetDisconnectedSource(int sourceId);
68 void SetSource(int sourceId);
71 int Watch(bool receive);
74 GIOChannel* gioc_ = nullptr;
77 Proxy* parent_ = nullptr;
81 static gboolean OnSocketDisconnected(GIOChannel *gio, GIOCondition cond,
83 static gboolean OnDataReceived(GIOChannel *gio, GIOCondition cond,
85 static gboolean DbusNameTimeout(gpointer user_data);
86 void OnPortAppeared() override;
87 void OnPortVanished() override;
88 void OnPortRejected(int error) override;
89 void OnPortConnected() override;
90 void OnPortDisconnected(bool cancel = false) override;
91 void SetRealAppId(const std::string& alias_appid);
94 std::string port_name_;
95 std::shared_ptr<ProxyPort> main_port_;
96 std::shared_ptr<ProxyPort> delegate_port_;
97 IEventListener* listener_ = nullptr;
98 std::shared_ptr<FdBroker> fd_broker_;
99 std::string target_appid_;
100 std::string real_appid_;
102 guint conn_timer_ = 0;
105 } // namespace internal
106 } // namespace rpc_port
108 #endif // PROXY_INTERNAL_H_