namespace cion {
namespace channel {
-BroadcastChannel::BroadcastChannel(std::string& topic, IEventSender* sender,
- IEventListener* listener) : sender_(sender), listener_(listener) {
+BroadcastChannel::BroadcastChannel(std::string& topic) {
}
}
}
-void BroadcastChannel::OnDataEvent(IDataInfo info, std::vector<char> data) {
+void BroadcastChannel::OnDataEvent(const IDataInfo& info,
+ std::vector<char> data) {
}
-void BroadcastChannel::OnConnectionEvent(IConnectionInfo info,
+void BroadcastChannel::OnConnectionEvent(const IConnectionInfo& info,
std::vector<char> serialized_peerInfo) {
}
#include <string>
#include <vector>
-#include "event_observer.hh"
-#include "event_listener.hh"
-#include "event_sender.hh"
-#include "../common/peer_info.hh"
-#include "../common/interface_payload.hh"
+#include "ievent_observer.hh"
+#include "ievent_listener.hh"
+#include "ievent_sender.hh"
+#include "cion/common/peer_info.hh"
+#include "cion/common/interface_payload.hh"
namespace cion {
namespace channel {
class BroadcastChannel: public IEventObserver {
public:
- BroadcastChannel(std::string& topic, IEventSender* sender,
- IEventListener* listener);
+ BroadcastChannel(std::string& topic);
void Subscribe();
void Unsubscribe();
void Publish(IPayload* data);
protected:
virtual void OnMessageReceived(IPayload* data,
std::shared_ptr<PeerInfo> peer) = 0;
- void OnDataEvent(IDataInfo info,
+ void OnDataEvent(const IDataInfo& info,
std::vector<char> serialized_payload) override;
- void OnConnectionEvent(IConnectionInfo info,
+ void OnConnectionEvent(const IConnectionInfo& info,
std::vector<char> serialized_peerinfo) override;
std::string GetServiceName() override;
int GetChannelId() override;
*/
#include "client_channel.hh"
+#include "client_channel_implementation.hh"
+#include "control_info.hh"
+#include "data_info.hh"
#include "vine_manager/vine_manager.hh"
#include "vine_manager/vine_sender.hh"
+#include "vine_manager/vine_listener.hh"
+#include "cion/common/util/id_generator.hh"
/**
* ClientChannel implementation
namespace cion {
namespace channel {
-ClientChannel::ClientChannel(const std::string& service_name) {
- channel_id_ = VineManager::GetChannelId();
- sender_ = new VineSender();
+ClientChannel::ClientChannel(std::string& service_name) {
+ int channel_id = IDGenerator::GetInst().GenChannelId();
+ std::unique_ptr<IEventSender> sender(new VineSender(service_name,
+ channel_id));
+ std::unique_ptr<IEventListener> listener(new VineListener());
+ impl_ = std::unique_ptr<Impl>(new Impl(this, service_name, channel_id,
+ std::move(sender), std::move(listener)));
+}
+
+ClientChannel::Impl::~Impl() {
+ VineManager::GetInst().UnregisterSender(channel_id_);
+}
+
+ClientChannel::Impl::Impl(ClientChannel* parent, std::string service_name,
+ int channel_id,
+ std::unique_ptr<IEventSender> sender,
+ std::unique_ptr<IEventListener> listener) : parent_(parent),
+ service_name_(service_name), channel_id_(channel_id),
+ sender_(std::move(sender)), listener_(std::move(listener)) {
+ VineManager::GetInst().RegisterSender(service_name_, channel_id_);
}
void ClientChannel::TryDiscovery() {
- sender_->Discovery(GetChannelId());
+ auto ci = ControlInfo(IControlInfo::ControlType::DISCOVERY,
+ IControlInfo::ChannelType::COMMUNICATION, impl_->service_name_);
+ impl_->sender_->OperateChannel(ci, nullptr);
}
void ClientChannel::StopDiscovery() {
-
+ auto ci = ControlInfo(IControlInfo::ControlType::STOP_DISCOVERY,
+ IControlInfo::ChannelType::COMMUNICATION, impl_->service_name_);
+ impl_->sender_->OperateChannel(ci, nullptr);
}
void ClientChannel::Connect(std::shared_ptr<PeerInfo> peer) {
-
+ auto ci = ControlInfo(IControlInfo::ControlType::CONNECT,
+ IControlInfo::ChannelType::COMMUNICATION, impl_->service_name_);
+ impl_->sender_->OperateChannel(ci, peer);
}
void ClientChannel::Disconnect() {
-
+ auto ci = ControlInfo(IControlInfo::ControlType::DISCONNECT,
+ IControlInfo::ChannelType::COMMUNICATION, impl_->service_name_);
+ impl_->sender_->OperateChannel(ci, impl_->peer_);
}
std::vector<char> ClientChannel::SendData(std::vector<char> data, int timeout) {
- return {};
+ auto di = DataInfo(IDataInfo::MessageType::Sync, impl_->peer_->GetUUID());
+ return impl_->sender_->SendData(data, di, impl_->peer_, timeout);
}
void ClientChannel::SendPayLoadAsync(IPayload* data) {
-
+ auto di = DataInfo(IDataInfo::MessageType::Sync, impl_->peer_->GetUUID());
+ impl_->sender_->SendData(data->Serialize(), di, impl_->peer_, -1);
}
std::shared_ptr<PeerInfo> ClientChannel::GetPeerInfo() {
- return {};
-}
-
-void ClientChannel::SetSecurity(SecurityInfo sec) {
-
+ return impl_->peer_;
}
-void ClientChannel::OnDataEvent(IDataInfo info, std::vector<char> data) {
-
+void ClientChannel::OnDataEvent(const IDataInfo& info, std::vector<char> data) {
+ if (info.GetType() == IDataInfo::MessageType::Async) {
+ auto pl = DataPayload(data);
+ OnPayloadReceived(pl);
+ }
}
-void ClientChannel::OnConnectionEvent(IConnectionInfo info,
+void ClientChannel::OnConnectionEvent(const IConnectionInfo& info,
std::vector<char> serialized_peerInfo) {
-
+ std::shared_ptr<PeerInfo> peer;
+ IConnectionInfo::ConnectionType type = info.GetConnectionType();
+ switch (type) {
+ case IConnectionInfo::ConnectionType::Connected: {
+ impl_->peer_ = std::shared_ptr<PeerInfo>(peer);
+ OnConnentionStatusChaneged(peer,
+ IConnectionInfo::ConnectionStatus::ONLINE);
+ break;
+ }
+ case IConnectionInfo::ConnectionType::Disconnected: {
+ impl_->peer_ = nullptr;
+ OnConnentionStatusChaneged(peer,
+ IConnectionInfo::ConnectionStatus::OFFLINE);
+ break;
+ }
+ case IConnectionInfo::ConnectionType::Discovered: {
+ OnDiscovered(peer);
+ break;
+ }
+ case IConnectionInfo::ConnectionType::Rejected: {
+ OnErrorReported(0, peer);
+ }
+ case IConnectionInfo::ConnectionType::ConnectionRequested:
+ case IConnectionInfo::ConnectionType::Undiscovered:
+ break;
+ }
}
std::string ClientChannel::GetServiceName() {
- return "";
+ return impl_->service_name_;;
}
int ClientChannel::GetChannelId() {
- return channel_id_;
+ return impl_->channel_id_;
}
} //namespace cion
#include <memory>
#include <vector>
-#include "event_observer.hh"
-#include "event_listener.hh"
-#include "event_sender.hh"
+#include "ievent_observer.hh"
+#include "ievent_listener.hh"
+#include "ievent_sender.hh"
#include "cion/security/security_info.hh"
#include "cion/common/peer_info.hh"
#include "cion/common/interface_payload.hh"
-#include "cion/channel/connection_info.hh"
-
-#ifndef EXPORT_API
-#define EXPORT_API __attribute__((visibility("default")))
-#endif
namespace cion {
namespace channel {
-class EXPORT_API ClientChannel: public IEventObserver {
- public:
- explicit ClientChannel(const std::string& service_name);
+class ClientChannel: public IEventObserver {
+public:
+ ClientChannel(std::string& service_name);
void TryDiscovery();
void StopDiscovery();
void Connect(std::shared_ptr<PeerInfo> peer);
void SetSecurity(SecurityInfo sec);
protected:
- virtual void OnConnentionStatusChaneged(PeerInfo peer,
+ virtual void OnConnentionStatusChaneged(std::shared_ptr<PeerInfo> peer,
IConnectionInfo::ConnectionStatus status) = 0;
- virtual void OnPayloadReceived(IPayload* data) = 0;
- virtual void OnErrorReported(int code, PeerInfo peer) = 0;
- virtual void OnDiscovered(PeerInfo peer) = 0;
+ virtual void OnPayloadReceived(IPayload& data) = 0;
+ virtual void OnErrorReported(int code, std::shared_ptr<PeerInfo> peer) = 0;
+ virtual void OnDiscovered(std::shared_ptr<PeerInfo> peer) = 0;
- void OnDataEvent(IDataInfo info,
+ void OnDataEvent(const IDataInfo& info,
std::vector<char> serialized_payload) override;
- void OnConnectionEvent(IConnectionInfo info,
+ void OnConnectionEvent(const IConnectionInfo& info,
std::vector<char> serialized_peerinfo) override;
std::string GetServiceName() override;
int GetChannelId() override;
private:
- IEventSender* sender_ = nullptr;
- IEventListener* listener_ = nullptr;
- int channel_id_;
+ class Impl;
+ std::unique_ptr<Impl> impl_;
};
} //namespace channel
--- /dev/null
+
+/*
+ * Copyright (c) 2021 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef CION_CLIENTCHANNEL_IMPLEMENTATION_H_
+#define CION_CLIENTCHANNEL_IMPLEMENTATION_H_
+
+#include <string>
+#include <vector>
+#include <list>
+
+#include "client_channel.hh"
+
+namespace cion {
+namespace channel {
+
+class ClientChannel::Impl {
+ public:
+ virtual ~Impl();
+
+ private:
+ Impl(ClientChannel* parent, std::string service_name,
+ int channel_id,
+ std::unique_ptr<IEventSender> sender,
+ std::unique_ptr<IEventListener> listener);
+
+ private:
+ friend class ClientChannel;
+ ClientChannel* parent_;
+ std::string service_name_;
+ int channel_id_;
+ std::unique_ptr<IEventSender> sender_;
+ std::unique_ptr<IEventListener> listener_;
+ std::shared_ptr<PeerInfo> peer_;
+};
+
+} //namespace channel
+} //namespace cion
+
+#endif //CION_CLIENTCHANNEL_IMPLEMENTATION_H_
+++ /dev/null
-/*
- * Copyright (c) 2020 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "connection_info.hh"
-
-/**
- * IConnectionInfo implementation
- */
-
-namespace cion{
-namespace channel {
-
-IConnectionInfo::ConnectionType IConnectionInfo::GetConnectionType() {
- return IConnectionInfo::ConnectionType::Discovered;
-}
-
-std::string IConnectionInfo::GetUUID() {
- return "";
-}
-
-} // namespace channel
-} // namespace cion
+++ /dev/null
-/*
- * Copyright (c) 2020 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef CION_ICONNECTIONINFO_H_
-#define CION_ICONNECTIONINFO_H_
-
-#include <string>
-
-#ifndef EXPORT_API
-#define EXPORT_API __attribute__((visibility("default")))
-#endif
-
-namespace cion {
-namespace channel {
-
-class EXPORT_API IConnectionInfo {
- public:
- enum class ConnectionType {
- Discovered,
- Undiscovered,
- Connected,
- Disconnected,
- ConnectionRequested,
- Rejected
- };
-
- enum class ConnectionStatus {
- ONLINE,
- OFFLINE,
- };
-
- ConnectionType GetConnectionType();
- std::string GetUUID();
-};
-
-} //namespace channel
-} //namespace cion
-
-#endif //CION_ICONNECTIONINFO_H_
-
/*
- * Copyright (c) 2020 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2021 Samsung Electronics Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
#include "control_info.hh"
-/**
- * IControlInfo implementation
- */
-
namespace cion {
namespace channel {
-
-int IControlInfo::GetControlType() {
- return 0;
+ControlInfo::ControlInfo(IControlInfo::ControlType control_type,
+ IControlInfo::ChannelType channel_type, std::string service_name)
+ : control_type_(control_type), channel_type_(channel_type), service_name_(service_name) {
+}
+IControlInfo::ControlType ControlInfo::GetControlType() {
+ return control_type_;
}
-int IControlInfo::GetChannelType() {
- return 0;
+IControlInfo::ChannelType ControlInfo::GetChannelType() {
+ return channel_type_;
+}
+std::string ControlInfo::GetServiceName() {
+ return service_name_;
}
-} //namespace channel
-} //namespace cion
+}
+}
-
/*
- * Copyright (c) 2020 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2021 Samsung Electronics Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* limitations under the License.
*/
-#ifndef CION_ICONTROLINFO_H_
-#define CION_ICONTROLINFO_H_
+#ifndef CION_CONTROLINFO_HH_
+#define CION_CONTROLINFO_HH_
+
+#include <vector>
+#include <string>
+
+#include "icontrol_info.hh"
namespace cion {
namespace channel {
-
-class IControlInfo {
+class ControlInfo : public IControlInfo {
public:
- int GetControlType();
- int GetChannelType();
+ ControlInfo(IControlInfo::ControlType control_type,
+ IControlInfo::ChannelType channel_type, std::string service_name);
+ IControlInfo::ControlType GetControlType() override;
+ IControlInfo::ChannelType GetChannelType() override;
+ std::string GetServiceName() override;
+
+ private:
+ IControlInfo::ControlType control_type_;
+ IControlInfo::ChannelType channel_type_;
+ std::string service_name_;
+
};
-} //namespace channel
-} //namespace cion
+}
+} // namespace cion
-#endif //CION_ICONTROLINFO_H_
+#endif // CION_CONTROL_INFO_HH_
\ No newline at end of file
/*
- * Copyright (c) 2020 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2021 Samsung Electronics Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
#include "data_info.hh"
-/**
- * IDataInfo implementation
- */
-
namespace cion {
namespace channel {
+DataInfo::DataInfo(IDataInfo::MessageType message_type,
+ std::string uuid)
+ : message_type_(message_type), uuid_(uuid) {
+}
-IDataInfo::MessageType IDataInfo::GetType() {
- return IDataInfo::MessageType::Sync;
+IDataInfo::MessageType DataInfo::GetType() const {
+ return message_type_;
}
-std::string IDataInfo::GetUUID() {
- return "";
+std::string DataInfo::GetUUID() const {
+ return uuid_;
}
-} //namespace channel
-} //namespace cion
+}
+}
/*
- * Copyright (c) 2020 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2021 Samsung Electronics Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* limitations under the License.
*/
-#ifndef CION_IDATAINFO_H_
-#define CION_IDATAINFO_H_
+#ifndef CION_DATAINFO_HH_
+#define CION_DATAINFO_HH_
+#include <vector>
#include <string>
+#include "idata_info.hh"
+
namespace cion {
namespace channel {
-
-class IDataInfo {
+class DataInfo : public IDataInfo {
public:
- enum class MessageType {
- Sync,
- Async
- };
+ DataInfo(IDataInfo::MessageType message_type, std::string uuid);
+ IDataInfo::MessageType GetType() const override;
+ std::string GetUUID() const override;
+
+ private:
+ IDataInfo::MessageType message_type_;
+ std::string uuid_;
- MessageType GetType();
- std::string GetUUID();
};
-} //namespace channel
-} //namespace cion
+}
+} // namespace cion
-#endif //CION_IDATAINFO_H_
+#endif // CION_DATAINFO_HH_
\ No newline at end of file
+++ /dev/null
-/*
- * Copyright (c) 2020 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef CION_CION_CHANNEL_EVENT_LISTENER_HH_
-#define CION_CION_CHANNEL_EVENT_LISTENER_HH_
-
-#include "event_observer.hh"
-
-namespace cion {
-namespace channel {
-
-class IEventListener {
- public:
- virtual void RegisterObserver(IEventObserver* observer) = 0;
- virtual void UnregisterObserver(IEventObserver* observer) = 0;
-};
-
-} // namespace channel
-} // namespace cion
-
-#endif // CION_CION_CHANNEL_EVENT_LISTENER_HH_
+++ /dev/null
-
-/*
- * Copyright (c) 2020 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef CION_IEVENTOBSERVER_H_
-#define CION_IEVENTOBSERVER_H_
-
-#include <string>
-#include <vector>
-
-#include "connection_info.hh"
-#include "data_info.hh"
-#include "../common/interface_payload.hh"
-
-namespace cion {
-namespace channel {
-
-class IEventObserver {
- public:
-
- virtual void OnDataEvent(IDataInfo info,
- std::vector<char> serialized_payload) = 0;
-
- virtual void OnConnectionEvent(IConnectionInfo info,
- std::vector<char> serialized_peerinfo) = 0;
-
- virtual std::string GetServiceName() = 0;
- virtual int GetChannelId() = 0;
-};
-
-} //namespace channel
-} //namespace cion
-
-#endif //CION_IEVENTOBSERVER_H_
+++ /dev/null
-/*
- * Copyright (c) 2020 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef CION_CION_CHANNEL_EVENT_SENDER_HH_
-#define CION_CION_CHANNEL_EVENT_SENDER_HH_
-
-#include <string>
-#include <vector>
-#include <memory>
-
-#include "data_info.hh"
-#include "control_info.hh"
-#include "cion/common/peer_info.hh"
-#include "cion/security/security_info.hh"
-#include "cion/common/peer_info.hh"
-
-namespace cion {
-namespace channel {
-
-class IEventSender {
- public:
- virtual void SendDataAsync(std::vector<char> serialized_payload,
- channel::IDataInfo info, std::shared_ptr<PeerInfo> peer_info) = 0;
- virtual std::vector<char> SendData(std::vector<char> serialized_payload,
- channel::IDataInfo info, std::shared_ptr<PeerInfo> peer_info,
- int timeout) = 0;
- virtual void OperateChannel(channel::IControlInfo info,
- std::shared_ptr<PeerInfo> peer_info) = 0;
- virtual void SetSecurity(SecurityInfo sec) = 0;
- virtual void Discovery(int channel_id) = 0;
-};
-
-} // namespace channel
-} // namespace cion
-
-#endif // CION_CION_CHANNEL_EVENT_SENDER_HH_
--- /dev/null
+/*
+ * Copyright (c) 2020 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef CION_ICONNECTIONINFO_H_
+#define CION_ICONNECTIONINFO_H_
+
+#include <string>
+
+#ifndef EXPORT_API
+#define EXPORT_API __attribute__((visibility("default")))
+#endif
+
+namespace cion {
+namespace channel {
+
+class EXPORT_API IConnectionInfo {
+ public:
+ enum class ConnectionType {
+ Discovered,
+ Undiscovered,
+ Connected,
+ Disconnected,
+ ConnectionRequested,
+ Rejected
+ };
+
+ enum class ConnectionStatus {
+ ONLINE,
+ OFFLINE,
+ };
+
+ virtual ConnectionType GetConnectionType() const = 0;
+ virtual std::string GetUUID() const = 0;
+};
+
+} //namespace channel
+} //namespace cion
+
+#endif //CION_ICONNECTIONINFO_H_
--- /dev/null
+
+/*
+ * Copyright (c) 2020 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef CION_ICONTROLINFO_H_
+#define CION_ICONTROLINFO_H_
+
+namespace cion {
+namespace channel {
+
+class IControlInfo {
+ public:
+ enum ControlType {
+ LISTEN,
+ STOP,
+ CONNECT,
+ DISCONNECT,
+ DISCOVERY,
+ STOP_DISCOVERY
+ };
+
+ enum ChannelType {
+ COMMUNICATION,
+ BROADCAST,
+ };
+ virtual ControlType GetControlType() = 0;
+ virtual ChannelType GetChannelType() = 0;
+ virtual std::string GetServiceName() = 0;
+};
+
+} //namespace channel
+} //namespace cion
+
+#endif //CION_ICONTROLINFO_H_
--- /dev/null
+/*
+ * Copyright (c) 2020 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef CION_IDATAINFO_H_
+#define CION_IDATAINFO_H_
+
+#include <string>
+
+namespace cion {
+namespace channel {
+
+class IDataInfo {
+ public:
+ enum class MessageType {
+ Sync,
+ Async
+ };
+
+ virtual MessageType GetType() const = 0;
+ virtual std::string GetUUID() const = 0;
+};
+
+} //namespace channel
+} //namespace cion
+
+#endif //CION_IDATAINFO_H_
--- /dev/null
+/*
+ * Copyright (c) 2020 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef CION_CION_CHANNEL_EVENT_LISTENER_HH_
+#define CION_CION_CHANNEL_EVENT_LISTENER_HH_
+
+#include "ievent_observer.hh"
+
+namespace cion {
+namespace channel {
+
+class IEventListener {
+public:
+ virtual void RegisterObserver(IEventObserver* observer) = 0;
+ virtual void UnregisterObserver(IEventObserver* observer) = 0;
+};
+
+} // namespace channel
+} // namespace cion
+
+#endif // CION_CION_CHANNEL_EVENT_LISTENER_HH_
--- /dev/null
+
+/*
+ * Copyright (c) 2020 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef CION_IEVENTOBSERVER_H_
+#define CION_IEVENTOBSERVER_H_
+
+#include <string>
+#include <vector>
+
+#include "iconnection_info.hh"
+#include "idata_info.hh"
+#include "cion/common/interface_payload.hh"
+
+namespace cion {
+namespace channel {
+
+class IEventObserver {
+ public:
+
+ virtual void OnDataEvent(const IDataInfo& info,
+ std::vector<char> serialized_payload) = 0;
+
+ virtual void OnConnectionEvent(const IConnectionInfo& info,
+ std::vector<char> serialized_peerinfo) = 0;
+
+ virtual std::string GetServiceName() = 0;
+ virtual int GetChannelId() = 0;
+};
+
+} //namespace channel
+} //namespace cion
+
+#endif //CION_IEVENTOBSERVER_H_
--- /dev/null
+/*
+ * Copyright (c) 2020 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef CION_CION_CHANNEL_EVENT_SENDER_HH_
+#define CION_CION_CHANNEL_EVENT_SENDER_HH_
+
+#include <string>
+#include <vector>
+#include <memory>
+
+#include "idata_info.hh"
+#include "icontrol_info.hh"
+#include "cion/common/peer_info.hh"
+#include "cion/security/security_info.hh"
+
+namespace cion {
+namespace channel {
+
+class IEventSender {
+ public:
+ virtual void SendDataAsync(std::vector<char> serialized_payload,
+ const IDataInfo& info, std::shared_ptr<PeerInfo> peer_info) = 0;
+ virtual std::vector<char> SendData(std::vector<char> serialized_payload,
+ const IDataInfo& info, std::shared_ptr<PeerInfo> peer_info,
+ int timeout) = 0;
+ virtual void OperateChannel(const IControlInfo& info,
+ std::shared_ptr<PeerInfo> peer_info) = 0;
+ virtual void SetSecurity(SecurityInfo sec) = 0;
+};
+
+} // namespace channel
+} // namespace cion
+
+#endif // CION_CION_CHANNEL_EVENT_SENDER_HH_
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-#include<utility>
#include "server_channel.hh"
#include "server_channel_implementation.hh"
+#include "control_info.hh"
+
#include "vine_manager/vine_manager.hh"
+#include "vine_manager/vine_sender.hh"
#include "vine_manager/vine_listener.hh"
+#include "cion/common/util/id_generator.hh"
/**
* ServerChannel implementation
namespace cion {
namespace channel {
-ServerChannel::ServerChannel(std::string service_name)
- : impl_(new Impl(this, service_name)) {
- impl_->channel_id_ = VineManager::GetChannelId();
+ServerChannel::ServerChannel(std::string service_name) {
+ int channel_id = IDGenerator::GetInst().GenChannelId();
+ std::unique_ptr<IEventSender> sender(new VineSender(service_name, channel_id));
+ std::unique_ptr<IEventListener> listener(new VineListener());
+ impl_ = std::unique_ptr<Impl>(new Impl(this, service_name, channel_id,
+ std::move(sender), std::move(listener)));
}
ServerChannel::~ServerChannel() = default;
ServerChannel::Impl::~Impl() {
- VineManager::GetInst().UnregisterSender(channel_id_);
+// VineManager::GetInst().UnregisterSender(channel_id_);
}
-ServerChannel::Impl::Impl(ServerChannel* parent, std::string service_name)
- : parent_(parent), service_name_(service_name) {
+ServerChannel::Impl::Impl(ServerChannel* parent, std::string service_name,
+ int channel_id,
+ std::unique_ptr<IEventSender> sender,
+ std::unique_ptr<IEventListener> listener) : parent_(parent),
+ service_name_(service_name), channel_id_(channel_id), sender_(std::move(sender)),
+ listener_(std::move(listener)) {
VineManager::GetInst().RegisterSender(service_name_, channel_id_);
- listener_ = std::unique_ptr<VineListener>(new VineListener());
+
+ peer_info_ = std::make_shared<PeerInfo>();
}
void ServerChannel::Listen() {
+ auto ci = ControlInfo(IControlInfo::ControlType::LISTEN,
+ IControlInfo::ChannelType::COMMUNICATION, impl_->service_name_);
impl_->listener_->RegisterObserver(this);
+ impl_->sender_->OperateChannel(ci, impl_->peer_info_);
}
void ServerChannel::Stop() {
+ auto ci = ControlInfo(IControlInfo::ControlType::STOP,
+ IControlInfo::ChannelType::COMMUNICATION, impl_->service_name_);
impl_->listener_->UnregisterObserver(this);
+ impl_->sender_->OperateChannel(ci, impl_->peer_info_);
}
-void ServerChannel::Disconnect(PeerInfo peer) {
-
+void ServerChannel::Disconnect(std::shared_ptr<PeerInfo> peer) {
+ auto ci = ControlInfo(IControlInfo::ControlType::DISCONNECT,
+ IControlInfo::ChannelType::COMMUNICATION, impl_->service_name_);
+ impl_->sender_->OperateChannel(ci, peer);
}
void ServerChannel::SendPayloadAsync(IPayload* data) {
void ServerChannel::SendPayloadAsync(IPayload* data,
std::shared_ptr<PeerInfo> peer_info) {
- IDataInfo info;
- impl_->sender_->SendDataAsync(data->Serialize(), info, peer_info);
+ // IDataInfo info;
+ // impl_->sender_->SendDataAsync(data->Serialize(), info, peer_info);
}
std::list<std::shared_ptr<PeerInfo>> ServerChannel::GetConnectedPeerList() {
return impl_->peerlist_;
}
-void ServerChannel::SetSecurity(SecurityInfo sec) {
-
-}
-
-void ServerChannel::OnDataEvent(IDataInfo info, std::vector<char> data) {
+void ServerChannel::OnDataEvent(const IDataInfo& info, std::vector<char> data) {
+ for (auto& i : impl_->peerlist_) {
+ if (i->GetUUID() == info.GetUUID()) {
+ if (info.GetType() == IDataInfo::MessageType::Async) {
+ auto pl = DataPayload(data);
+ OnPayloadReceived(pl, i);
+ } else if (info.GetType() == IDataInfo::MessageType::Sync) {
+ OnDataReceived(data, i);
+ }
+ break;
+ }
+ }
}
-void ServerChannel::OnConnectionEvent(IConnectionInfo info,
+void ServerChannel::OnConnectionEvent(const IConnectionInfo& info,
std::vector<char> serialized_peerInfo) {
- if (info.GetConnectionType() == IConnectionInfo::ConnectionType::Connected) {
- std::shared_ptr<PeerInfo> connected_peer;
- impl_->peerlist_.push_back(connected_peer);
+ std::shared_ptr<PeerInfo> peer;
+ IConnectionInfo::ConnectionType type = info.GetConnectionType();
+ switch (type) {
+ case IConnectionInfo::ConnectionType::ConnectionRequested: {
+ OnConnentionRequest(peer);
+ break;
+ }
+ case IConnectionInfo::ConnectionType::Connected: {
+ impl_->peerlist_.push_back(peer);
+ OnConnentionStatusChaneged(peer,
+ IConnectionInfo::ConnectionStatus::ONLINE);
+ break;
+ }
+ case IConnectionInfo::ConnectionType::Disconnected: {
+ for (auto it : impl_->peerlist_) {
+ if (it->GetUUID() == info.GetUUID()) {
+ impl_->peerlist_.remove(it);
+ break;
+ }
+ }
+ OnConnentionStatusChaneged(peer,
+ IConnectionInfo::ConnectionStatus::OFFLINE);
+ break;
+ }
+ case IConnectionInfo::ConnectionType::Discovered:
+ case IConnectionInfo::ConnectionType::Undiscovered:
+ case IConnectionInfo::ConnectionType::Rejected:
+ break;
}
}
#include <string>
#include <vector>
-#include "event_observer.hh"
-#include "event_sender.hh"
-#include "event_listener.hh"
+#include "ievent_observer.hh"
+#include "ievent_sender.hh"
+#include "ievent_listener.hh"
#include "cion/security/security_info.hh"
#include "cion/common/peer_info.hh"
#include "cion/common/interface_payload.hh"
-#ifndef EXPORT_API
-#define EXPORT_API __attribute__((visibility("default")))
-#endif
namespace cion {
namespace channel {
-class EXPORT_API ServerChannel: public IEventObserver {
+class ServerChannel: public IEventObserver {
public:
- explicit ServerChannel(std::string service_name);
+ ServerChannel(std::string service_name);
virtual ~ServerChannel();
void Listen();
void Stop();
- void Disconnect(PeerInfo peer);
+ void Disconnect(std::shared_ptr<PeerInfo>);
void SendPayloadAsync(IPayload* data);
void SendPayloadAsync(IPayload* data, std::shared_ptr<PeerInfo> peer);
std::list<std::shared_ptr<PeerInfo>> GetConnectedPeerList();
IConnectionInfo::ConnectionStatus status) = 0;
virtual std::vector<char> OnDataReceived(std::vector<char> data,
std::shared_ptr<PeerInfo> peer) = 0;
- virtual void OnPayloadReceived(IPayload* data,
+ virtual void OnPayloadReceived(IPayload& data,
std::shared_ptr<PeerInfo> peer) = 0;
virtual bool OnConnentionRequest(std::shared_ptr<PeerInfo> peer) = 0;
virtual void OnErrorReported(int code, std::shared_ptr<PeerInfo> peer) = 0;
- void OnDataEvent(IDataInfo info,
+ void OnDataEvent(const IDataInfo& info,
std::vector<char> serialized_payload) override;
- void OnConnectionEvent(IConnectionInfo info,
+ void OnConnectionEvent(const IConnectionInfo& info,
std::vector<char> serialized_peerinfo) override;
std::string GetServiceName() override;
int GetChannelId() override;
virtual ~Impl();
private:
- Impl(ServerChannel* parent, std::string service_name);
+ Impl(ServerChannel* parent, std::string service_name,
+ int channel_id,
+ std::unique_ptr<IEventSender> sender,
+ std::unique_ptr<IEventListener> listener);
private:
friend class ServerChannel;
std::unique_ptr<IEventSender> sender_;
std::unique_ptr<IEventListener> listener_;
std::list<std::shared_ptr<PeerInfo>> peerlist_;
+ std::shared_ptr<PeerInfo> peer_info_;
};
} //namespace channel
#include <unistd.h>
#include <memory>
+#include "vine_manager.hh"
#include "vine_listener.hh"
#include "vine_listener_implementation.hh"
-#include "vine_manager.hh"
namespace cion {
}
void VineListener::RegisterObserver(channel::IEventObserver* observer) {
- VineManager::GetInst().RegisterObserver(observer);
+ VineManager::GetInst().RegisterObserver(observer);
}
void VineListener::UnregisterObserver(channel::IEventObserver* observer) {
+ VineManager::GetInst().UnregisterObserver(observer);
}
} // namespace cion
#include <memory>
-#include "cion/channel/event_observer.hh"
-#include "cion/channel/event_listener.hh"
+#include "cion/channel/ievent_observer.hh"
+#include "cion/channel/ievent_listener.hh"
namespace cion {
#endif
class EXPORT_API VineListener : public channel::IEventListener {
+
public:
VineListener();
virtual ~VineListener();
void RegisterObserver(channel::IEventObserver* observer) override;
void UnregisterObserver(channel::IEventObserver* observer) override;
- protected:
-
private:
class Impl;
}
void VineManager::SendDataAsync(std::vector<char> serialized_payload,
- channel::IDataInfo info, int channel_id,
+ channel::IDataInfo& info, int channel_id,
std::shared_ptr<PeerInfo> peer_info) {
}
std::vector<char> VineManager::SendData(std::vector<char> serialized_payload,
- channel::IDataInfo info, int channel_id,
+ channel::IDataInfo& info, int channel_id,
std::string peer_uuid, int timeout) {
return {};
}
-void VineManager::OperateChannel(int channel_id, channel::IControlInfo info,
- std::shared_ptr<PeerInfo> peer_info) {
+void VineManager::OperateChannel(int channel_id,
+ const channel::IControlInfo& info, std::shared_ptr<PeerInfo> peer_info) {
}
} // namespace cion
\ No newline at end of file
#include <vine.h>
-#include "../cion/tizen-api/cion_error.h"
-#include "../cion/channel/event_observer.hh"
-#include "../cion/common/data_payload.hh"
-#include "../cion/common/peer_info.hh"
-#include "../cion/channel/data_info.hh"
-#include "../cion/channel/control_info.hh"
+#include "cion/tizen-api/cion_error.h"
+#include "cion/channel/ievent_observer.hh"
+#include "cion/common/data_payload.hh"
+#include "cion/common/peer_info.hh"
+#include "cion/channel/idata_info.hh"
+#include "cion/channel/icontrol_info.hh"
#include "session_info.hh"
#ifndef EXPORT_API
class EXPORT_API VineManager {
public:
static VineManager& GetInst();
- static int GetChannelId();
void AddDataPath(int channel_id, PeerInfo info, vine_dp_h dp);
void RegisterSender(std::string service_name, int channel_id);
void UnregisterSender(int channel_id);
void RegisterObserver(channel::IEventObserver* observer);
void UnregisterObserver(channel::IEventObserver* observer);
void SendDataAsync(std::vector<char> serialized_payload,
- channel::IDataInfo info, int channel_id,
+ channel::IDataInfo& info, int channel_id,
std::shared_ptr<PeerInfo> peer_info);
std::vector<char> SendData(std::vector<char> serialized_payload,
- channel::IDataInfo info, int channel_id,
+ channel::IDataInfo& info, int channel_id,
std::string peer_uuid, int timeout);
- void OperateChannel(int channel_id, channel::IControlInfo info,
+ void OperateChannel(int channel_id, const channel::IControlInfo& info,
std::shared_ptr<PeerInfo> peer_info);
void RegisterService(std::shared_ptr<SessionInfo> info, int port);
bool Discovery(int channel_id);
#include <unistd.h>
#include <memory>
+#include "vine_manager.hh"
+
#include "vine_sender.hh"
#include "vine_sender_implementation.hh"
-#include "vine_manager.hh"
namespace cion {
-VineSender::VineSender()
- : impl_(new Impl()) {
+VineSender::VineSender(std::string service_name, int channel_id)
+ : impl_(new Impl(service_name, channel_id)) {
}
VineSender::~VineSender() {
+
}
-VineSender::Impl::Impl() {
+VineSender::Impl::Impl(std::string service_name, int channel_id)
+ : service_name_(service_name), channel_id_(channel_id) {
port_ = 0;
+ VineManager::GetInst().RegisterSender(service_name, channel_id);
+}
+
+VineSender::Impl::~Impl() {
+ VineManager::GetInst().UnregisterSender(channel_id_);
+}
+
+void VineSender::Impl::OperateChannel(const channel::IControlInfo& info,
+ std::shared_ptr<PeerInfo> peer_info) {
+
+ VineManager::GetInst().OperateChannel(channel_id_, info, peer_info);
}
void VineSender::SendDataAsync(std::vector<char> serialized_payload,
- channel::IDataInfo info, std::shared_ptr<PeerInfo> peer_info) {
+ const channel::IDataInfo& info, std::shared_ptr<PeerInfo> peer_info) {
}
std::vector<char> VineSender::SendData(std::vector<char> serialized_payload,
- channel::IDataInfo info, std::shared_ptr<PeerInfo> peer_info, int timeout) {
+ const channel::IDataInfo& info, std::shared_ptr<PeerInfo> peer_info, int timeout) {
return {};
}
-void VineSender::OperateChannel(channel::IControlInfo info,
+void VineSender::OperateChannel(const channel::IControlInfo& info,
std::shared_ptr<PeerInfo> peer_info) {
+ impl_->OperateChannel(info, peer_info);
}
void VineSender::SetSecurity(SecurityInfo sec) {
}
-void VineSender::Discovery(int channel_id) {
- VineManager::GetInst().Discovery(channel_id);
-}
-
} // namespace cion
#include "cion/common/data_payload.hh"
#include "cion/common/peer_info.hh"
-#include "cion/channel/data_info.hh"
-#include "cion/channel/control_info.hh"
+#include "cion/channel/idata_info.hh"
+#include "cion/channel/icontrol_info.hh"
+#include "cion/channel/ievent_sender.hh"
#include "cion/security/security_info.hh"
-#include "cion/channel/event_sender.hh"
#ifndef EXPORT_API
#define EXPORT_API __attribute__((visibility("default")))
class EXPORT_API VineSender : public channel::IEventSender {
public:
- VineSender();
+ VineSender(std::string service_name, int channel_id);
virtual ~VineSender();
protected:
void SendDataAsync(std::vector<char> serialized_payload,
- channel::IDataInfo info, std::shared_ptr<PeerInfo> peer_info) override;
+ const channel::IDataInfo& info,
+ std::shared_ptr<PeerInfo> peer_info) override;
std::vector<char> SendData(std::vector<char> serialized_payload,
- channel::IDataInfo info, std::shared_ptr<PeerInfo> peer_info,
- int timeout) override;
- void OperateChannel(channel::IControlInfo info,
+ const channel::IDataInfo& info,
+ std::shared_ptr<PeerInfo> peer_info, int timeout) override;
+ void OperateChannel(const channel::IControlInfo& info,
std::shared_ptr<PeerInfo> peer_info) override;
void SetSecurity(SecurityInfo sec) override;
- void Discovery(int channel_id) override;
-
-
private:
class Impl;
#ifndef CION_API_VINE_SENDER_IMPLEMENTATION_HH_
#define CION_API_VINE_SENDER_IMPLEMENTATION_HH_
+#include "cion/common/peer_info.hh"
+#include "cion/channel/idata_info.hh"
+#include "cion/channel/icontrol_info.hh"
+#include "cion/security/security_info.hh"
+
namespace cion {
class VineSender::Impl {
public:
- virtual ~Impl() = default;
+ virtual ~Impl();
private:
friend class VineSender;
- explicit Impl();
+
+ explicit Impl(std::string service_name, int channel_id);
+ void OperateChannel(const channel::IControlInfo& info,
+ std::shared_ptr<PeerInfo> peer_info);
private:
+ std::string service_name_;
+ int channel_id_;
int port_;
};