Cion classes should not use raw vine APIs.
Change-Id: I011942639a2df0afb559c240ac2ce4e6e00d41a4
Signed-off-by: Sangyoon Jang <jeremy.jang@samsung.com>
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) {
}
}
~ChannelJob() = default;
- vine_dp_h GetClientDp() {
+ std::shared_ptr<VineDp> GetClientDp() {
return client_dp_;
}
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
#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"
}
}
-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;
}
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) {
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,
#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"
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;
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;
};
+++ /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_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_
#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 {
+++ /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.
- */
-
-#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
+++ /dev/null
-/*
- * 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_
#include <glib.h>
#include <glib-unix.h>
-#include <vine.h>
#include "cion/channel/server_channel.hh"
#include "cion/channel/server_peer_info.hh"
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,
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);
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() {
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();
}
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);
}
}
#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"
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;
}
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();
}
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_;
}
#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
+++ /dev/null
-/*
- * 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_