Remove using raw vine APIs
authorSangyoon Jang <jeremy.jang@samsung.com>
Wed, 24 Mar 2021 07:58:20 +0000 (16:58 +0900)
committer장상윤/Tizen Platform Lab(SR)/Engineer/삼성전자 <jeremy.jang@samsung.com>
Thu, 25 Mar 2021 08:11:16 +0000 (17:11 +0900)
Cion classes should not use raw vine APIs.

Change-Id: I011942639a2df0afb559c240ac2ce4e6e00d41a4
Signed-off-by: Sangyoon Jang <jeremy.jang@samsung.com>
12 files changed:
cion/channel/channel_job.hh
cion/channel/client_channel.cc
cion/channel/client_channel_implementation.hh
cion/channel/client_job copy.hh [deleted file]
cion/channel/client_peer_info.hh
cion/channel/connection_info.cc [deleted file]
cion/channel/connection_info.hh [deleted file]
cion/channel/server_channel.cc
cion/channel/server_channel_implementation.hh
cion/channel/server_peer_info.cc
cion/channel/server_peer_info.hh
cion/channel/session_info.hh [deleted file]

index a6ada5160dae07fbe5c970e5fdabde6c40f8f597..0d6312dd9a5eef8b2e1b41d62978add2a573345c 100644 (file)
 
 namespace cion {
 
+class VineDp;
+
 template <class T>
 class ChannelJob {
  public:
   ChannelJob() = default;
   ChannelJob(T* channel,
-      std::shared_ptr<tizen_base::Parcel> parcel, vine_dp_h dp)
+      std::shared_ptr<tizen_base::Parcel> parcel, std::shared_ptr<VineDp> dp)
     : channel_(channel), parcel_(parcel), client_dp_(dp) {
   }
 
@@ -39,7 +41,7 @@ class ChannelJob {
   }
   ~ChannelJob() = default;
 
-  vine_dp_h GetClientDp() {
+  std::shared_ptr<VineDp> GetClientDp() {
     return client_dp_;
   }
 
@@ -54,7 +56,7 @@ class ChannelJob {
  private:
   T* channel_;
   std::shared_ptr<tizen_base::Parcel> parcel_;
-  vine_dp_h client_dp_ = nullptr;
+  std::shared_ptr<VineDp> client_dp_ = nullptr;
 };
 
 }  // namespace cion
index 1b506ffdb83ca4f282aec6f78af280d9e54b2387..455069c451312869ba30009b2f8c91abbb6c8822 100644 (file)
@@ -20,7 +20,6 @@
 #include <glib.h>
 #include <glib-unix.h>
 #include <dlog.h>
-#include <vine.h>
 
 #include "cion/channel/client_channel.hh"
 #include "cion/channel/client_channel_implementation.hh"
@@ -63,9 +62,9 @@ ClientChannel::Impl::Impl(ClientChannel* parent, std::string service_name,
   }
 }
 
-std::shared_ptr<VineClientDp> ClientChannel::Impl::PopDp(vine_dp_h dp) {
+std::shared_ptr<VineClientDp> ClientChannel::Impl::PopDp(VineDpPtr dp) {
   for (std::shared_ptr<VineClientDp> i : dp_list_) {
-    if (i->GetRawDp() == dp) {
+    if (*i == *dp) {
       dp_list_.remove(i);
       return i;
     }
@@ -92,12 +91,12 @@ void ClientChannel::Impl::OnOpened(VineDpPtr dp, int result) {
 
 void ClientChannel::Impl::Disconnect(VineDpPtr dp) {
   if (connected_peer_ != nullptr && connected_peer_->GetVineClientDp()) {
-    if (connected_peer_->GetVineClientDp() == dp) {
+    if (*connected_peer_->GetVineClientDp() == *dp) {
       parent_->OnDisconnected(connected_peer_);
       connected_peer_ = nullptr;
     }
   }
-  PopDp(dp->GetRawDp());
+  PopDp(dp);
 }
 
 void ClientChannel::Impl::OnTerminated(VineDpPtr dp) {
@@ -127,7 +126,7 @@ void ClientChannel::Impl::OnReceived(
 
   ChannelJob<ClientChannel> job(parent_, std::make_shared<tizen_base::Parcel>(
         reinterpret_cast<unsigned char*>(data.data()),
-      data.size()), dp->GetRawDp());
+      data.size()), dp);
   queue_.Push(job);
 
   g_idle_add_full(G_PRIORITY_HIGH,
index b34fc17dd1df75400f152e4885e97f5ba4ba3e17..d7d88cf5ec24d73fbb3c8e34ed810b1be379ffeb 100644 (file)
@@ -26,7 +26,6 @@
 
 #include "cion/channel/client_channel.hh"
 #include "cion/channel/client_peer_info.hh"
-#include "cion/channel/connection_info.hh"
 #include "cion/channel/shared_queue.hh"
 #include "cion/channel/channel_job.hh"
 #include "cion/common/cion_cmd.hh"
@@ -42,12 +41,10 @@ class ClientChannel::Impl : public IVineBrowser, IVineDpOpenedEventHandler,
     IVineDpReceivedEventHandler, IVineDpTerminatedEventHandler {
  public:
   virtual ~Impl();
-  void HandlingRecvData(vine_dp_h client_dp, void* user_data);
-  void HandlingDiscoveredPeer(vine_dp_h client_dp, void* user_data);
   void SendPeerInfo(PeerInfo* peerinfo);
   void Send(cmd::CionCmd cmd, std::vector<char> raw);
   void Send(cmd::CionCmd cmd, std::vector<uint8_t> raw);
-  std::shared_ptr<VineClientDp> PopDp(vine_dp_h dp);
+  std::shared_ptr<VineClientDp> PopDp(std::shared_ptr<VineDp> dp);
   void Disconnect(VineDpPtr dp);
 
   void OnDiscovered(VineService service, std::string ip) override;
@@ -64,13 +61,11 @@ class ClientChannel::Impl : public IVineBrowser, IVineDpOpenedEventHandler,
   std::string service_name_;
   int channel_id_;
   std::shared_ptr<VineSession> session_;
-  vine_service_h service_;
   std::shared_ptr<ClientPeerInfo> connected_peer_;
   std::list<std::shared_ptr<VineClientDp>> dp_list_;
   bool is_discovering_ = false;
   SharedQueue<ChannelJob<ClientChannel>> queue_;
   SharedQueue<std::vector<char>> reply_queue_;
-  vine_dp_h server_dp_ = nullptr;
   std::shared_ptr<VineDiscoverer> discoverer_ = nullptr;
 };
 
diff --git a/cion/channel/client_job copy.hh b/cion/channel/client_job copy.hh
deleted file mode 100644 (file)
index 49eeea9..0000000
+++ /dev/null
@@ -1,62 +0,0 @@
-/*
- * 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_CHANNEL_CLIENT_JOB_HH_
-#define CION_CHANNEL_CLIENT_JOB_HH_
-
-#include <queue>
-#include <string>
-#include <memory>
-
-#include "cion/channel/client_channel.hh"
-
-namespace cion {
-
-class ClientJob {
- public:
-  ClientJob() = default;
-  ClientJob(channel::ClientChannel* channel,
-      std::shared_ptr<tizen_base::Parcel> parcel, vine_dp_h dp)
-    : channel_(channel), parcel_(parcel), client_dp_(dp) {
-  }
-
-  ClientJob(channel::ClientChannel* channel,
-      std::shared_ptr<tizen_base::Parcel> parcel)
-    : channel_(channel), parcel_(parcel) {
-  }
-  ~ClientJob() = default;
-
-  vine_dp_h GetClientDp() {
-    return client_dp_;
-  }
-
-  std::shared_ptr<tizen_base::Parcel> GetParcel() {
-    return parcel_;
-  }
-
-  channel::ClientChannel* GetChannel() {
-    return channel_;
-  }
-
- private:
-  channel::ClientChannel* channel_;
-  std::shared_ptr<tizen_base::Parcel> parcel_;
-  vine_dp_h client_dp_;
-};
-
-}  // namespace cion
-
-#endif  // CION_CHANNEL_CLIENT_JOB_HH_
index 37f804938a86bdcbfec35d397cbf0df026bc92d6..3526bf09e28fc7a0d1af8bf66848e71b901fd8a7 100644 (file)
 #define CION_CHANNEL_CLIENT_PEER_INFO_HH_
 
 #include <parcel/parcel.hh>
-#include <vine.h>
 
 #include <memory>
 #include <string>
 #include <vector>
 
 #include "cion/common/peer_info.hh"
-#include "cion/channel/connection_info.hh"
 #include "cion/vine/vine_client_dp.hh"
 
 namespace cion {
diff --git a/cion/channel/connection_info.cc b/cion/channel/connection_info.cc
deleted file mode 100644 (file)
index acd8026..0000000
+++ /dev/null
@@ -1,60 +0,0 @@
-/*
- * 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.
- */
-
-#include <dlog.h>
-
-#include "cion/channel/client_peer_info.hh"
-#include "cion/common/util/logging.hh"
-
-namespace cion {
-
-ConnectionInfo::ConnectionInfo(std::string ip,
-    vine_address_family_e address_family, int port,
-    vine_security_h security, vine_dp_h client_dp)
-  : ip_(ip), address_family_(address_family),
-    port_(port), security_(security), client_dp_(client_dp) {
-  LOG(INFO) << "create connection info " << client_dp_;
-}
-
-ConnectionInfo::~ConnectionInfo() {
-  LOG(WARNING) << "destroy connection info " << client_dp_;
-  vine_dp_destroy(client_dp_);
-}
-
-std::string ConnectionInfo::GetIp() {
-  return ip_;
-}
-
-vine_address_family_e ConnectionInfo::GetAddressFamliy() {
-  return address_family_;
-}
-
-int ConnectionInfo::GetPort() {
-  return port_;
-}
-
-vine_dp_h ConnectionInfo::GetDp() {
-  return client_dp_;
-}
-
-void ConnectionInfo::SetDp(vine_dp_h dp) {
-  client_dp_ = dp;
-}
-
-vine_security_h ConnectionInfo::GetSecurity() {
-  return security_;
-}
-}  // namespace cion
diff --git a/cion/channel/connection_info.hh b/cion/channel/connection_info.hh
deleted file mode 100644 (file)
index 098325d..0000000
+++ /dev/null
@@ -1,46 +0,0 @@
-/*
- * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * 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_CHANNEL_CONNECTION_INFO_HH_
-#define CION_CHANNEL_CONNECTION_INFO_HH_
-
-#include <vine.h>
-
-#include <string>
-
-namespace cion {
-class ConnectionInfo {
- public:
-  explicit ConnectionInfo(std::string ip, vine_address_family_e address_family,
-      int port, vine_security_h security, vine_dp_h client_dp);
-  ~ConnectionInfo();
-  std::string GetIp();
-  vine_address_family_e GetAddressFamliy();
-  int GetPort();
-  vine_dp_h GetDp();
-  void SetDp(vine_dp_h dp);
-  vine_security_h GetSecurity();
-
- private:
-  std::string ip_;
-  vine_address_family_e address_family_;
-  int port_;
-  vine_security_h security_;
-  vine_dp_h client_dp_;
-};
-
-}   // namespace cion
-
-#endif  // CION_CHANNEL_CONNECTION_INFO_HH_
index c81c664417f093bad4480e8d9a1833a2f3272e8f..d48655ca9cdc9c45a733a55c2b7158135fc03e27 100644 (file)
@@ -20,7 +20,6 @@
 
 #include <glib.h>
 #include <glib-unix.h>
-#include <vine.h>
 
 #include "cion/channel/server_channel.hh"
 #include "cion/channel/server_peer_info.hh"
@@ -62,7 +61,7 @@ void ServerChannel::Impl::OnReceived(
     VineDpPtr dp, std::vector<unsigned char> data) {
   LOG(INFO) << "OnReceived " << dp->GetRawDp();
   ChannelJob<ServerChannel> job(parent_, std::make_shared<tizen_base::Parcel>(
-    data.data(), data.size()), dp->GetRawDp());
+    data.data(), data.size()), dp);
   queue_.Push(job);
 
   g_idle_add_full(G_PRIORITY_HIGH,
@@ -159,7 +158,7 @@ void ServerChannel::Impl::OnTerminated(VineDpPtr dp) {
   for (std::shared_ptr<PeerInfo> peer : peerlist_) {
     std::shared_ptr<ServerPeerInfo> speer =
         std::dynamic_pointer_cast<ServerPeerInfo>(peer);
-    if (speer->GetClientDp() == dp->GetRawDp()) {
+    if (speer->GetClientDp() == dp) {
       LOG(INFO) << "Remove peer from connected peer list " << dp->GetRawDp();
       parent_->OnDisconnected(peer);
       peerlist_.remove(peer);
@@ -173,8 +172,7 @@ void ServerChannel::Impl::OnAccepted(VineDpPtr dp, VineDpPtr accepted_dp) {
   accepted_dp->SetDpReceivedEventHandler(this);
   accepted_dp->SetDpTerminatedEventHandler(this);
   accepted_dp_list_.push_back(accepted_dp);
-  Send(cmd::CionCmd::PeerInfo, accepted_dp->GetRawDp(),
-      my_peer_info_->Serialize());
+  Send(cmd::CionCmd::PeerInfo, accepted_dp, my_peer_info_->Serialize());
 }
 
 ServerChannel::~ServerChannel() {
@@ -193,27 +191,25 @@ ServerChannel::Impl::Impl(
   my_peer_info_ = std::make_shared<PeerInfo>();
 }
 
-void ServerChannel::Impl::Send(cmd::CionCmd cmd, vine_dp_h client_dp,
+void ServerChannel::Impl::Send(cmd::CionCmd cmd, VineDpPtr client_dp,
       std::vector<char> raw) {
   tizen_base::Parcel parcel;
   parcel.WriteUInt32(cmd);
   parcel.WriteUInt32(raw.size());
   parcel.Write(raw.data(), raw.size());
 
-  VineDp dp(client_dp, false);
-  dp.SendDataAsync(parcel.GetRaw());
+  client_dp->SendDataAsync(parcel.GetRaw());
   LOG(INFO) << "send " << parcel.GetRaw().size();
 }
 
-void ServerChannel::Impl::Send(cmd::CionCmd cmd, vine_dp_h client_dp,
+void ServerChannel::Impl::Send(cmd::CionCmd cmd, VineDpPtr client_dp,
     std::vector<uint8_t> raw) {
   tizen_base::Parcel parcel;
   parcel.WriteUInt32(cmd);
   parcel.WriteUInt32(raw.size());
   parcel.Write(raw.data(), raw.size());
 
-  VineDp dp(client_dp, false);
-  dp.SendDataAsync(parcel.GetRaw());
+  client_dp->SendDataAsync(parcel.GetRaw());
   LOG(WARNING) << "send " << parcel.GetRaw().size();
 }
 
@@ -239,12 +235,10 @@ void ServerChannel::Disconnect(std::shared_ptr<PeerInfo> peer) {
       std::dynamic_pointer_cast<ServerPeerInfo>(i);
     if (si->GetClientDp() == speer->GetClientDp())
       impl_->peerlist_.remove(i);
-
-    vine_dp_close(speer->GetClientDp());
   }
 
   for (VineDpPtr ptr : impl_->accepted_dp_list_) {
-    if (ptr->GetRawDp() == speer->GetClientDp())
+    if (ptr == speer->GetClientDp())
       impl_->accepted_dp_list_.remove(ptr);
   }
 }
index b47183011e85b4d3da366460fd816de145d3c27b..7790713c4c906b7af6fd9b0e55d0cd5457b39c05 100644 (file)
@@ -23,8 +23,6 @@
 #include <list>
 #include <memory>
 
-#include <vine.h>
-
 #include "cion/channel/server_channel.hh"
 #include "cion/channel/shared_queue.hh"
 #include "cion/channel/channel_job.hh"
@@ -52,11 +50,8 @@ class ServerChannel::Impl : public IVineDpOpenedEventHandler,
   Impl(ServerChannel* parent, std::string service_name,
       int channel_id);
 
-  void Send(cmd::CionCmd cmd, vine_dp_h client_dp,
-      std::vector<char> raw);
-  void Send(cmd::CionCmd cmd, vine_dp_h client_dp,
-      std::vector<uint8_t> raw);
-  void HandlingRecvData(vine_dp_h client_dp, void* user_data);
+  void Send(cmd::CionCmd cmd, VineDpPtr client_dp, std::vector<char> raw);
+  void Send(cmd::CionCmd cmd, VineDpPtr client_dp, std::vector<uint8_t> raw);
 
  private:
   friend class ServerChannel;
index 50a8bab3569250cf882250d5b537ed7e3395d2f7..7ed854224575abe4809e3cf7f26cdc1bdcd8a264 100644 (file)
@@ -26,7 +26,7 @@ ServerPeerInfo::ServerPeerInfo() : PeerInfo() {
 }
 
 ServerPeerInfo::ServerPeerInfo(const void* buf, uint32_t size,
-    vine_dp_h client_dp)
+    std::shared_ptr<VineDp> client_dp)
   : PeerInfo(buf, size), client_dp_(client_dp) {
   LOG(INFO) << "server peer info " << GetUUID();
 }
@@ -38,10 +38,9 @@ ServerPeerInfo::ServerPeerInfo(const ServerPeerInfo& peerinfo)
 ServerPeerInfo::~ServerPeerInfo() {
   LOG(WARNING) << "destroy server peer info "
       << GetUUID() << ", " << client_dp_;
-  vine_dp_destroy(client_dp_);
 }
 
-vine_dp_h ServerPeerInfo::GetClientDp() {
+std::shared_ptr<VineDp> ServerPeerInfo::GetClientDp() {
   return client_dp_;
 }
 
index fba35ca8c26839a03571c28925e09ed690e3015b..6c35e2eb6fc4620dd419917ecfb3d659d3930d1d 100644 (file)
@@ -18,7 +18,6 @@
 #define CION_CHANNEL_SERVER_PEER_INFO_HH_
 
 #include <parcel/parcel.hh>
-#include <vine.h>
 
 #include <memory>
 #include <string>
 
 namespace cion {
 
+class VineDp;
+
 class ServerPeerInfo : public PeerInfo {
  public:
   ServerPeerInfo();
-  ServerPeerInfo(const void* buf, uint32_t size, vine_dp_h client_dp);
+  ServerPeerInfo(const void* buf, uint32_t size,
+      std::shared_ptr<VineDp> client_dp);
   ServerPeerInfo(const ServerPeerInfo& peerinfo);
   ~ServerPeerInfo();
-  vine_dp_h GetClientDp();
+  std::shared_ptr<VineDp> GetClientDp();
 
  private:
-  vine_dp_h client_dp_;
+  std::shared_ptr<VineDp> client_dp_;
 };
 
 }  // namespace cion
diff --git a/cion/channel/session_info.hh b/cion/channel/session_info.hh
deleted file mode 100644 (file)
index f4227ef..0000000
+++ /dev/null
@@ -1,86 +0,0 @@
-/*
- * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * 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 VINE_MANAGER_SESSION_INFO_HH_
-#define VINE_MANAGER_SESSION_INFO_HH_
-
-#include<string>
-#include<list>
-#include<map>
-#include<memory>
-
-#include "cion/common/peer_info.hh"
-#include "session_info.hh"
-
-namespace cion {
-class SessionInfo {
- public:
-  explicit SessionInfo(int channel_id) {
-    channel_id_ = channel_id;
-  }
-
-  SessionInfo(int channel_id, vine_session_h session) {
-    channel_id_ = channel_id;
-    session_ = session;
-  }
-
-  void SetService(vine_service_h service) {
-    service_ = service;
-  }
-
-  vine_service_h GetService() {
-    return service_;
-  }
-
-  vine_session_h GetSession() {
-    return session_;
-  }
-
-  void SetPort(int port) {
-    vine_service_set_port(service_, port);
-  }
-
-  int GetChannelId() {
-    return channel_id_;
-  }
-
-  void AddDataPath(std::string uuid, vine_dp_h dp) {
-    dp_map_[uuid] = dp;
-  }
-
-  vine_dp_h GetDataPath(std::string uuid) {
-    return dp_map_[uuid];
-  }
-
-  bool IsDiscovering() {
-    return is_discovering_;
-  }
-
-  void SetIsDiscovering(bool is_discovering) {
-    is_discovering_ = is_discovering;
-  }
-
- private:
-  std::map<std::string, vine_dp_h> dp_map_;
-  bool is_discovering_ = false;
-  vine_dp_h dp_;
-  vine_session_h session_;
-  vine_service_h service_;
-  int channel_id_;
-};
-
-}   // namespace cion
-
-#endif  // VINE_MANAGER_SESSION_INFO_HH_