Sync
authorhyunho <hhstark.kang@samsung.com>
Mon, 22 Feb 2021 06:45:04 +0000 (15:45 +0900)
committerhyunho <hhstark.kang@samsung.com>
Mon, 22 Feb 2021 06:45:04 +0000 (15:45 +0900)
Signed-off-by: hyunho <hhstark.kang@samsung.com>
30 files changed:
cion/channel/broadcast_channel.cc [changed mode: 0755->0644]
cion/channel/broadcast_channel.hh [changed mode: 0755->0644]
cion/channel/client_channel.cc [changed mode: 0755->0644]
cion/channel/client_channel.hh [changed mode: 0755->0644]
cion/channel/client_channel_implementation.hh [new file with mode: 0644]
cion/channel/connection_info.cc [deleted file]
cion/channel/connection_info.hh [deleted file]
cion/channel/control_info.cc [changed mode: 0755->0644]
cion/channel/control_info.hh [changed mode: 0755->0644]
cion/channel/data_info.cc [changed mode: 0755->0644]
cion/channel/data_info.hh [changed mode: 0755->0644]
cion/channel/event_listener.hh [deleted file]
cion/channel/event_observer.hh [deleted file]
cion/channel/event_sender.hh [deleted file]
cion/channel/iconnection_info.hh [new file with mode: 0644]
cion/channel/icontrol_info.hh [new file with mode: 0644]
cion/channel/idata_info.hh [new file with mode: 0644]
cion/channel/ievent_listener.hh [new file with mode: 0644]
cion/channel/ievent_observer.hh [new file with mode: 0644]
cion/channel/ievent_sender.hh [new file with mode: 0644]
cion/channel/server_channel.cc [changed mode: 0755->0644]
cion/channel/server_channel.hh [changed mode: 0755->0644]
cion/channel/server_channel_implementation.hh
vine_manager/vine_listener.cc
vine_manager/vine_listener.hh
vine_manager/vine_manager.cc
vine_manager/vine_manager.hh
vine_manager/vine_sender.cc
vine_manager/vine_sender.hh
vine_manager/vine_sender_implementation.hh

old mode 100755 (executable)
new mode 100644 (file)
index 99d8483..330b759
@@ -23,8 +23,7 @@
 namespace cion {
 namespace channel {
 
-BroadcastChannel::BroadcastChannel(std::string& topic, IEventSender* sender,
-    IEventListener* listener) : sender_(sender), listener_(listener) {
+BroadcastChannel::BroadcastChannel(std::string& topic) {
 
 }
 
@@ -42,11 +41,12 @@ void BroadcastChannel::Publish(IPayload* data) {
   }
 }
 
-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) {
 
 }
old mode 100755 (executable)
new mode 100644 (file)
index 38396a4..cffdd2b
 #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);
@@ -40,9 +39,9 @@ public:
 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;
old mode 100755 (executable)
new mode 100644 (file)
index 55f26a1..6c8a5f0
  */
 
 #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
old mode 100755 (executable)
new mode 100644 (file)
index 4f57ed1..278c000
 #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);
@@ -49,23 +44,22 @@ class EXPORT_API ClientChannel: public IEventObserver {
   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
diff --git a/cion/channel/client_channel_implementation.hh b/cion/channel/client_channel_implementation.hh
new file mode 100644 (file)
index 0000000..66de5d7
--- /dev/null
@@ -0,0 +1,53 @@
+
+/*
+ * 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_
diff --git a/cion/channel/connection_info.cc b/cion/channel/connection_info.cc
deleted file mode 100755 (executable)
index 36698d1..0000000
+++ /dev/null
@@ -1,35 +0,0 @@
-/*
- * 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
diff --git a/cion/channel/connection_info.hh b/cion/channel/connection_info.hh
deleted file mode 100755 (executable)
index 32756cd..0000000
+++ /dev/null
@@ -1,52 +0,0 @@
-/*
- * 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_
old mode 100755 (executable)
new mode 100644 (file)
index 06cfc31..cffcf19
@@ -1,6 +1,5 @@
-
 /*
- * 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
+}
+}
old mode 100755 (executable)
new mode 100644 (file)
index cfbfc75..03636a9
@@ -1,6 +1,5 @@
-
 /*
- * 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
old mode 100755 (executable)
new mode 100644 (file)
index 3976d0c..905a8cf
@@ -1,5 +1,5 @@
 /*
- * 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
+}
+}
old mode 100755 (executable)
new mode 100644 (file)
index 9dbaf30..6addb01
@@ -1,5 +1,5 @@
 /*
- * 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
diff --git a/cion/channel/event_listener.hh b/cion/channel/event_listener.hh
deleted file mode 100755 (executable)
index 4e9fd17..0000000
+++ /dev/null
@@ -1,34 +0,0 @@
-/*
- * 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_
diff --git a/cion/channel/event_observer.hh b/cion/channel/event_observer.hh
deleted file mode 100755 (executable)
index db49e77..0000000
+++ /dev/null
@@ -1,47 +0,0 @@
-
-/*
- * 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_
diff --git a/cion/channel/event_sender.hh b/cion/channel/event_sender.hh
deleted file mode 100755 (executable)
index e3eece1..0000000
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- * 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_
diff --git a/cion/channel/iconnection_info.hh b/cion/channel/iconnection_info.hh
new file mode 100644 (file)
index 0000000..3d8bd6d
--- /dev/null
@@ -0,0 +1,52 @@
+/*
+ * 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_
diff --git a/cion/channel/icontrol_info.hh b/cion/channel/icontrol_info.hh
new file mode 100644 (file)
index 0000000..6355a9e
--- /dev/null
@@ -0,0 +1,47 @@
+
+/*
+ * 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_
diff --git a/cion/channel/idata_info.hh b/cion/channel/idata_info.hh
new file mode 100644 (file)
index 0000000..744f609
--- /dev/null
@@ -0,0 +1,39 @@
+/*
+ * 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_
diff --git a/cion/channel/ievent_listener.hh b/cion/channel/ievent_listener.hh
new file mode 100644 (file)
index 0000000..b66a167
--- /dev/null
@@ -0,0 +1,34 @@
+/*
+ * 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_
diff --git a/cion/channel/ievent_observer.hh b/cion/channel/ievent_observer.hh
new file mode 100644 (file)
index 0000000..b8fae58
--- /dev/null
@@ -0,0 +1,47 @@
+
+/*
+ * 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_
diff --git a/cion/channel/ievent_sender.hh b/cion/channel/ievent_sender.hh
new file mode 100644 (file)
index 0000000..733bc4d
--- /dev/null
@@ -0,0 +1,47 @@
+/*
+ * 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_
old mode 100755 (executable)
new mode 100644 (file)
index 71c290f..4808f77
  * 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) {
@@ -63,27 +82,59 @@ 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;
   }
 }
 
old mode 100755 (executable)
new mode 100644 (file)
index 50fccc3..2e868f5
 #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();
@@ -54,14 +51,14 @@ class EXPORT_API ServerChannel: public IEventObserver {
       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;
index 433b08d3f7411541053f9b3ccf7260b3c2af5158..8ec4114aa7cc080b89fe8fe8ee0e70ba4767f4dd 100644 (file)
@@ -32,7 +32,10 @@ class ServerChannel::Impl {
   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;
@@ -42,6 +45,7 @@ class ServerChannel::Impl {
   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
index 3a41f4704268ee5b7dbc74b021ad6dc00d4d493c..6ba0177c1efdd1e3b2222354c9979059980c9590 100644 (file)
@@ -18,9 +18,9 @@
 #include <unistd.h>
 #include <memory>
 
+#include "vine_manager.hh"
 #include "vine_listener.hh"
 #include "vine_listener_implementation.hh"
-#include "vine_manager.hh"
 
 namespace cion {
 
@@ -35,10 +35,11 @@ VineListener::Impl::Impl() {
 }
 
 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
index 6004a94343328069d7328fbc69f907c8d88d58f2..9f9a0c4a98dd8aa4204e5cf314fa8c6d95dc8967 100644 (file)
@@ -19,8 +19,8 @@
 
 #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 {
 
@@ -29,14 +29,13 @@ 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;
index 8148efd706d847c79107cd888c0e3cbebd9a7221..7d9b803def164484dce56526a764e0837db62421 100644 (file)
@@ -276,18 +276,18 @@ void VineManager::UnregisterObserver(channel::IEventObserver* observer) {
 }
 
 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
index 09d9fb6d9e9070b4ddb4e4dff859c780d991e288..84205995788691226f70e31251ab11eee2bbbfdd 100644 (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
@@ -40,19 +40,18 @@ namespace cion {
 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);
index fdf54734a1926391bd480736dae3b4ed3985dd8c..1197fe2cd6fe1de5976dff2bf2cf1809a2f79dd9 100644 (file)
 #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
index 0fab5aa2657dd6ad3cfa114842dfe5ace69be104..06f55c80c0f6c0341ceb9b3f5b3a77a607651f54 100644 (file)
 
 #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")))
@@ -36,21 +36,19 @@ namespace cion {
 
 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;
index 634951d37c71a0405f7740b0177ea957fdc8f24b..f16ae79f466e6939df74a745f39eae05997fbf6c 100644 (file)
 #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_;
 };