ADD_SUBDIRECTORY(cion)
#ADD_SUBDIRECTORY(cion-service)
-ADD_SUBDIRECTORY(vine_wrapper)
-ADD_SUBDIRECTORY(vine_manager)
IF(NOT DEFINED MINIMUM_BUILD)
ENABLE_TESTING()
AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/channel/ CHANNEL_SOURCES)
AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/security SECURITY_SOURCES)
AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/tizen-api/ SOURCES)
+AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/vine_manager/ SOURCES)
+AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/vine_wrapper/ SOURCES)
ADD_LIBRARY(${TARGET_CION} SHARED ${SOURCES} ${COMMON_SOURCES} ${CHANNEL_SOURCES} ${SECURITY_SOURCES})
TARGET_INCLUDE_DIRECTORIES(${TARGET_CION} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/../)
PARCEL_DEPS
PKGMGR_INFO_DEPS
UUID_DEPS
+ VINE_DEPS
)
SET_TARGET_PROPERTIES(${TARGET_CION} PROPERTIES VERSION ${FULLVER})
* limitations under the License.
*/
-#include "broadcast_channel.hh"
+#include "cion/channel/broadcast_channel.hh"
/**
* BroadcastChannel implementation
#include <string>
#include <vector>
-#include "ievent_observer.hh"
-#include "ievent_listener.hh"
-#include "ievent_sender.hh"
+#include "cion/channel/ievent_observer.hh"
+#include "cion/channel/ievent_listener.hh"
+#include "cion/channel/ievent_sender.hh"
#include "cion/common/peer_info.hh"
#include "cion/common/interface_payload.hh"
* limitations under the License.
*/
+#include "cion/channel/client_channel.hh"
+
#include <memory>
-#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/channel/client_channel_implementation.hh"
+#include "cion/channel/control_info.hh"
+#include "cion/channel/data_info.hh"
#include "cion/common/util/id_generator.hh"
+#include "cion/vine_manager/vine_manager.hh"
+#include "cion/vine_manager/vine_sender.hh"
+#include "cion/vine_manager/vine_listener.hh"
/**
* ClientChannel implementation
#include <memory>
#include <vector>
-#include "ievent_observer.hh"
-#include "ievent_listener.hh"
-#include "ievent_sender.hh"
+#include "cion/channel/ievent_observer.hh"
+#include "cion/channel/ievent_listener.hh"
+#include "cion/channel/ievent_sender.hh"
#include "cion/security/security_info.hh"
#include "cion/common/peer_info.hh"
#include "cion/common/interface_payload.hh"
#include <vector>
#include <list>
-#include "client_channel.hh"
+#include "cion/channel/client_channel.hh"
namespace cion {
namespace channel {
#include <vector>
#include <string>
-#include "icontrol_info.hh"
+#include "cion/channel/icontrol_info.hh"
namespace cion {
namespace channel {
* limitations under the License.
*/
-#include "data_info.hh"
+#include "cion/channel/data_info.hh"
namespace cion {
namespace channel {
#include <vector>
#include <string>
-#include "idata_info.hh"
+#include "cion/channel/idata_info.hh"
namespace cion {
namespace channel {
#ifndef CION_CION_CHANNEL_EVENT_LISTENER_HH_
#define CION_CION_CHANNEL_EVENT_LISTENER_HH_
-#include "ievent_observer.hh"
+#include "cion/channel/ievent_observer.hh"
namespace cion {
namespace channel {
#include <string>
#include <vector>
-#include "iconnection_info.hh"
-#include "idata_info.hh"
+#include "cion/channel/iconnection_info.hh"
+#include "cion/channel/idata_info.hh"
#include "cion/common/interface_payload.hh"
namespace cion {
#include <vector>
#include <memory>
-#include "idata_info.hh"
-#include "icontrol_info.hh"
+#include "cion/channel/idata_info.hh"
+#include "cion/channel/icontrol_info.hh"
#include "cion/common/peer_info.hh"
#include "cion/security/security_info.hh"
#include <memory>
-#include "server_channel.hh"
-#include "server_channel_implementation.hh"
-#include "control_info.hh"
+#include "cion/channel/server_channel.hh"
-#include "vine_manager/vine_manager.hh"
-#include "vine_manager/vine_sender.hh"
-#include "vine_manager/vine_listener.hh"
+#include "cion/channel/server_channel_implementation.hh"
+#include "cion/channel/control_info.hh"
#include "cion/common/util/id_generator.hh"
+#include "cion/vine_manager/vine_manager.hh"
+#include "cion/vine_manager/vine_sender.hh"
+#include "cion/vine_manager/vine_listener.hh"
/**
* ServerChannel implementation
#include <string>
#include <vector>
-#include "ievent_observer.hh"
-#include "ievent_sender.hh"
-#include "ievent_listener.hh"
+#include "cion/channel/ievent_observer.hh"
+#include "cion/channel/ievent_sender.hh"
+#include "cion/channel/ievent_listener.hh"
#include "cion/security/security_info.hh"
#include "cion/common/peer_info.hh"
#include "cion/common/interface_payload.hh"
#include <vector>
#include <list>
-#include "server_channel.hh"
+#include "cion/channel/server_channel.hh"
namespace cion {
namespace channel {
* limitations under the License.
*/
-#include "data_payload.hh"
+#include "cion/common/data_payload.hh"
#include <stdexcept>
#include <vector>
-#include "interface_payload.hh"
+#include "cion/common/interface_payload.hh"
namespace cion {
* limitations under the License.
*/
-#include "file_payload.hh"
+#include "cion/common/file_payload.hh"
namespace cion {
#include <vector>
#include <string>
-#include "interface_payload.hh"
+#include "cion/common/interface_payload.hh"
namespace cion {
* limitations under the License.
*/
-#include "factory_manager.hh"
-#include "../interface_payload.hh"
-#include "../data_payload.hh"
-#include "../file_payload.hh"
+#include "cion/common/util/factory_manager.hh"
+
+#include "cion/common/interface_payload.hh"
+#include "cion/common/data_payload.hh"
+#include "cion/common/file_payload.hh"
namespace cion {
* limitations under the License.
*/
-#include "id_generator.hh"
+#include "cion/common/util/id_generator.hh"
namespace cion {
* limitations under the License.
*/
-#include "security_info.hh"
+#include "cion/security/security_info.hh"
namespace cion {
--- /dev/null
+/*
+ * Copyright (c) 2020 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.
+ */
+
+#include <dlog.h>
+#include <unistd.h>
+#include <memory>
+
+#include "cion/vine_manager/vine_manager.hh"
+#include "cion/vine_manager/vine_listener.hh"
+#include "cion/vine_manager/vine_listener_implementation.hh"
+
+namespace cion {
+
+VineListener::VineListener()
+ : impl_(new Impl()) {
+}
+
+VineListener::~VineListener() {
+}
+
+VineListener::Impl::Impl() {
+}
+
+void VineListener::RegisterObserver(channel::IEventObserver* observer) {
+ VineManager::GetInst().RegisterObserver(observer);
+}
+
+void VineListener::UnregisterObserver(channel::IEventObserver* observer) {
+ VineManager::GetInst().UnregisterObserver(observer);
+}
+
+} // namespace cion
--- /dev/null
+/*
+ * Copyright (c) 2020 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_VINE_MANAGER_VINE_LISTENER_HH_
+#define CION_VINE_MANAGER_VINE_LISTENER_HH_
+
+#include <memory>
+
+#include "cion/channel/ievent_observer.hh"
+#include "cion/channel/ievent_listener.hh"
+
+namespace cion {
+
+#ifndef EXPORT_API
+#define EXPORT_API __attribute__((visibility("default")))
+#endif
+
+class EXPORT_API VineListener : public channel::IEventListener {
+
+ public:
+ VineListener();
+ virtual ~VineListener();
+ void RegisterObserver(channel::IEventObserver* observer) override;
+ void UnregisterObserver(channel::IEventObserver* observer) override;
+
+
+ private:
+ class Impl;
+ std::unique_ptr<Impl> impl_;
+};
+
+} // namespace cion
+
+#endif // CION_VINE_MANAGER_VINE_LISTENER_HH_
--- /dev/null
+/*
+ * Copyright (c) 2020 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_API_VINE_LISTENER_IMPLEMENTATION_HH_
+#define CION_API_VINE_LISTENER_IMPLEMENTATION_HH_
+
+namespace cion {
+
+class VineListener::Impl {
+ public:
+ virtual ~Impl() = default;
+
+ private:
+ friend class VineListener;
+ Impl();
+
+
+ private:
+};
+
+} // namespace cion
+
+#endif // CION_API_VINE_LISTENER_IMPLEMENTATION_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.
+ */
+
+#include <dlog.h>
+#include <unistd.h>
+#include <vine.h>
+#include <glib-unix.h>
+#include <sys/socket.h>
+#include <sys/types.h>
+
+#include <memory>
+#include <utility>
+
+#include "cion/vine_manager/vine_manager.hh"
+#include "cion/vine_manager/vine_manager_implementation.hh"
+
+#ifdef LOG_TAG
+#undef LOG_TAG
+#endif
+
+#define LOG_TAG "VINE_MANAGER"
+
+#define VINE_TEST_TOPIC "CION_TOPIC"
+#define VINE_TEST_SERVICE "CION_TEST"
+#define VINE_TEST_SERVER_PORT 55555
+#define VINE_TEST_CLIENT_PORT 55556
+#define VINE_TEST_SERVICE_TYPE "_cion"
+
+namespace cion {
+
+VineManager& VineManager::GetInst() {
+ static VineManager w_inst;
+ int ret;
+
+ if (w_inst.impl_ == nullptr) {
+ ret = w_inst.Init();
+ if (ret != CION_ERROR_NONE)
+ throw ret;
+ }
+ return w_inst;
+}
+
+VineManager::VineManager() = default;
+VineManager::~VineManager() = default;
+VineManager::Impl::Impl() = default;
+
+VineManager::Impl::~Impl() {
+ vine_session_unset_discovered_cb(session_);
+ vine_deinitialize();
+}
+
+int VineManager::Init() {
+ std::unique_ptr<Impl> tmp_impl;
+
+ try {
+ tmp_impl = std::unique_ptr<VineManager::Impl>(new Impl());
+ } catch (const std::bad_alloc &ba) {
+ LOGE("Out of memory");
+ return -1;
+ }
+
+ impl_ = std::move(tmp_impl);
+ vine_initialize();
+ vine_session_create(&impl_->session_);
+ int fd;
+ vine_session_get_event_fd(impl_->session_, &fd);
+ g_unix_fd_add(fd, G_IO_IN, [] (int fd, GIOCondition condition,
+ gpointer user_data) -> int {
+ LOGE("@@@ gio in!!");
+ VineManager* ptr = (VineManager*)user_data;
+ vine_session_process_event(ptr->impl_->session_);
+ LOGE("@@@ process event done !!");
+ return G_SOURCE_CONTINUE;
+ }, this);
+
+ LOGI("VineManager init done");
+ return 0;
+}
+
+void VineManager::Impl::AddSenderInfo(std::string service_name,
+ int channel_id) {
+ for (auto& sender : sender_list_) {
+ if (service_name == sender.GetServiceName()
+ && channel_id == sender.GetChannelId()) {
+ LOGW("Already exist");
+ return;
+ }
+ }
+ SenderInfo info(service_name, channel_id);
+ sender_list_.push_back(info);
+}
+
+bool VineManager::Impl::ValidateSender(std::string service_name) {
+ for (auto& sender : sender_list_) {
+ if (service_name == sender.GetServiceName())
+ return true;
+ }
+ return false;
+}
+
+void VineManager::Discovery() {
+ vine_session_set_discovered_cb(impl_->session_,
+ [] (vine_session_h session, vine_service_h service,
+ vine_service_state_e state, void *user_data) -> void {
+ char* name;
+ int port;
+ vine_service_get_name(service, &name);
+ vine_service_get_port(service, &port);
+
+ LOGD("Available Service");
+ LOGD("Service Name: %s", name);
+ LOGD("Port: %d", port);
+
+ VineManager* ptr = (VineManager*)user_data;
+ if (ptr == nullptr) {
+ LOGE("null vine manager");
+ return;
+ }
+
+ if (state == VINE_SERVICE_AVAILABLE) {
+ LOGW("A service is discovered\n");
+ /*
+
+
+
+ vine_dp_h dp;
+ vine_dp_create(session, VINE_DP_TYPE_PUBSUB, &dp);
+ vine_dp_set_port(dp, VINE_TEST_CLIENT_PORT);
+ vine_dp_set_topic(dp, VINE_TEST_TOPIC);
+ vine_dp_open(dp,
+ [](vine_dp_h dp, vine_error_e result, void *user_data) {
+ LOGW("@@@@@@@ open");
+ std::string msg = "test string";
+ vine_dp_send(dp, (unsigned char*)msg.c_str(), msg.size());
+ }, nullptr);
+*/
+ vine_session_set_ip_resolved_cb(ptr->impl_->session_, service,
+ [] (vine_session_h session, vine_service_h service,
+ const char *ip, vine_address_family_e address_family,
+ void *user_data) -> void {
+ LOGW("IP address: %s\n", ip);
+ vine_dp_h dp;
+ vine_dp_create(session, VINE_DP_TYPE_CLIENT, &dp);
+ vine_dp_set_remote_ip(dp, VINE_ADDRESS_FAMILY_IPV4, ip);
+ vine_dp_set_security(dp, nullptr);
+ vine_dp_set_port(dp, VINE_TEST_SERVER_PORT);
+ vine_dp_open(dp,
+ [](vine_dp_h dp, vine_error_e result, void *user_data)
+ -> void {
+ LOGW("@@@@@@@ open");
+ vine_dp_send(dp, (unsigned char*)"TEST", 5);
+ }, nullptr);
+ }, nullptr);
+ }
+ }, this);
+ vine_session_start_discovery(impl_->session_,
+ VINE_TEST_SERVICE_TYPE, nullptr);
+}
+
+void VineManager::RegisterSender(std::string service_name, int channel_id) {
+ impl_->AddSenderInfo(service_name, channel_id);
+}
+
+void VineManager::UnregisterSender(int channel_id) {
+}
+
+void VineManager::RegisterObserver(channel::IEventObserver* observer) {
+ vine_session_set_registered_cb(impl_->session_, [] (
+ vine_session_h session, const char* service_name,
+ vine_error_e error, void* user_data) -> void {
+ LOGI("session registered : %s", service_name);
+
+ /*vine_dp_h dp;
+ vine_dp_create(session, VINE_DP_TYPE_PUBSUB, &dp);
+ vine_dp_set_address_family(g_pubsub_dp, VINE_ADDRESS_FAMILY_IPV4);
+ vine_dp_set_port(dp, VINE_TEST_SERVER_PORT);
+ vine_dp_set_topic(dp, VINE_TEST_TOPIC);
+ vine_dp_open(dp,
+ [](vine_dp_h dp, vine_error_e result, void *user_data) {
+
+ vine_dp_set_received_cb(dp, [](vine_dp_h dp, size_t received_len,
+ void *user_data) {
+ unsigned char buf[20] = {0, };
+ size_t bytes = 0;
+ LOGW("[RECV_CB] %p received %zd bytes.", dp, received_len);
+ printf("[RECV_CB] %p received %zd bytes.\n", dp, received_len);
+ do {
+ vine_dp_recv(dp, buf, 20, &bytes);
+ for (int i = 0; i < (int)received_len; i++)
+ printf("%c", buf[i]);
+ printf("\n");
+ received_len -= bytes;
+ } while (received_len > 0);
+ }, nullptr);
+
+ LOGW("@@@@@@@ open");
+ //std::string msg = "test string";
+ //vine_dp_send(dp, (unsigned char*)msg.c_str(), msg.size());
+ }, nullptr);*/
+
+
+ vine_dp_h dp;
+ vine_dp_create(session, VINE_DP_TYPE_SERVER, &dp);
+ vine_dp_set_port(dp, VINE_TEST_SERVER_PORT);
+ vine_dp_open(dp,
+ [] (vine_dp_h dp, vine_error_e result, void *user_data) -> void {
+ LOGW("Opened !!!");
+ vine_dp_set_received_cb(dp, [](vine_dp_h dp, size_t received_len,
+ void *user_data) -> void {
+ unsigned char buf[20] = {0, };
+ size_t bytes = 0;
+ LOGW("[RECV_CB] %p received %zd bytes.", dp, received_len);
+ printf("[RECV_CB] %p received %zd bytes.\n", dp, received_len);
+ do {
+ vine_dp_recv(dp, buf, 20, &bytes);
+ for (int i = 0; i < (int)received_len; i++)
+ printf("%c", buf[i]);
+ printf("\n");
+ received_len -= bytes;
+ } while (received_len > 0);
+ }, nullptr);
+
+ }, nullptr);
+ vine_dp_set_accepted_cb(dp, [] (vine_dp_h dp, void *user_data) -> void {
+ }, nullptr);
+
+ }, nullptr);
+
+ vine_service_h service;
+ vine_service_create(&service);
+ vine_service_set_type(service, VINE_TEST_SERVICE_TYPE);
+ std::string channel_id = "test";
+
+ vine_service_set_name(service, VINE_TEST_SERVICE);
+ impl_->port_ = VINE_TEST_SERVER_PORT;
+ vine_service_set_port(service, impl_->port_);
+ vine_service_add_attribute(service, "id", VINE_TEST_SERVICE);
+ vine_service_add_attribute(service,
+ "channel", channel_id.c_str());
+ impl_->service_ = service;
+
+ vine_session_register(impl_->session_, service, nullptr);
+ LOGI("session register !! : %s", VINE_TEST_SERVICE);
+}
+
+void VineManager::UnregisterObserver(channel::IEventObserver* observer) {
+}
+
+void VineManager::SendDataAsync(const std::vector<char>& serialized_payload,
+ std::shared_ptr<channel::IDataInfo> info, int channel_id,
+ std::shared_ptr<PeerInfo> peer_info) {
+}
+
+std::vector<char> VineManager::SendData(
+ const std::vector<char>& serialized_payload,
+ std::shared_ptr<channel::IDataInfo> info, int channel_id,
+ std::string peer_uuid, int timeout) {
+ return {};
+}
+
+void VineManager::OperateChannel(int channel_id,
+ std::shared_ptr<channel::IControlInfo> info,
+ std::shared_ptr<PeerInfo> peer_info) {
+}
+
+} // namespace cion
\ No newline at end of file
--- /dev/null
+/*
+ * Copyright (c) 2020 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_VINE_MANAGER_VINE_MANAGER_HH_
+#define CION_VINE_MANAGER_VINE_MANAGER_HH_
+
+#include <vector>
+#include <string>
+#include <memory>
+
+#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"
+
+#ifndef EXPORT_API
+#define EXPORT_API __attribute__((visibility("default")))
+#endif
+
+namespace cion {
+
+class EXPORT_API VineManager {
+ public:
+ static VineManager& GetInst();
+ 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(const std::vector<char>& serialized_payload,
+ std::shared_ptr<channel::IDataInfo> info, int channel_id,
+ std::shared_ptr<PeerInfo> peer_info);
+ std::vector<char> SendData(const std::vector<char>& serialized_payload,
+ std::shared_ptr<channel::IDataInfo> info, int channel_id,
+ std::string peer_uuid, int timeout);
+ void OperateChannel(int channel_id,
+ std::shared_ptr<channel::IControlInfo> info,
+ std::shared_ptr<PeerInfo> peer_info);
+ void Discovery();
+ VineManager();
+
+ private:
+ virtual ~VineManager();
+ int Init();
+
+ private:
+ class Impl;
+ std::unique_ptr<Impl> impl_;
+};
+
+} // namespace cion
+
+#endif // CION_VINE_MANAGER_VINE_MANAGER_HH_
--- /dev/null
+/*
+ * Copyright (c) 2020 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_API_VINE_MANAGER_IMPLEMENTATION_HH_
+#define CION_API_VINE_MANAGER_IMPLEMENTATION_HH_
+
+#include<string>
+#include<list>
+#include<dlog.h>
+
+#ifdef LOG_TAG
+#undef LOG_TAG
+#endif
+
+#define LOG_TAG "VINE_MANAGER"
+
+
+namespace cion {
+
+class SenderInfo {
+ public:
+ SenderInfo(std::string service_name, int channel_id) {
+ service_name_ = service_name;
+ channel_id_ = channel_id;
+ }
+
+ std::string GetServiceName() {
+ return service_name_;
+ }
+
+ int GetChannelId() {
+ return channel_id_;
+ }
+
+ private:
+ std::string service_name_;
+ int channel_id_;
+};
+
+class VineManager::Impl {
+ public:
+ virtual ~Impl();
+ void AddSenderInfo(std::string service_name, int channel_id);
+ bool ValidateSender(std::string service_name);
+
+ private:
+ friend class VineManager;
+ Impl();
+
+ private:
+ vine_session_h session_;
+ vine_service_h service_;
+ std::list<SenderInfo> sender_list_;
+ int port_;
+};
+
+} // namespace cion
+
+#endif // CION_API_VINE_MANAGER_IMPLEMENTATION_HH_
--- /dev/null
+/*
+ * Copyright (c) 2020 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.
+ */
+
+#include <dlog.h>
+#include <unistd.h>
+#include <memory>
+
+#include "vine_manager.hh"
+
+#include "cion/vine_manager/vine_sender.hh"
+#include "cion/vine_manager/vine_sender_implementation.hh"
+
+namespace cion {
+
+VineSender::VineSender(std::string service_name, int channel_id)
+ : impl_(new Impl(service_name, channel_id)) {
+}
+
+VineSender::~VineSender() {
+
+}
+
+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(
+ std::shared_ptr<channel::IControlInfo> info,
+ std::shared_ptr<PeerInfo> peer_info) {
+ VineManager::GetInst().OperateChannel(channel_id_, info, peer_info);
+}
+
+void VineSender::SendDataAsync(const std::vector<char>& serialized_payload,
+ std::shared_ptr<channel::IDataInfo> info,
+ std::shared_ptr<PeerInfo> peer_info) {
+}
+
+std::vector<char> VineSender::SendData(
+ const std::vector<char>& serialized_payload,
+ std::shared_ptr<channel::IDataInfo> info,
+ std::shared_ptr<PeerInfo> peer_info, int timeout) {
+ return {};
+}
+
+void VineSender::OperateChannel(std::shared_ptr<channel::IControlInfo> info,
+ std::shared_ptr<PeerInfo> peer_info) {
+ impl_->OperateChannel(info, peer_info);
+}
+
+void VineSender::SetSecurity(SecurityInfo sec) {
+}
+
+} // 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_VINE_MANAGER_VINE_SENDER_HH_
+#define CION_VINE_MANAGER_VINE_SENDER_HH_
+
+#include <string>
+#include <vector>
+#include <memory>
+
+#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 "cion/channel/ievent_sender.hh"
+#include "cion/security/security_info.hh"
+
+#ifndef EXPORT_API
+#define EXPORT_API __attribute__((visibility("default")))
+#endif
+
+namespace cion {
+
+class EXPORT_API VineSender : public channel::IEventSender {
+ public:
+ VineSender(std::string service_name, int channel_id);
+ virtual ~VineSender();
+
+ protected:
+ void SendDataAsync(const std::vector<char>& serialized_payload,
+ std::shared_ptr<channel::IDataInfo> info,
+ std::shared_ptr<PeerInfo> peer_info) override;
+ std::vector<char> SendData(const std::vector<char>& serialized_payload,
+ std::shared_ptr<channel::IDataInfo> info,
+ std::shared_ptr<PeerInfo> peer_info, int timeout) override;
+ void OperateChannel(std::shared_ptr<channel::IControlInfo> info,
+ std::shared_ptr<PeerInfo> peer_info) override;
+ void SetSecurity(SecurityInfo sec) override;
+
+ private:
+ class Impl;
+ std::unique_ptr<Impl> impl_;
+};
+
+} // namespace cion
+
+#endif // CION_VINE_MANAGER_VINE_SENDER_HH_
--- /dev/null
+/*
+ * Copyright (c) 2020 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_API_VINE_SENDER_IMPLEMENTATION_HH_
+#define CION_API_VINE_SENDER_IMPLEMENTATION_HH_
+
+#include <memory>
+
+#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();
+
+ private:
+ friend class VineSender;
+
+ explicit Impl(std::string service_name, int channel_id);
+ void OperateChannel(std::shared_ptr<channel::IControlInfo> info,
+ std::shared_ptr<PeerInfo> peer_info);
+
+ private:
+ std::string service_name_;
+ int channel_id_;
+ int port_;
+};
+
+} // namespace cion
+
+#endif // CION_API_VINE_SENDER_IMPLEMENTATION_HH_
--- /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 <unistd.h>
+
+#include "cion/tizen-api/cion_error.h"
+#include "cion/vine_wrapper/vine.hh"
+#include "cion/vine_wrapper/vine_implementation.hh"
+
+#ifdef LOG_TAG
+#undef LOG_TAG
+#endif
+
+#define LOG_TAG "VINE_WRAPPER"
+
+using namespace std;
+namespace cion {
+
+Vine& Vine::GetInst() {
+ static Vine w_inst;
+ int ret;
+
+ if (w_inst.impl_ == nullptr) {
+ ret = w_inst.Init();
+ if (ret != CION_ERROR_NONE)
+ throw ret;
+ }
+ return w_inst;
+}
+
+Vine::Vine() = default;
+Vine::~Vine() = default;
+Vine::Impl::Impl() = default;
+
+Vine::Impl::~Impl() {
+ vine_deinitialize();
+}
+
+int Vine::Init() {
+ std::unique_ptr<Impl> tmp_impl;
+
+ try {
+ tmp_impl = std::unique_ptr<Vine::Impl>(new Impl());
+ } catch (const std::bad_alloc &ba) {
+ LOGE("Out of memory");
+ return -1;
+ }
+
+ vine_initialize();
+
+ impl_ = std::move(tmp_impl);
+ return 0;
+}
+
+shared_ptr<Vine::VineService> Vine::CreateVineService() {
+ vine_service_h service = nullptr;
+ vine_service_create(&service);
+
+ return make_shared<Vine::VineService>(service);
+}
+
+shared_ptr<Vine::VineService> Vine::CloneVineService(shared_ptr<Vine::VineService> service) {
+ vine_service_h cloned = nullptr;
+ vine_service_clone(static_cast<vine_service_h>(service->GetService()), &cloned);
+
+ return make_shared<Vine::VineService>(cloned);
+}
+
+shared_ptr<Vine::VineSession> Vine::CreateVineSession() {
+ vine_session_h session = nullptr;
+ vine_session_create(&session);
+
+ return make_shared<Vine::VineSession>(session);
+}
+
+shared_ptr<Vine::VineSecurity> Vine::CreateVineSecurity() {
+ vine_security_h security = nullptr;
+ vine_security_create(&security);
+
+ return make_shared<Vine::VineSecurity>(security);
+}
+
+shared_ptr<Vine::VineDataPath> Vine::CreateVineDataPath(shared_ptr<Vine::VineSession> session,
+ Vine::VineDataPath::DataPathType type) {
+ vine_dp_h data_path = nullptr;
+ vine_dp_create(static_cast<vine_session_h>(session->GetSession()),
+ static_cast<vine_dp_type_e>(type), &data_path);
+
+ return make_shared<Vine::VineDataPath>(data_path);
+}
+
+} // 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_API_VINE_HH_
+#define CION_API_VINE_HH_
+
+#include <memory>
+#include <string>
+#include <unistd.h>
+#include <map>
+#include <functional>
+
+#include <dlog.h>
+#include <vine.h>
+
+#include <stdio.h>
+
+using namespace std;
+
+namespace cion {
+
+class Vine {
+ public:
+ class VineService {
+ public:
+ VineService(vine_service_h service) : service_(service) {
+ }
+
+ ~VineService() {
+ vine_service_destroy(service_);
+ }
+
+ typedef void* vine_service;
+
+ enum AddressFamily {
+ IPV4 = VINE_ADDRESS_FAMILY_IPV4,
+ IPV6 = VINE_ADDRESS_FAMILY_IPV6
+ };
+
+ void SetType(string service_type) {
+ int ret;
+ ret = vine_service_set_type(service_, service_type.c_str());
+
+ LOGD("Service SetType : %d", ret);
+ }
+
+ string GetType() {
+ char *type;
+ int ret;
+
+ ret = vine_service_get_type(service_, &type);
+ LOGD("Service GetType : %d", ret);
+
+ return string(type);
+ }
+
+ void SetName(string service_name) {
+ int ret;
+ ret = vine_service_set_name(service_, service_name.c_str());
+
+ LOGD("Service SetName : %d", ret);
+ }
+
+ string GetName() {
+ char *name;
+ int ret;
+
+ ret = vine_service_get_name(service_, &name);
+
+ LOGD("Service GetName : %d", ret);
+ return string(name);
+ }
+
+ void AddAttribute(string key, string value) {
+ int ret;
+ ret = vine_service_add_attribute(service_, key.c_str(), value.c_str());
+
+ LOGD("Service AddAttribute : %d", ret);
+ }
+
+ void RemoveAttribute(string key) {
+ int ret;
+ ret = vine_service_remove_attribute(service_, key.c_str());
+
+ LOGD("Service RemoveAttribute : %d", ret);
+ }
+
+ map<string, string> GetAttribute() {
+ int ret;
+ ret = vine_service_foreach_attribute(service_, VineServiceAttrCb, this);
+
+ LOGD("Service GetAttribute : %d", ret);
+
+ return attrs;
+ }
+
+ void SetPort(int port) {
+ int ret;
+ ret = vine_service_set_port(service_, port);
+
+ LOGD("Service SetPort : %d", ret);
+ }
+
+ int GetPort() {
+ int port;
+ int ret;
+
+ ret = vine_service_get_port(service_, &port);
+
+ LOGD("Service GetPort : %d", ret);
+
+ return port;
+ }
+
+ vine_service GetService() {
+ return service_;
+ }
+
+ private:
+ void SetAttr(string key, string value) {
+ attrs[key] = value;
+ }
+
+ static bool VineServiceAttrCb(const char *key, const char* value, void* user_data) {
+ VineService* service = static_cast<VineService*>(user_data);
+
+ service->SetAttr(string(key), string(value));
+
+ return true;
+ }
+
+ private:
+ vine_service service_ = nullptr;
+ map<string, string> attrs;
+ };
+
+ class VineSecurity {
+ public:
+ VineSecurity(vine_security_h security) : security_(security) {
+ }
+
+ ~VineSecurity() {
+ vine_security_destroy(security_);
+ }
+
+ typedef void* vine_security;
+
+ enum SecurityType {
+ SECURITY_TYPE_NONE = VINE_SECURITY_TYPE_NONE,
+ SECURITY_TYPE_TLS = VINE_SECURITY_TYPE_TLS,
+ SECURITY_TYPE_PSK_OVER_TLS = VINE_SECURITY_TYPE_PSK_OVER_TLS
+ };
+
+ enum TlsVersion {
+ TLS_VERSION_DEFAULT = VINE_SECURITY_TLS_VERSION_DEFAULT,
+ TLS_VERSION_1_0 = VINE_SECURITY_TLS_VERSION_1_0,
+ TLS_VERSION_1_1 = VINE_SECURITY_TLS_VERSION_1_1,
+ TLS_VERSION_1_2 = VINE_SECURITY_TLS_VERSION_1_2,
+ TLS_VERSION_1_3 = VINE_SECURITY_TLS_VERSION_1_3
+ };
+
+ enum VerificationFlag {
+ VERIFICATION_FLAG_DEFAAULT = VINE_SECURITY_VERIFICATION_FLAG_DEFAULT,
+ VERIFICATION_FLAG_ALLOW_SELF_SIGNED = VINE_SECURITY_VERIFICATION_FLAG_ALLOW_SELF_SIGNED,
+ VERIFICATION_FLAG_SKIP_HOST_NAME_CHECK = VINE_SECURITY_VERIFICATION_FLAG_SKIP_HOST_NAME_CHECK
+ };
+
+ void SetType(SecurityType type) {
+ int ret;
+ ret = vine_security_set_type(security_, static_cast<vine_security_type_e>(type));
+
+ LOGD("Security SetType : %d", ret);
+ }
+
+ SecurityType GetType() {
+ vine_security_type_e type;
+ int ret;
+
+ ret = vine_security_get_type(security_, &type);
+
+ LOGD("Security GetType : %d", ret);
+
+ return static_cast<SecurityType>(type);
+ }
+
+ void SetTlsVersion(TlsVersion version) {
+ int ret;
+ ret = vine_security_set_tls_version(security_, static_cast<vine_security_tls_version_e>(version));
+
+ LOGD("Security SetTlsVersion : %d", ret);
+ }
+
+ TlsVersion GetTlsVersion() {
+ vine_security_tls_version_e version;
+ int ret;
+
+ ret = vine_security_get_tls_version(security_, &version);
+
+ LOGD("Security GetTlsVersion : %d", ret);
+
+ return static_cast<TlsVersion>(version);
+ }
+
+ void SetVerificationFlags(int flags) {
+ int ret;
+ ret = vine_security_set_verification_flags(security_, flags);
+
+ LOGD("Security SetVerificationFlags : %d", ret);
+ }
+
+ int GetVerificationFlags() {
+ int flags;
+ int ret;
+
+ ret = vine_security_get_verification_flags(security_, &flags);
+
+ LOGD("Security GetVerificationFlags : %d", ret);
+
+ return flags;
+ }
+
+ void SetCaPath(string ca_path) {
+ int ret;
+ ret = vine_security_set_ca_path(security_, ca_path.c_str());
+
+ LOGD("Security SetCaPath : %d", ret);
+ }
+
+ string GetCaPath() {
+ char* ca_path;
+ int ret;
+
+ ret = vine_security_get_ca_path(security_, &ca_path);
+
+ LOGD("Security GetCaPath : %d", ret);
+
+ return string(ca_path);
+ }
+
+ void SetCertPath(string cert_path) {
+ int ret;
+ ret = vine_security_set_cert_path(security_, cert_path.c_str());
+
+ LOGD("Security SetCertPath : %d", ret);
+ }
+
+ string GetCertPath() {
+ char* cert_path;
+ int ret;
+
+ ret = vine_security_get_cert_path(security_, &cert_path);
+
+ LOGD("Security GetCertPath : %d", ret);
+
+ return string(cert_path);
+ }
+
+ void SetPrivateKey(string key_path) {
+ int ret;
+ ret = vine_security_set_private_key(security_, key_path.c_str());
+
+ LOGD("Security SetPrivateKey : %d", ret);
+ }
+
+ string GetPrivateKey() {
+ char* key_path;
+ int ret;
+
+ ret = vine_security_get_private_key(security_, &key_path);
+
+ LOGD("Security GetPrivateKey : %d", ret);
+
+ return string(key_path);
+ }
+
+ void SetPresharedKey(string key) {
+ int ret;
+ ret = vine_security_set_psk(security_, key.c_str());
+
+ LOGD("Security SetPresharedKey : %d", ret);
+ }
+
+ string GetPresharedKey() {
+ char* key;
+ int ret;
+
+ ret = vine_security_get_psk(security_, &key);
+
+ LOGD("Security GetPresharedKey : %d", ret);
+
+ return string(key);
+ }
+
+ vine_security GetSecurity() {
+ return security_;
+ }
+
+ private:
+ vine_security security_ = nullptr;
+
+ };
+
+ class VineSession {
+ public:
+ VineSession(vine_session_h session) : session_(session) {
+ }
+
+ ~VineSession() {
+ vine_session_destroy(session_);
+ }
+
+ typedef void* vine_session;
+
+ int GetEventFd() {
+ int fd;
+ int ret;
+
+ ret = vine_session_get_event_fd(session_, &fd);
+
+ LOGD("Session GetEventFd : %d", ret);
+
+ return fd;
+ }
+
+ void ProcessEvent() {
+ int ret;
+
+ ret = vine_session_process_event(session_);
+
+ LOGD("Session ProcessEvent : %d", ret);
+ }
+
+ void SetRegisteredCallback() {
+ int ret;
+
+ ret = vine_session_set_registered_cb(session_, RegisteredCallback, nullptr);
+
+ LOGD("Session ProcessEvent : %d", ret);
+ }
+
+ void UnsetRegisterCallback() {
+ int ret;
+
+ ret = vine_session_unset_registered_cb(session_);
+
+ LOGD("Session UnsetRegisterCallback : %d", ret);
+ }
+
+
+ void SetDiscoveredCallback() {
+ int ret;
+
+ ret = vine_session_set_discovered_cb(session_, DiscoveredCallback, nullptr);
+
+ LOGD("Session SetDiscoveredCallback : %d", ret);
+ }
+
+ void UnsetDiscoveredCallback() {
+ int ret;
+
+ ret = vine_session_unset_discovered_cb(session_);
+
+ LOGD("Session UnsetDiscoveredCallback : %d", ret);
+ }
+
+ enum DiscoveryMethod {
+ DISCOVERY_METHOD_DNS_SD = VINE_DISCOVERY_METHOD_DNS_SD
+ };
+
+ void SetDiscoveryMethod(DiscoveryMethod method) {
+ int ret;
+
+ ret = vine_session_set_discovery_method(session_,
+ static_cast<vine_discovery_method_e>(method));
+
+ LOGD("Session SetDiscoveryMethod : %d", ret);
+ }
+
+ void RegisterService(shared_ptr<VineService> service, std::string iface_name) {
+ int ret;
+
+ ret = vine_session_register(session_, static_cast<vine_service_h>(service->GetService()), iface_name.c_str());
+
+ LOGD("Session RegisterService : %d", ret);
+ }
+
+ void UnregisterService() {
+ int ret;
+
+ ret = vine_session_unregister(session_);
+
+ LOGD("Session UnregisterService : %d", ret);
+ }
+
+ void StartDiscovery(string service_type, string iface_name) {
+ int ret;
+
+ ret = vine_session_start_discovery(session_, service_type.c_str(),
+ iface_name.c_str());
+
+ LOGD("Session StartDiscovery : %d", ret);
+ }
+
+ void StopDiscovery() {
+ int ret;
+
+ ret = vine_session_stop_discovery(session_);
+
+ LOGD("Session StopDiscovery : %d", ret);
+ }
+
+ void SetIpResolvedCallback(shared_ptr<VineService> service) {
+ int ret;
+
+ ret = vine_session_set_ip_resolved_cb(session_, static_cast<vine_service_h>(service->GetService()), IpResolvedCallback, nullptr);
+
+ LOGD("Session SetIpResolvedCallback : %d", ret);
+ }
+
+ void UnsetIpResolvedCallback(shared_ptr<VineService> service) {
+ int ret;
+
+ ret = vine_session_unset_ip_resolved_cb(session_, static_cast<vine_service_h>(service->GetService()));
+
+ LOGD("Session UnsetIpResolvedCallback : %d", ret);
+ }
+
+ vine_session GetSession() {
+ return session_;
+ }
+
+ private:
+ static void RegisteredCallback(vine_session_h session,
+ const char *service_name, vine_error_e error, void *user_data) {
+ printf("service registered \n");
+ }
+
+ // discovered_service can not be set data
+ static void DiscoveredCallback(vine_session_h session,
+ vine_service_h discovered_service, vine_service_state_e state, void *user_data) {
+ printf("service discovered \n");
+ }
+
+ static void IpResolvedCallback(vine_session_h session, vine_service_h service,
+ const char *ip, vine_address_family_e address_family, void *user_data) {
+ printf("ip resolved\n");
+ }
+
+ private:
+ vine_session session_ = nullptr;
+
+ };
+
+ class VineDataPath {
+ public:
+ VineDataPath(vine_dp_h dp) : dp_(dp) {
+ }
+
+ ~VineDataPath() {
+ vine_dp_destroy(dp_);
+ }
+
+ typedef void* vine_data_path;
+
+ enum DataPathType {
+ DP_TYPE_SERVER = VINE_DP_TYPE_SERVER,
+ DP_TYPE_CLIENT = VINE_DP_TYPE_CLIENT,
+ DP_TYPE_PUBSUB = VINE_DP_TYPE_PUBSUB,
+ DP_TYPE_UNKNOWN = VINE_DP_TYPE_UNKNOWN
+ };
+
+ void SetIfaceName(std::string name){
+ int ret;
+
+ ret = vine_dp_set_iface_name(dp_, name.c_str());
+
+ LOGD("DataPath SetIfaceName : %d", ret);
+ }
+
+ // DP_TYPE_SERVER || DP_TYPE_PUBSUB possible
+ void SetAddressFamily(VineService::AddressFamily addr_family) {
+ int ret;
+
+ ret = vine_dp_set_address_family(dp_,
+ static_cast<vine_address_family_e>(addr_family));
+
+ LOGD("DataPath SetAddressFamily : %d", ret);
+ }
+
+ // DP_TYPE_CLIENT possible
+ void SetRemoteIp(VineService::AddressFamily addr_family, std::string ip) {
+ int ret;
+
+ ret = vine_dp_set_remote_ip(dp_,
+ static_cast<vine_address_family_e>(addr_family), ip.c_str());
+
+ LOGD("DataPath SetRemoteIp : %d", ret);
+ }
+
+ void SetPort(int port) {
+ int ret;
+
+ ret = vine_dp_set_port(dp_, port);
+
+ LOGD("DataPath SetPort : %d", ret);
+ }
+
+ int GetPort() {
+ int port;
+ int ret;
+
+ ret = vine_dp_get_port(dp_, &port);
+
+ LOGD("DataPath GetPort : %d", ret);
+
+ return port;
+ }
+
+ // DP_TYPE_PUBSUB possible
+ void SetTopic(std::string topic) {
+ int ret;
+
+ ret = vine_dp_set_topic(dp_, topic.c_str());
+
+ LOGD("DataPath SetTopic : %d", ret);
+ }
+
+ void SetSecurity(shared_ptr<VineSecurity> security) {
+ int ret;
+
+ ret = vine_dp_set_security(dp_, static_cast<vine_security_h>(security->GetSecurity()));
+
+ LOGD("DataPath SetSecurity : %d", ret);
+ }
+
+ // DP_TYPE_SERVER only
+ void SetAcceptedCallback() {
+ int ret;
+
+ ret = vine_dp_set_accepted_cb(dp_, DataPathAcceptedCallback, nullptr);
+
+ LOGD("DataPath SetAcceptedCallback : %d", ret);
+ }
+
+ // DP_TYPE_SERVER only
+ void UnsetAcceptedCallback() {
+ int ret;
+
+ ret = vine_dp_unset_accepted_cb(dp_);
+
+ LOGD("DataPath UnsetAcceptedCallback : %d", ret);
+ }
+
+ void SetTerminatedCallback() {
+ int ret;
+
+ ret = vine_dp_set_terminated_cb(dp_, DataPathTerminatedCallback, nullptr);
+
+ LOGD("DataPath SetTerminatedCallback : %d", ret);
+ }
+
+ void UnsetTerminatedCallback() {
+ int ret;
+
+ ret = vine_dp_unset_terminated_cb(dp_);
+
+ LOGD("DataPath SetTerminatedCallback : %d", ret);
+ }
+
+ void DataPathOpen() {
+ int ret;
+
+ ret = vine_dp_open(dp_, DataPathOpenedCallback, nullptr);
+
+ LOGD("DataPath SetTerminatedCallback : %d", ret);
+ }
+
+ void DataPathClose() {
+ int ret;
+
+ ret = vine_dp_close(dp_);
+
+ LOGD("DataPath DataPathClose : %d", ret);
+ }
+
+ void Send(std::string buf, size_t len) {
+ //vine_dp_send(dp_, buf.c_str(), len);
+ }
+
+ void Receive(std::string buf, size_t buf_len, size_t* read_len) {
+ //vine_dp_recv(dp_, buf.c_str(), buf_len, read_len);
+ }
+
+ void SetReceivedCallback() {
+ int ret;
+
+ ret = vine_dp_set_received_cb(dp_, DataPathReceivedCallback, nullptr);
+
+ LOGD("DataPath SetReceivedCallback : %d", ret);
+ }
+
+ void UnsetReceivedCallback() {
+ int ret;
+
+ ret = vine_dp_unset_received_cb(dp_);
+
+ LOGD("DataPath UnsetReceivedCallback : %d", ret);
+ }
+
+ private:
+ static void DataPathAcceptedCallback(vine_dp_h dp, void *user_data) {
+ printf("data path accepted\n");
+ }
+
+ static void DataPathTerminatedCallback(vine_dp_h dp, void *user_data) {
+ printf("data path accepted\n");
+ }
+
+ static void DataPathOpenedCallback(vine_dp_h dp, vine_error_e result, void *user_data) {
+ printf("data path opened\n");
+ }
+
+ static void DataPathReceivedCallback(vine_dp_h dp, size_t received_len, void *user_data) {
+ printf("data path received\n");
+ }
+
+ private:
+ vine_data_path dp_ = nullptr;
+ };
+
+ public:
+ static Vine& GetInst();
+ shared_ptr<VineService> CreateVineService();
+ shared_ptr<VineService> CloneVineService(shared_ptr<VineService> service);
+ shared_ptr<VineSession> CreateVineSession();
+ shared_ptr<VineSecurity> CreateVineSecurity();
+ shared_ptr<VineDataPath> CreateVineDataPath(shared_ptr<VineSession> session,
+ VineDataPath::DataPathType type);
+
+ private:
+ Vine();
+ virtual ~Vine();
+ int Init();
+
+ private:
+ class Impl;
+ unique_ptr<Impl> impl_;
+};
+
+} // namespace cion
+
+#endif // CION_API_VINE_HH_
--- /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_API_VINE_MANAGER_IMPLEMENTATION_HH_
+#define CION_API_VINE_MANAGER_IMPLEMENTATION_HH_
+
+namespace cion {
+
+class Vine::Impl {
+ public:
+ virtual ~Impl();
+
+ private:
+ friend class Vine;
+ Impl();
+
+ private:
+};
+
+} // namespace cion
+
+#endif // CION_API_VINE_MANAGER_IMPLEMENTATION_HH_
%description -n cion-service
Tizen Companion Service Application
-#################################################
-# Vine-Manager
-#################################################
-%package -n libvine_manager
-Summary: Vine Manager module
-License: Apache-2.0
-Group: Application Framework/Communication
-
-%description -n libvine_manager
-Vine Manager module
-
-#################################################
-# libvine_wrapper
-#################################################
-%package -n libvine_wrapper
-Summary: Vine API wrapper module
-License: Apache-2.0
-Group: Application Framework/Communication
-
-%description -n libvine_wrapper
-Vine API wrapper module
-
#################################################
# unittests
#################################################
#TODO: enable check section
#%check
#ctest --output-on-failure %{?_smp_mflags}
-export LD_LIBRARY_PATH=../cion:../vine_manager:../vine_wrapper
+export LD_LIBRARY_PATH=../cion
ctest -V
%if 0%{?gcov:1}
lcov -c --ignore-errors graph --no-external -q -d . -o cion.info
#%{_manifestdir}/org.tizen.%{name}-service.xml
#%{_shareddir}/*
-#################################################
-# Vine-Manager
-#################################################
-%post -n libvine_manager -p /sbin/ldconfig
-
-%postun -n libvine_manager -p /sbin/ldconfig
-
-%files -n libvine_manager
-%manifest %{name}.manifest
-%license LICENSE
-%defattr(-,root,root,-)
-%{_libdir}/libvine_manager.so.*
-%{_includedir}/vine_manager/*.hh
-%{_libdir}/libvine_manager.so
-%{_libdir}/pkgconfig/vine_manager.pc
-
-#################################################
-# libvine_wrapper
-#################################################
-%post -n libvine_wrapper -p /sbin/ldconfig
-
-%postun -n libvine_wrapper -p /sbin/ldconfig
-
-%files -n libvine_wrapper
-%manifest %{name}.manifest
-%license LICENSE
-%defattr(-,root,root,-)
-%{_libdir}/libvine_wrapper.so.*
-%{_includedir}/vine_wrapper/*.hh
-%{_libdir}/libvine_wrapper.so
-%{_libdir}/pkgconfig/vine_wrapper.pc
-
#################################################
# unittests
#################################################
-AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/../vine_wrapper VINE_WRAPPER_SOURCE)
AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/src SOURCES)
AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/mock MOCK_SRCS)
ADD_EXECUTABLE(${TARGET_CION_UNITTESTS}
${SOURCES}
${MOCK_SRCS}
- ${VINE_WRAPPER_SOURCE}
)
TARGET_INCLUDE_DIRECTORIES(${TARGET_CION_UNITTESTS} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../)
GMOCK_DEPS
)
-TARGET_LINK_LIBRARIES(${TARGET_CION_UNITTESTS} PRIVATE ${TARGET_CION} ${TARGET_VINE_MANAGER} ${TARGET_VINE_WRAPPER})
+TARGET_LINK_LIBRARIES(${TARGET_CION_UNITTESTS} PRIVATE ${TARGET_CION})
INSTALL(TARGETS ${TARGET_CION_UNITTESTS} DESTINATION ${BINDIR})
#include <gmock/gmock.h>
#include <stdio.h>
+#include "cion/vine_wrapper/vine.hh"
#include "unittests/mock/test_fixture.hh"
#include "unittests/mock/vine_mock.hh"
-#include "vine_wrapper/vine.hh"
using namespace std;
using namespace cion;
#include <gmock/gmock.h>
#include <stdio.h>
+#include "cion/vine_wrapper/vine.hh"
#include "unittests/mock/test_fixture.hh"
#include "unittests/mock/vine_mock.hh"
-#include "vine_wrapper/vine.hh"
using namespace std;
using namespace cion;
#include <gmock/gmock.h>
#include <stdio.h>
+#include "cion/vine_wrapper/vine.hh"
#include "unittests/mock/test_fixture.hh"
#include "unittests/mock/vine_mock.hh"
-#include "vine_wrapper/vine.hh"
using namespace std;
using namespace cion;
EXPECT_NE(service->GetService(), nullptr);
string type;
-
+
service->SetType(string("vine_type"));
type = service->GetType();
#include <gmock/gmock.h>
#include <stdio.h>
+#include "cion/vine_wrapper/vine.hh"
#include "unittests/mock/test_fixture.hh"
#include "unittests/mock/vine_mock.hh"
-#include "vine_wrapper/vine.hh"
using namespace std;
using namespace cion;
+++ /dev/null
-AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR} SOURCES)
-ADD_LIBRARY(${TARGET_VINE_MANAGER} SHARED ${SOURCES})
-
-TARGET_INCLUDE_DIRECTORIES(${TARGET_VINE_MANAGER} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/)
-TARGET_INCLUDE_DIRECTORIES(${TARGET_VINE_MANAGER} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../)
-
-APPLY_PKG_CONFIG(${TARGET_VINE_MANAGER} PUBLIC DLOG_DEPS VINE_DEPS GLIB_DEPS)
-
-SET_TARGET_PROPERTIES(${TARGET_VINE_MANAGER} PROPERTIES VERSION ${FULLVER})
-SET_TARGET_PROPERTIES(${TARGET_VINE_MANAGER} PROPERTIES SOVERSION ${MAJORVER})
-
-CONFIGURE_FILE(${TARGET_VINE_MANAGER}.pc.in ${TARGET_VINE_MANAGER}.pc @ONLY)
-
-INSTALL(TARGETS ${TARGET_VINE_MANAGER} DESTINATION ${LIB_INSTALL_DIR})
-INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/${TARGET_VINE_MANAGER}.pc DESTINATION ${LIB_INSTALL_DIR}/pkgconfig)
-
-INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/vine_listener.hh DESTINATION include/${TARGET_VINE_MANAGER})
-INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/vine_manager.hh DESTINATION include/${TARGET_VINE_MANAGER})
-INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/vine_sender.hh DESTINATION include/${TARGET_VINE_MANAGER})
+++ /dev/null
-/*
- * Copyright (c) 2020 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.
- */
-
-#include <dlog.h>
-#include <unistd.h>
-#include <memory>
-
-#include "vine_manager.hh"
-#include "vine_listener.hh"
-#include "vine_listener_implementation.hh"
-
-namespace cion {
-
-VineListener::VineListener()
- : impl_(new Impl()) {
-}
-
-VineListener::~VineListener() {
-}
-
-VineListener::Impl::Impl() {
-}
-
-void VineListener::RegisterObserver(channel::IEventObserver* observer) {
- VineManager::GetInst().RegisterObserver(observer);
-}
-
-void VineListener::UnregisterObserver(channel::IEventObserver* observer) {
- VineManager::GetInst().UnregisterObserver(observer);
-}
-
-} // namespace cion
+++ /dev/null
-/*
- * Copyright (c) 2020 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_VINE_MANAGER_VINE_LISTENER_HH_
-#define CION_VINE_MANAGER_VINE_LISTENER_HH_
-
-#include <memory>
-
-#include "cion/channel/ievent_observer.hh"
-#include "cion/channel/ievent_listener.hh"
-
-namespace cion {
-
-#ifndef EXPORT_API
-#define EXPORT_API __attribute__((visibility("default")))
-#endif
-
-class EXPORT_API VineListener : public channel::IEventListener {
-
- public:
- VineListener();
- virtual ~VineListener();
- void RegisterObserver(channel::IEventObserver* observer) override;
- void UnregisterObserver(channel::IEventObserver* observer) override;
-
-
- private:
- class Impl;
- std::unique_ptr<Impl> impl_;
-};
-
-} // namespace cion
-
-#endif // CION_VINE_MANAGER_VINE_LISTENER_HH_
+++ /dev/null
-/*
- * Copyright (c) 2020 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_API_VINE_LISTENER_IMPLEMENTATION_HH_
-#define CION_API_VINE_LISTENER_IMPLEMENTATION_HH_
-
-namespace cion {
-
-class VineListener::Impl {
- public:
- virtual ~Impl() = default;
-
- private:
- friend class VineListener;
- Impl();
-
-
- private:
-};
-
-} // namespace cion
-
-#endif // CION_API_VINE_LISTENER_IMPLEMENTATION_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.
- */
-
-#include <dlog.h>
-#include <unistd.h>
-#include <vine.h>
-#include <glib-unix.h>
-#include <sys/socket.h>
-#include <sys/types.h>
-
-#include <memory>
-#include <utility>
-
-#include "vine_manager.hh"
-#include "vine_manager_implementation.hh"
-
-#ifdef LOG_TAG
-#undef LOG_TAG
-#endif
-
-#define LOG_TAG "VINE_MANAGER"
-
-#define VINE_TEST_TOPIC "CION_TOPIC"
-#define VINE_TEST_SERVICE "CION_TEST"
-#define VINE_TEST_SERVER_PORT 55555
-#define VINE_TEST_CLIENT_PORT 55556
-#define VINE_TEST_SERVICE_TYPE "_cion"
-
-namespace cion {
-
-VineManager& VineManager::GetInst() {
- static VineManager w_inst;
- int ret;
-
- if (w_inst.impl_ == nullptr) {
- ret = w_inst.Init();
- if (ret != CION_ERROR_NONE)
- throw ret;
- }
- return w_inst;
-}
-
-VineManager::VineManager() = default;
-VineManager::~VineManager() = default;
-VineManager::Impl::Impl() = default;
-
-VineManager::Impl::~Impl() {
- vine_session_unset_discovered_cb(session_);
- vine_deinitialize();
-}
-
-int VineManager::Init() {
- std::unique_ptr<Impl> tmp_impl;
-
- try {
- tmp_impl = std::unique_ptr<VineManager::Impl>(new Impl());
- } catch (const std::bad_alloc &ba) {
- LOGE("Out of memory");
- return -1;
- }
-
- impl_ = std::move(tmp_impl);
- vine_initialize();
- vine_session_create(&impl_->session_);
- int fd;
- vine_session_get_event_fd(impl_->session_, &fd);
- g_unix_fd_add(fd, G_IO_IN, [] (int fd, GIOCondition condition,
- gpointer user_data) -> int {
- LOGE("@@@ gio in!!");
- VineManager* ptr = (VineManager*)user_data;
- vine_session_process_event(ptr->impl_->session_);
- LOGE("@@@ process event done !!");
- return G_SOURCE_CONTINUE;
- }, this);
-
- LOGI("VineManager init done");
- return 0;
-}
-
-void VineManager::Impl::AddSenderInfo(std::string service_name,
- int channel_id) {
- for (auto& sender : sender_list_) {
- if (service_name == sender.GetServiceName()
- && channel_id == sender.GetChannelId()) {
- LOGW("Already exist");
- return;
- }
- }
- SenderInfo info(service_name, channel_id);
- sender_list_.push_back(info);
-}
-
-bool VineManager::Impl::ValidateSender(std::string service_name) {
- for (auto& sender : sender_list_) {
- if (service_name == sender.GetServiceName())
- return true;
- }
- return false;
-}
-
-void VineManager::Discovery() {
- vine_session_set_discovered_cb(impl_->session_,
- [] (vine_session_h session, vine_service_h service,
- vine_service_state_e state, void *user_data) -> void {
- char* name;
- int port;
- vine_service_get_name(service, &name);
- vine_service_get_port(service, &port);
-
- LOGD("Available Service");
- LOGD("Service Name: %s", name);
- LOGD("Port: %d", port);
-
- VineManager* ptr = (VineManager*)user_data;
- if (ptr == nullptr) {
- LOGE("null vine manager");
- return;
- }
-
- if (state == VINE_SERVICE_AVAILABLE) {
- LOGW("A service is discovered\n");
- /*
-
-
-
- vine_dp_h dp;
- vine_dp_create(session, VINE_DP_TYPE_PUBSUB, &dp);
- vine_dp_set_port(dp, VINE_TEST_CLIENT_PORT);
- vine_dp_set_topic(dp, VINE_TEST_TOPIC);
- vine_dp_open(dp,
- [](vine_dp_h dp, vine_error_e result, void *user_data) {
- LOGW("@@@@@@@ open");
- std::string msg = "test string";
- vine_dp_send(dp, (unsigned char*)msg.c_str(), msg.size());
- }, nullptr);
-*/
- vine_session_set_ip_resolved_cb(ptr->impl_->session_, service,
- [] (vine_session_h session, vine_service_h service,
- const char *ip, vine_address_family_e address_family,
- void *user_data) -> void {
- LOGW("IP address: %s\n", ip);
- vine_dp_h dp;
- vine_dp_create(session, VINE_DP_TYPE_CLIENT, &dp);
- vine_dp_set_remote_ip(dp, VINE_ADDRESS_FAMILY_IPV4, ip);
- vine_dp_set_security(dp, nullptr);
- vine_dp_set_port(dp, VINE_TEST_SERVER_PORT);
- vine_dp_open(dp,
- [](vine_dp_h dp, vine_error_e result, void *user_data)
- -> void {
- LOGW("@@@@@@@ open");
- vine_dp_send(dp, (unsigned char*)"TEST", 5);
- }, nullptr);
- }, nullptr);
- }
- }, this);
- vine_session_start_discovery(impl_->session_,
- VINE_TEST_SERVICE_TYPE, nullptr);
-}
-
-void VineManager::RegisterSender(std::string service_name, int channel_id) {
- impl_->AddSenderInfo(service_name, channel_id);
-}
-
-void VineManager::UnregisterSender(int channel_id) {
-}
-
-void VineManager::RegisterObserver(channel::IEventObserver* observer) {
- vine_session_set_registered_cb(impl_->session_, [] (
- vine_session_h session, const char* service_name,
- vine_error_e error, void* user_data) -> void {
- LOGI("session registered : %s", service_name);
-
- /*vine_dp_h dp;
- vine_dp_create(session, VINE_DP_TYPE_PUBSUB, &dp);
- vine_dp_set_address_family(g_pubsub_dp, VINE_ADDRESS_FAMILY_IPV4);
- vine_dp_set_port(dp, VINE_TEST_SERVER_PORT);
- vine_dp_set_topic(dp, VINE_TEST_TOPIC);
- vine_dp_open(dp,
- [](vine_dp_h dp, vine_error_e result, void *user_data) {
-
- vine_dp_set_received_cb(dp, [](vine_dp_h dp, size_t received_len,
- void *user_data) {
- unsigned char buf[20] = {0, };
- size_t bytes = 0;
- LOGW("[RECV_CB] %p received %zd bytes.", dp, received_len);
- printf("[RECV_CB] %p received %zd bytes.\n", dp, received_len);
- do {
- vine_dp_recv(dp, buf, 20, &bytes);
- for (int i = 0; i < (int)received_len; i++)
- printf("%c", buf[i]);
- printf("\n");
- received_len -= bytes;
- } while (received_len > 0);
- }, nullptr);
-
- LOGW("@@@@@@@ open");
- //std::string msg = "test string";
- //vine_dp_send(dp, (unsigned char*)msg.c_str(), msg.size());
- }, nullptr);*/
-
-
- vine_dp_h dp;
- vine_dp_create(session, VINE_DP_TYPE_SERVER, &dp);
- vine_dp_set_port(dp, VINE_TEST_SERVER_PORT);
- vine_dp_open(dp,
- [] (vine_dp_h dp, vine_error_e result, void *user_data) -> void {
- LOGW("Opened !!!");
- vine_dp_set_received_cb(dp, [](vine_dp_h dp, size_t received_len,
- void *user_data) -> void {
- unsigned char buf[20] = {0, };
- size_t bytes = 0;
- LOGW("[RECV_CB] %p received %zd bytes.", dp, received_len);
- printf("[RECV_CB] %p received %zd bytes.\n", dp, received_len);
- do {
- vine_dp_recv(dp, buf, 20, &bytes);
- for (int i = 0; i < (int)received_len; i++)
- printf("%c", buf[i]);
- printf("\n");
- received_len -= bytes;
- } while (received_len > 0);
- }, nullptr);
-
- }, nullptr);
- vine_dp_set_accepted_cb(dp, [] (vine_dp_h dp, void *user_data) -> void {
- }, nullptr);
-
- }, nullptr);
-
- vine_service_h service;
- vine_service_create(&service);
- vine_service_set_type(service, VINE_TEST_SERVICE_TYPE);
- std::string channel_id = "test";
-
- vine_service_set_name(service, VINE_TEST_SERVICE);
- impl_->port_ = VINE_TEST_SERVER_PORT;
- vine_service_set_port(service, impl_->port_);
- vine_service_add_attribute(service, "id", VINE_TEST_SERVICE);
- vine_service_add_attribute(service,
- "channel", channel_id.c_str());
- impl_->service_ = service;
-
- vine_session_register(impl_->session_, service, nullptr);
- LOGI("session register !! : %s", VINE_TEST_SERVICE);
-}
-
-void VineManager::UnregisterObserver(channel::IEventObserver* observer) {
-}
-
-void VineManager::SendDataAsync(const std::vector<char>& serialized_payload,
- std::shared_ptr<channel::IDataInfo> info, int channel_id,
- std::shared_ptr<PeerInfo> peer_info) {
-}
-
-std::vector<char> VineManager::SendData(
- const std::vector<char>& serialized_payload,
- std::shared_ptr<channel::IDataInfo> info, int channel_id,
- std::string peer_uuid, int timeout) {
- return {};
-}
-
-void VineManager::OperateChannel(int channel_id,
- std::shared_ptr<channel::IControlInfo> info,
- std::shared_ptr<PeerInfo> peer_info) {
-}
-
-} // namespace cion
\ No newline at end of file
+++ /dev/null
-/*
- * Copyright (c) 2020 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_VINE_MANAGER_VINE_MANAGER_HH_
-#define CION_VINE_MANAGER_VINE_MANAGER_HH_
-
-#include <vector>
-#include <string>
-#include <memory>
-
-#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"
-
-#ifndef EXPORT_API
-#define EXPORT_API __attribute__((visibility("default")))
-#endif
-
-namespace cion {
-
-class EXPORT_API VineManager {
- public:
- static VineManager& GetInst();
- 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(const std::vector<char>& serialized_payload,
- std::shared_ptr<channel::IDataInfo> info, int channel_id,
- std::shared_ptr<PeerInfo> peer_info);
- std::vector<char> SendData(const std::vector<char>& serialized_payload,
- std::shared_ptr<channel::IDataInfo> info, int channel_id,
- std::string peer_uuid, int timeout);
- void OperateChannel(int channel_id,
- std::shared_ptr<channel::IControlInfo> info,
- std::shared_ptr<PeerInfo> peer_info);
- void Discovery();
- VineManager();
-
- private:
- virtual ~VineManager();
- int Init();
-
- private:
- class Impl;
- std::unique_ptr<Impl> impl_;
-};
-
-} // namespace cion
-
-#endif // CION_VINE_MANAGER_VINE_MANAGER_HH_
+++ /dev/null
-prefix=@PREFIX@
-exec_prefix=@EXEC_PREFIX@
-libdir=@LIB_INSTALL_DIR@
-includedir=@INCLUDE_INSTALL_DIR@
-
-Name: vine_manager
-Description: Support development of the Tizen Companion Library
-Version: @VERSION@
-Libs: -L${libdir} -lcion -lvine_manager -lvine
-Cflags: -I${includedir} -I${includedir}/vine_manager
-cppflags: -I${includedir}
+++ /dev/null
-/*
- * Copyright (c) 2020 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_API_VINE_MANAGER_IMPLEMENTATION_HH_
-#define CION_API_VINE_MANAGER_IMPLEMENTATION_HH_
-
-#include<string>
-#include<list>
-#include<dlog.h>
-
-#ifdef LOG_TAG
-#undef LOG_TAG
-#endif
-
-#define LOG_TAG "VINE_MANAGER"
-
-
-namespace cion {
-
-class SenderInfo {
- public:
- SenderInfo(std::string service_name, int channel_id) {
- service_name_ = service_name;
- channel_id_ = channel_id;
- }
-
- std::string GetServiceName() {
- return service_name_;
- }
-
- int GetChannelId() {
- return channel_id_;
- }
-
- private:
- std::string service_name_;
- int channel_id_;
-};
-
-class VineManager::Impl {
- public:
- virtual ~Impl();
- void AddSenderInfo(std::string service_name, int channel_id);
- bool ValidateSender(std::string service_name);
-
- private:
- friend class VineManager;
- Impl();
-
- private:
- vine_session_h session_;
- vine_service_h service_;
- std::list<SenderInfo> sender_list_;
- int port_;
-};
-
-} // namespace cion
-
-#endif // CION_API_VINE_MANAGER_IMPLEMENTATION_HH_
+++ /dev/null
-/*
- * Copyright (c) 2020 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.
- */
-
-#include <dlog.h>
-#include <unistd.h>
-#include <memory>
-
-#include "vine_manager.hh"
-
-#include "vine_sender.hh"
-#include "vine_sender_implementation.hh"
-
-namespace cion {
-
-VineSender::VineSender(std::string service_name, int channel_id)
- : impl_(new Impl(service_name, channel_id)) {
-}
-
-VineSender::~VineSender() {
-
-}
-
-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(
- std::shared_ptr<channel::IControlInfo> info,
- std::shared_ptr<PeerInfo> peer_info) {
- VineManager::GetInst().OperateChannel(channel_id_, info, peer_info);
-}
-
-void VineSender::SendDataAsync(const std::vector<char>& serialized_payload,
- std::shared_ptr<channel::IDataInfo> info,
- std::shared_ptr<PeerInfo> peer_info) {
-}
-
-std::vector<char> VineSender::SendData(
- const std::vector<char>& serialized_payload,
- std::shared_ptr<channel::IDataInfo> info,
- std::shared_ptr<PeerInfo> peer_info, int timeout) {
- return {};
-}
-
-void VineSender::OperateChannel(std::shared_ptr<channel::IControlInfo> info,
- std::shared_ptr<PeerInfo> peer_info) {
- impl_->OperateChannel(info, peer_info);
-}
-
-void VineSender::SetSecurity(SecurityInfo sec) {
-}
-
-} // 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_VINE_MANAGER_VINE_SENDER_HH_
-#define CION_VINE_MANAGER_VINE_SENDER_HH_
-
-#include <string>
-#include <vector>
-#include <memory>
-
-#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 "cion/channel/ievent_sender.hh"
-#include "cion/security/security_info.hh"
-
-#ifndef EXPORT_API
-#define EXPORT_API __attribute__((visibility("default")))
-#endif
-
-namespace cion {
-
-class EXPORT_API VineSender : public channel::IEventSender {
- public:
- VineSender(std::string service_name, int channel_id);
- virtual ~VineSender();
-
- protected:
- void SendDataAsync(const std::vector<char>& serialized_payload,
- std::shared_ptr<channel::IDataInfo> info,
- std::shared_ptr<PeerInfo> peer_info) override;
- std::vector<char> SendData(const std::vector<char>& serialized_payload,
- std::shared_ptr<channel::IDataInfo> info,
- std::shared_ptr<PeerInfo> peer_info, int timeout) override;
- void OperateChannel(std::shared_ptr<channel::IControlInfo> info,
- std::shared_ptr<PeerInfo> peer_info) override;
- void SetSecurity(SecurityInfo sec) override;
-
- private:
- class Impl;
- std::unique_ptr<Impl> impl_;
-};
-
-} // namespace cion
-
-#endif // CION_VINE_MANAGER_VINE_SENDER_HH_
+++ /dev/null
-/*
- * Copyright (c) 2020 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_API_VINE_SENDER_IMPLEMENTATION_HH_
-#define CION_API_VINE_SENDER_IMPLEMENTATION_HH_
-
-#include <memory>
-
-#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();
-
- private:
- friend class VineSender;
-
- explicit Impl(std::string service_name, int channel_id);
- void OperateChannel(std::shared_ptr<channel::IControlInfo> info,
- std::shared_ptr<PeerInfo> peer_info);
-
- private:
- std::string service_name_;
- int channel_id_;
- int port_;
-};
-
-} // namespace cion
-
-#endif // CION_API_VINE_SENDER_IMPLEMENTATION_HH_
+++ /dev/null
-AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR} SOURCES)
-ADD_LIBRARY(${TARGET_VINE_WRAPPER} SHARED ${SOURCES})
-
-TARGET_INCLUDE_DIRECTORIES(${TARGET_VINE_WRAPPER} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/)
-TARGET_INCLUDE_DIRECTORIES(${TARGET_VINE_WRAPPER} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../)
-
-APPLY_PKG_CONFIG(${TARGET_VINE_WRAPPER} PUBLIC DLOG_DEPS VINE_DEPS)
-
-SET_TARGET_PROPERTIES(${TARGET_VINE_WRAPPER} PROPERTIES VERSION ${FULLVER})
-SET_TARGET_PROPERTIES(${TARGET_VINE_WRAPPER} PROPERTIES SOVERSION ${MAJORVER})
-
-CONFIGURE_FILE(${TARGET_VINE_WRAPPER}.pc.in ${TARGET_VINE_WRAPPER}.pc @ONLY)
-
-INSTALL(TARGETS ${TARGET_VINE_WRAPPER} DESTINATION ${LIB_INSTALL_DIR})
-INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/${TARGET_VINE_WRAPPER}.pc DESTINATION ${LIB_INSTALL_DIR}/pkgconfig)
-
-INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/vine.hh DESTINATION include/${TARGET_VINE_WRAPPER})
+++ /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 <unistd.h>
-
-#include "cion/tizen-api/cion_error.h"
-#include "vine_wrapper/vine.hh"
-#include "vine_wrapper/vine_implementation.hh"
-
-#ifdef LOG_TAG
-#undef LOG_TAG
-#endif
-
-#define LOG_TAG "VINE_WRAPPER"
-
-using namespace std;
-namespace cion {
-
-Vine& Vine::GetInst() {
- static Vine w_inst;
- int ret;
-
- if (w_inst.impl_ == nullptr) {
- ret = w_inst.Init();
- if (ret != CION_ERROR_NONE)
- throw ret;
- }
- return w_inst;
-}
-
-Vine::Vine() = default;
-Vine::~Vine() = default;
-Vine::Impl::Impl() = default;
-
-Vine::Impl::~Impl() {
- vine_deinitialize();
-}
-
-int Vine::Init() {
- std::unique_ptr<Impl> tmp_impl;
-
- try {
- tmp_impl = std::unique_ptr<Vine::Impl>(new Impl());
- } catch (const std::bad_alloc &ba) {
- LOGE("Out of memory");
- return -1;
- }
-
- vine_initialize();
-
- impl_ = std::move(tmp_impl);
- return 0;
-}
-
-shared_ptr<Vine::VineService> Vine::CreateVineService() {
- vine_service_h service = nullptr;
- vine_service_create(&service);
-
- return make_shared<Vine::VineService>(service);
-}
-
-shared_ptr<Vine::VineService> Vine::CloneVineService(shared_ptr<Vine::VineService> service) {
- vine_service_h cloned = nullptr;
- vine_service_clone(static_cast<vine_service_h>(service->GetService()), &cloned);
-
- return make_shared<Vine::VineService>(cloned);
-}
-
-shared_ptr<Vine::VineSession> Vine::CreateVineSession() {
- vine_session_h session = nullptr;
- vine_session_create(&session);
-
- return make_shared<Vine::VineSession>(session);
-}
-
-shared_ptr<Vine::VineSecurity> Vine::CreateVineSecurity() {
- vine_security_h security = nullptr;
- vine_security_create(&security);
-
- return make_shared<Vine::VineSecurity>(security);
-}
-
-shared_ptr<Vine::VineDataPath> Vine::CreateVineDataPath(shared_ptr<Vine::VineSession> session,
- Vine::VineDataPath::DataPathType type) {
- vine_dp_h data_path = nullptr;
- vine_dp_create(static_cast<vine_session_h>(session->GetSession()),
- static_cast<vine_dp_type_e>(type), &data_path);
-
- return make_shared<Vine::VineDataPath>(data_path);
-}
-
-} // 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_API_VINE_HH_
-#define CION_API_VINE_HH_
-
-#include <memory>
-#include <string>
-#include <unistd.h>
-#include <map>
-#include <functional>
-
-#include <dlog.h>
-#include <vine.h>
-
-#include <stdio.h>
-
-using namespace std;
-
-namespace cion {
-
-class Vine {
- public:
- class VineService {
- public:
- VineService(vine_service_h service) : service_(service) {
- }
-
- ~VineService() {
- vine_service_destroy(service_);
- }
-
- typedef void* vine_service;
-
- enum AddressFamily {
- IPV4 = VINE_ADDRESS_FAMILY_IPV4,
- IPV6 = VINE_ADDRESS_FAMILY_IPV6
- };
-
- void SetType(string service_type) {
- int ret;
- ret = vine_service_set_type(service_, service_type.c_str());
-
- LOGD("Service SetType : %d", ret);
- }
-
- string GetType() {
- char *type;
- int ret;
-
- ret = vine_service_get_type(service_, &type);
- LOGD("Service GetType : %d", ret);
-
- return string(type);
- }
-
- void SetName(string service_name) {
- int ret;
- ret = vine_service_set_name(service_, service_name.c_str());
-
- LOGD("Service SetName : %d", ret);
- }
-
- string GetName() {
- char *name;
- int ret;
-
- ret = vine_service_get_name(service_, &name);
-
- LOGD("Service GetName : %d", ret);
- return string(name);
- }
-
- void AddAttribute(string key, string value) {
- int ret;
- ret = vine_service_add_attribute(service_, key.c_str(), value.c_str());
-
- LOGD("Service AddAttribute : %d", ret);
- }
-
- void RemoveAttribute(string key) {
- int ret;
- ret = vine_service_remove_attribute(service_, key.c_str());
-
- LOGD("Service RemoveAttribute : %d", ret);
- }
-
- map<string, string> GetAttribute() {
- int ret;
- ret = vine_service_foreach_attribute(service_, VineServiceAttrCb, this);
-
- LOGD("Service GetAttribute : %d", ret);
-
- return attrs;
- }
-
- void SetPort(int port) {
- int ret;
- ret = vine_service_set_port(service_, port);
-
- LOGD("Service SetPort : %d", ret);
- }
-
- int GetPort() {
- int port;
- int ret;
-
- ret = vine_service_get_port(service_, &port);
-
- LOGD("Service GetPort : %d", ret);
-
- return port;
- }
-
- vine_service GetService() {
- return service_;
- }
-
- private:
- void SetAttr(string key, string value) {
- attrs[key] = value;
- }
-
- static bool VineServiceAttrCb(const char *key, const char* value, void* user_data) {
- VineService* service = static_cast<VineService*>(user_data);
-
- service->SetAttr(string(key), string(value));
-
- return true;
- }
-
- private:
- vine_service service_ = nullptr;
- map<string, string> attrs;
- };
-
- class VineSecurity {
- public:
- VineSecurity(vine_security_h security) : security_(security) {
- }
-
- ~VineSecurity() {
- vine_security_destroy(security_);
- }
-
- typedef void* vine_security;
-
- enum SecurityType {
- SECURITY_TYPE_NONE = VINE_SECURITY_TYPE_NONE,
- SECURITY_TYPE_TLS = VINE_SECURITY_TYPE_TLS,
- SECURITY_TYPE_PSK_OVER_TLS = VINE_SECURITY_TYPE_PSK_OVER_TLS
- };
-
- enum TlsVersion {
- TLS_VERSION_DEFAULT = VINE_SECURITY_TLS_VERSION_DEFAULT,
- TLS_VERSION_1_0 = VINE_SECURITY_TLS_VERSION_1_0,
- TLS_VERSION_1_1 = VINE_SECURITY_TLS_VERSION_1_1,
- TLS_VERSION_1_2 = VINE_SECURITY_TLS_VERSION_1_2,
- TLS_VERSION_1_3 = VINE_SECURITY_TLS_VERSION_1_3
- };
-
- enum VerificationFlag {
- VERIFICATION_FLAG_DEFAAULT = VINE_SECURITY_VERIFICATION_FLAG_DEFAULT,
- VERIFICATION_FLAG_ALLOW_SELF_SIGNED = VINE_SECURITY_VERIFICATION_FLAG_ALLOW_SELF_SIGNED,
- VERIFICATION_FLAG_SKIP_HOST_NAME_CHECK = VINE_SECURITY_VERIFICATION_FLAG_SKIP_HOST_NAME_CHECK
- };
-
- void SetType(SecurityType type) {
- int ret;
- ret = vine_security_set_type(security_, static_cast<vine_security_type_e>(type));
-
- LOGD("Security SetType : %d", ret);
- }
-
- SecurityType GetType() {
- vine_security_type_e type;
- int ret;
-
- ret = vine_security_get_type(security_, &type);
-
- LOGD("Security GetType : %d", ret);
-
- return static_cast<SecurityType>(type);
- }
-
- void SetTlsVersion(TlsVersion version) {
- int ret;
- ret = vine_security_set_tls_version(security_, static_cast<vine_security_tls_version_e>(version));
-
- LOGD("Security SetTlsVersion : %d", ret);
- }
-
- TlsVersion GetTlsVersion() {
- vine_security_tls_version_e version;
- int ret;
-
- ret = vine_security_get_tls_version(security_, &version);
-
- LOGD("Security GetTlsVersion : %d", ret);
-
- return static_cast<TlsVersion>(version);
- }
-
- void SetVerificationFlags(int flags) {
- int ret;
- ret = vine_security_set_verification_flags(security_, flags);
-
- LOGD("Security SetVerificationFlags : %d", ret);
- }
-
- int GetVerificationFlags() {
- int flags;
- int ret;
-
- ret = vine_security_get_verification_flags(security_, &flags);
-
- LOGD("Security GetVerificationFlags : %d", ret);
-
- return flags;
- }
-
- void SetCaPath(string ca_path) {
- int ret;
- ret = vine_security_set_ca_path(security_, ca_path.c_str());
-
- LOGD("Security SetCaPath : %d", ret);
- }
-
- string GetCaPath() {
- char* ca_path;
- int ret;
-
- ret = vine_security_get_ca_path(security_, &ca_path);
-
- LOGD("Security GetCaPath : %d", ret);
-
- return string(ca_path);
- }
-
- void SetCertPath(string cert_path) {
- int ret;
- ret = vine_security_set_cert_path(security_, cert_path.c_str());
-
- LOGD("Security SetCertPath : %d", ret);
- }
-
- string GetCertPath() {
- char* cert_path;
- int ret;
-
- ret = vine_security_get_cert_path(security_, &cert_path);
-
- LOGD("Security GetCertPath : %d", ret);
-
- return string(cert_path);
- }
-
- void SetPrivateKey(string key_path) {
- int ret;
- ret = vine_security_set_private_key(security_, key_path.c_str());
-
- LOGD("Security SetPrivateKey : %d", ret);
- }
-
- string GetPrivateKey() {
- char* key_path;
- int ret;
-
- ret = vine_security_get_private_key(security_, &key_path);
-
- LOGD("Security GetPrivateKey : %d", ret);
-
- return string(key_path);
- }
-
- void SetPresharedKey(string key) {
- int ret;
- ret = vine_security_set_psk(security_, key.c_str());
-
- LOGD("Security SetPresharedKey : %d", ret);
- }
-
- string GetPresharedKey() {
- char* key;
- int ret;
-
- ret = vine_security_get_psk(security_, &key);
-
- LOGD("Security GetPresharedKey : %d", ret);
-
- return string(key);
- }
-
- vine_security GetSecurity() {
- return security_;
- }
-
- private:
- vine_security security_ = nullptr;
-
- };
-
- class VineSession {
- public:
- VineSession(vine_session_h session) : session_(session) {
- }
-
- ~VineSession() {
- vine_session_destroy(session_);
- }
-
- typedef void* vine_session;
-
- int GetEventFd() {
- int fd;
- int ret;
-
- ret = vine_session_get_event_fd(session_, &fd);
-
- LOGD("Session GetEventFd : %d", ret);
-
- return fd;
- }
-
- void ProcessEvent() {
- int ret;
-
- ret = vine_session_process_event(session_);
-
- LOGD("Session ProcessEvent : %d", ret);
- }
-
- void SetRegisteredCallback() {
- int ret;
-
- ret = vine_session_set_registered_cb(session_, RegisteredCallback, nullptr);
-
- LOGD("Session ProcessEvent : %d", ret);
- }
-
- void UnsetRegisterCallback() {
- int ret;
-
- ret = vine_session_unset_registered_cb(session_);
-
- LOGD("Session UnsetRegisterCallback : %d", ret);
- }
-
-
- void SetDiscoveredCallback() {
- int ret;
-
- ret = vine_session_set_discovered_cb(session_, DiscoveredCallback, nullptr);
-
- LOGD("Session SetDiscoveredCallback : %d", ret);
- }
-
- void UnsetDiscoveredCallback() {
- int ret;
-
- ret = vine_session_unset_discovered_cb(session_);
-
- LOGD("Session UnsetDiscoveredCallback : %d", ret);
- }
-
- enum DiscoveryMethod {
- DISCOVERY_METHOD_DNS_SD = VINE_DISCOVERY_METHOD_DNS_SD
- };
-
- void SetDiscoveryMethod(DiscoveryMethod method) {
- int ret;
-
- ret = vine_session_set_discovery_method(session_,
- static_cast<vine_discovery_method_e>(method));
-
- LOGD("Session SetDiscoveryMethod : %d", ret);
- }
-
- void RegisterService(shared_ptr<VineService> service, std::string iface_name) {
- int ret;
-
- ret = vine_session_register(session_, static_cast<vine_service_h>(service->GetService()), iface_name.c_str());
-
- LOGD("Session RegisterService : %d", ret);
- }
-
- void UnregisterService() {
- int ret;
-
- ret = vine_session_unregister(session_);
-
- LOGD("Session UnregisterService : %d", ret);
- }
-
- void StartDiscovery(string service_type, string iface_name) {
- int ret;
-
- ret = vine_session_start_discovery(session_, service_type.c_str(),
- iface_name.c_str());
-
- LOGD("Session StartDiscovery : %d", ret);
- }
-
- void StopDiscovery() {
- int ret;
-
- ret = vine_session_stop_discovery(session_);
-
- LOGD("Session StopDiscovery : %d", ret);
- }
-
- void SetIpResolvedCallback(shared_ptr<VineService> service) {
- int ret;
-
- ret = vine_session_set_ip_resolved_cb(session_, static_cast<vine_service_h>(service->GetService()), IpResolvedCallback, nullptr);
-
- LOGD("Session SetIpResolvedCallback : %d", ret);
- }
-
- void UnsetIpResolvedCallback(shared_ptr<VineService> service) {
- int ret;
-
- ret = vine_session_unset_ip_resolved_cb(session_, static_cast<vine_service_h>(service->GetService()));
-
- LOGD("Session UnsetIpResolvedCallback : %d", ret);
- }
-
- vine_session GetSession() {
- return session_;
- }
-
- private:
- static void RegisteredCallback(vine_session_h session,
- const char *service_name, vine_error_e error, void *user_data) {
- printf("service registered \n");
- }
-
- // discovered_service can not be set data
- static void DiscoveredCallback(vine_session_h session,
- vine_service_h discovered_service, vine_service_state_e state, void *user_data) {
- printf("service discovered \n");
- }
-
- static void IpResolvedCallback(vine_session_h session, vine_service_h service,
- const char *ip, vine_address_family_e address_family, void *user_data) {
- printf("ip resolved\n");
- }
-
- private:
- vine_session session_ = nullptr;
-
- };
-
- class VineDataPath {
- public:
- VineDataPath(vine_dp_h dp) : dp_(dp) {
- }
-
- ~VineDataPath() {
- vine_dp_destroy(dp_);
- }
-
- typedef void* vine_data_path;
-
- enum DataPathType {
- DP_TYPE_SERVER = VINE_DP_TYPE_SERVER,
- DP_TYPE_CLIENT = VINE_DP_TYPE_CLIENT,
- DP_TYPE_PUBSUB = VINE_DP_TYPE_PUBSUB,
- DP_TYPE_UNKNOWN = VINE_DP_TYPE_UNKNOWN
- };
-
- void SetIfaceName(std::string name){
- int ret;
-
- ret = vine_dp_set_iface_name(dp_, name.c_str());
-
- LOGD("DataPath SetIfaceName : %d", ret);
- }
-
- // DP_TYPE_SERVER || DP_TYPE_PUBSUB possible
- void SetAddressFamily(VineService::AddressFamily addr_family) {
- int ret;
-
- ret = vine_dp_set_address_family(dp_,
- static_cast<vine_address_family_e>(addr_family));
-
- LOGD("DataPath SetAddressFamily : %d", ret);
- }
-
- // DP_TYPE_CLIENT possible
- void SetRemoteIp(VineService::AddressFamily addr_family, std::string ip) {
- int ret;
-
- ret = vine_dp_set_remote_ip(dp_,
- static_cast<vine_address_family_e>(addr_family), ip.c_str());
-
- LOGD("DataPath SetRemoteIp : %d", ret);
- }
-
- void SetPort(int port) {
- int ret;
-
- ret = vine_dp_set_port(dp_, port);
-
- LOGD("DataPath SetPort : %d", ret);
- }
-
- int GetPort() {
- int port;
- int ret;
-
- ret = vine_dp_get_port(dp_, &port);
-
- LOGD("DataPath GetPort : %d", ret);
-
- return port;
- }
-
- // DP_TYPE_PUBSUB possible
- void SetTopic(std::string topic) {
- int ret;
-
- ret = vine_dp_set_topic(dp_, topic.c_str());
-
- LOGD("DataPath SetTopic : %d", ret);
- }
-
- void SetSecurity(shared_ptr<VineSecurity> security) {
- int ret;
-
- ret = vine_dp_set_security(dp_, static_cast<vine_security_h>(security->GetSecurity()));
-
- LOGD("DataPath SetSecurity : %d", ret);
- }
-
- // DP_TYPE_SERVER only
- void SetAcceptedCallback() {
- int ret;
-
- ret = vine_dp_set_accepted_cb(dp_, DataPathAcceptedCallback, nullptr);
-
- LOGD("DataPath SetAcceptedCallback : %d", ret);
- }
-
- // DP_TYPE_SERVER only
- void UnsetAcceptedCallback() {
- int ret;
-
- ret = vine_dp_unset_accepted_cb(dp_);
-
- LOGD("DataPath UnsetAcceptedCallback : %d", ret);
- }
-
- void SetTerminatedCallback() {
- int ret;
-
- ret = vine_dp_set_terminated_cb(dp_, DataPathTerminatedCallback, nullptr);
-
- LOGD("DataPath SetTerminatedCallback : %d", ret);
- }
-
- void UnsetTerminatedCallback() {
- int ret;
-
- ret = vine_dp_unset_terminated_cb(dp_);
-
- LOGD("DataPath SetTerminatedCallback : %d", ret);
- }
-
- void DataPathOpen() {
- int ret;
-
- ret = vine_dp_open(dp_, DataPathOpenedCallback, nullptr);
-
- LOGD("DataPath SetTerminatedCallback : %d", ret);
- }
-
- void DataPathClose() {
- int ret;
-
- ret = vine_dp_close(dp_);
-
- LOGD("DataPath DataPathClose : %d", ret);
- }
-
- void Send(std::string buf, size_t len) {
- //vine_dp_send(dp_, buf.c_str(), len);
- }
-
- void Receive(std::string buf, size_t buf_len, size_t* read_len) {
- //vine_dp_recv(dp_, buf.c_str(), buf_len, read_len);
- }
-
- void SetReceivedCallback() {
- int ret;
-
- ret = vine_dp_set_received_cb(dp_, DataPathReceivedCallback, nullptr);
-
- LOGD("DataPath SetReceivedCallback : %d", ret);
- }
-
- void UnsetReceivedCallback() {
- int ret;
-
- ret = vine_dp_unset_received_cb(dp_);
-
- LOGD("DataPath UnsetReceivedCallback : %d", ret);
- }
-
- private:
- static void DataPathAcceptedCallback(vine_dp_h dp, void *user_data) {
- printf("data path accepted\n");
- }
-
- static void DataPathTerminatedCallback(vine_dp_h dp, void *user_data) {
- printf("data path accepted\n");
- }
-
- static void DataPathOpenedCallback(vine_dp_h dp, vine_error_e result, void *user_data) {
- printf("data path opened\n");
- }
-
- static void DataPathReceivedCallback(vine_dp_h dp, size_t received_len, void *user_data) {
- printf("data path received\n");
- }
-
- private:
- vine_data_path dp_ = nullptr;
- };
-
- public:
- static Vine& GetInst();
- shared_ptr<VineService> CreateVineService();
- shared_ptr<VineService> CloneVineService(shared_ptr<VineService> service);
- shared_ptr<VineSession> CreateVineSession();
- shared_ptr<VineSecurity> CreateVineSecurity();
- shared_ptr<VineDataPath> CreateVineDataPath(shared_ptr<VineSession> session,
- VineDataPath::DataPathType type);
-
- private:
- Vine();
- virtual ~Vine();
- int Init();
-
- private:
- class Impl;
- unique_ptr<Impl> impl_;
-};
-
-} // namespace cion
-
-#endif // CION_API_VINE_HH_
+++ /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_API_VINE_MANAGER_IMPLEMENTATION_HH_
-#define CION_API_VINE_MANAGER_IMPLEMENTATION_HH_
-
-namespace cion {
-
-class Vine::Impl {
- public:
- virtual ~Impl();
-
- private:
- friend class Vine;
- Impl();
-
- private:
-};
-
-} // namespace cion
-
-#endif // CION_API_VINE_MANAGER_IMPLEMENTATION_HH_
+++ /dev/null
-prefix=@PREFIX@
-exec_prefix=@EXEC_PREFIX@
-libdir=@LIB_INSTALL_DIR@
-includedir=@INCLUDE_INSTALL_DIR@
-
-Name: vine_wrapper
-Description: Vine API wrapper module
-Version: @VERSION@
-Libs: -L${libdir} -lcion
-Cflags: -I${includedir} -I${includedir}/vine_wrapper
-cppflags: -I${includedir}