namespace tidl {
CppCionGeneratorBase::CppCionGeneratorBase(std::shared_ptr<Document> doc)
- : Generator(doc) {
+ : CionPluginBase(doc) {
type_map_ = {
{"char", "char"}, {"int", "int"}, {"short", "short"},
{"long", "long long"}, {"string", "std::string"}, {"bool", "bool"},
void CppCionGeneratorBase::GenBodyCallback(std::ofstream& stream,
const Interface& iface, const Declaration& decl, bool is_proxy) {
if (!is_proxy) {
- GenTemplate(CB_CALLBACK_FILE_PAYLOAD_SEND, stream,
+ GenTemplate(std::string(ReplaceAll(CB_CALLBACK_FILE_PAYLOAD_SEND, {
+ { "<PEER_INFO_T>", GetTransportable().Cpp().GenPeerInfoType() },
+ { "<FILE_PAYLOAD_SEND>", GetTransportable().Cpp()
+ .GenServerFileSend("path", "cion_server_", "peer") },
+ { "<PAYLOAD_T>", GetTransportable().Cpp().GenPayloadType() }
+ })),
+ stream,
[&]()->std::string {
return iface.GetID();
},
[&]()->std::string {
return decl.GetID();
});
-
- GenTemplate(CB_CALLBACK_INVOKE_METHOD, stream,
+ GenTemplate(std::string(ReplaceAll(CB_CALLBACK_INVOKE_METHOD, {
+ { "<PAYLOAD_T>", GetTransportable().Cpp().GenPayloadType() },
+ { "<SERVER_SEND_ASYNC>", GetTransportable().Cpp()
+ .GenServerSendAsync("cion_server_", "", "pl", "size") }
+ })), stream,
[&]()->std::string {
return iface.GetID();
},
.Change("<PRIVATE_MEMBERS>", [&]() {
return is_proxy ? CB_CALLBACK_PRIVATE_PROXY : CB_CALLBACK_PRIVATE_STUB;
})
+ .Change("<PEER_INFO_T>", GetTransportable().Cpp().GenPeerInfoType())
+ .Change("<SERVER_T>", GetTransportable().Cpp().GenServerType())
.Out(stream);
}
for (const auto& attr : iface.GetAttributes()) {
if (attr->GetKey() == "ca_path")
- security_path += ReplaceAll(CB_INTERFACE_SECURITY_CA, "<ARG>",
- attr->GetValue());
+ security_path +=
+ GetTransportable().Cpp().GenSetSecurityCA(attr->GetValue());
else if (attr->GetKey() == "cert_path")
- security_path += ReplaceAll(CB_INTERFACE_SECURITY_CERT, "<ARG>",
- attr->GetValue());
+ security_path +=
+ GetTransportable().Cpp().GenSetSecurityCert(attr->GetValue());
else if (attr->GetKey() == "private_key")
- security_path += ReplaceAll(CB_INTERFACE_SECURITY_PRIVATE_KEY, "<ARG>",
- attr->GetValue());
+ security_path +=
+ GetTransportable().Cpp().GenSetSecurityPrivateKey(attr->GetValue());
}
return security_path;
#include "idlc/ast/type.h"
#include "idlc/ast/structure.h"
-#include "idlc/gen/generator.h"
+#include "idlc/gen_cion/cion_plugin_base.h"
namespace tidl {
-class CppCionGeneratorBase : public Generator {
+class CppCionGeneratorBase : public CionPluginBase {
public:
explicit CppCionGeneratorBase(std::shared_ptr<Document> doc);
virtual ~CppCionGeneratorBase() = default;
const char CB_CALLBACK_CTOR_STUB[] =
R"__cpp_cb(
- <CLS_NAME>(std::weak_ptr<ServiceBase> service, cion_server_h cion_server)
+ <CLS_NAME>(std::weak_ptr<ServiceBase> service, <SERVER_T> cion_server)
: CallbackBase(static_cast<int>(DelegateId::<CLS_NAME>), false) {
service_ = std::move(service);
cion_server_ = cion_server;
const char CB_CALLBACK_PRIVATE_STUB[] =
R"__cpp_cb(
- void FilePayloadSend(std::string path, cion_peer_info_h peer);
+ void FilePayloadSend(std::string path, <PEER_INFO_T> peer);
std::weak_ptr<ServiceBase> service_;
bool valid_ = true;
- cion_server_h cion_server_;
+ <SERVER_T> cion_server_;
)__cpp_cb";
const char CB_CALLBACK_FILE_PAYLOAD_SEND[] = R"__cpp_cb(
-void $$::$$::FilePayloadSend(std::string path, cion_peer_info_h peer)
+void $$::$$::FilePayloadSend(std::string path, <PEER_INFO_T> peer)
{
- cion_payload_h pl;
- int ret = cion_payload_create(&pl, CION_PAYLOAD_TYPE_FILE);
- if (ret != CION_ERROR_NONE) {
- _E("Failed to cion_payload_create : %d", ret);
- return;
- }
-
- ret = cion_payload_set_file_path(pl, path.c_str());
- if (ret != CION_ERROR_NONE) {
- _E("Failed to cion_payload_set_file_path : %d - %s", ret, path.c_str());
- cion_payload_destroy(pl);
- return;
- }
-
- ret = cion_server_send_payload_async(cion_server_, peer, pl, nullptr, nullptr);
- if (ret != CION_ERROR_NONE) {
- _E("Failed to cion_server_send_payload_async : %d", ret);
- cion_payload_destroy(pl);
- return;
- }
-
- cion_payload_destroy(pl);
+ <FILE_PAYLOAD_SEND>
}
)__cpp_cb";
throw InvalidIOException();
}
- cion_payload_h pl;
- cion_ret_ = cion_payload_create(&pl, CION_PAYLOAD_TYPE_DATA);
- if (cion_ret_ != CION_ERROR_NONE) {
- _E("Failed to cion_payload_create : %d", cion_ret_);
- rpc_port_parcel_destroy(p);
- return;
- }
-
- cion_ret_ = cion_payload_set_data(pl, (const unsigned char*)data, size);
- if (cion_ret_ != CION_ERROR_NONE) {
- _E("Failed to cion_payload_set_data : %d", cion_ret_);
- rpc_port_parcel_destroy(p);
- cion_payload_destroy(pl);
- return;
- }
-
- cion_ret_ = cion_server_send_payload_async(cion_server_, service_.lock()->GetPeer(), pl, nullptr, nullptr);
- if (cion_ret_ != CION_ERROR_NONE) {
- _E("Failed to cion_client_send_payload_async : %d", cion_ret_);
- rpc_port_parcel_destroy(p);
- cion_payload_destroy(pl);
- return;
- }
-
+ <PAYLOAD_T> pl;
+ <SERVER_SEND_ASYNC>
rpc_port_parcel_destroy(p);
- cion_payload_destroy(pl);
valid_ = false;
}
)__cpp_cb";
}
)__cpp_cb";
-const char CB_INTERFACE_SECURITY_CA[] =
-R"__cpp_cb(
- if (cion_security_set_ca_path(security, "<ARG>") != CION_ERROR_NONE) {
- _E("Failed to set ca path.");
- throw InvalidIOException();
- }
-)__cpp_cb";
-
-const char CB_INTERFACE_SECURITY_CERT[] =
-R"__cpp_cb(
- if (cion_security_set_cert_path(security, "<ARG>") != CION_ERROR_NONE) {
- _E("Failed to set cert path.");
- throw InvalidIOException();
- }
-)__cpp_cb";
-
-const char CB_INTERFACE_SECURITY_PRIVATE_KEY[] =
-R"__cpp_cb(
- if (cion_security_set_private_key_path(security, "<ARG>") != CION_ERROR_NONE) {
- _E("Failed to set private key path.");
- throw InvalidIOException();
- }
-)__cpp_cb";
-
const char CB_LOG_TAG[] =
R"__cpp_cb(
#ifdef LOG_TAG
void CppCionGroupBodyGen::GenConstructor(std::ofstream& stream,
const Interface& iface) {
ReplaceAll(CB_GROUP_INTERFACE_CTOR)
+ .Change("<GROUP_CREATE>", GetTransportable().Cpp().GenGroupCreate())
.Change("<CLS_NAME>", iface.GetID())
.Change("<SET_SECURITY>", GenSecurity(iface))
+ .Change("<PEER_INFO_T>", GetTransportable().Cpp().GenPeerInfoType())
+ .Change("<PAYLOAD_T>", GetTransportable().Cpp().GenPayloadType())
+ .Change("<SECURITY_T>", GetTransportable().Cpp().GenSecurityType())
+ .Change("<GROUP_T>", GetTransportable().Cpp().GenGroupType())
.Out(stream);
}
void CppCionGroupBodyGen::GenDestructor(std::ofstream& stream,
const Interface& iface) {
- stream << ReplaceAll(CB_DTOR, "<CLS_NAME>", iface.GetID()) << NLine(1);
+ stream << ReplaceAll(CB_DTOR, {
+ { "<CLS_NAME>", iface.GetID() },
+ { "<GROUP_DESTROY>", GetTransportable().Cpp().GenGroupDestroy() }
+ }) << NLine(1);
}
void CppCionGroupBodyGen::GenCionPayloadReceivedEvent(std::ofstream& stream,
const Interface& iface) {
- stream << ReplaceAll(CB_GROUP_ON_PAYLOAD_RECEIVED_CB_FRONT, "<CLS_NAME>",
- iface.GetID());
+ stream << ReplaceAll(CB_GROUP_ON_PAYLOAD_RECEIVED_CB_FRONT, {
+ { "<CLS_NAME>", iface.GetID() },
+ { "<PEER_INFO_T>", GetTransportable().Cpp().GenPeerInfoType() },
+ { "<PAYLOAD_T>", GetTransportable().Cpp().GenPayloadType() },
+ { "<PAYLOAD_TYPE_E>", GetTransportable().Cpp().GenPayloadTypeEnum() },
+ { "<PAYLOAD_GET_TYPE>",
+ GetTransportable().Cpp().GenPayloadGetType() },
+ { "<ERROR_NONE>", GetTransportable().Cpp().GenErrorNone() },
+ { "<PAYLOAD_TYPE_DATA>",
+ GetTransportable().Cpp().GenPayloadTypeData() },
+ { "<PAYLOAD_GET_DATA>", GetTransportable().Cpp().GenPayloadGetData() }
+ });
for (const auto& i : iface.GetDeclarations()) {
if (i->GetMethodType() == Declaration::MethodType::DELEGATE ||
if (!l.empty())
stream << AddIndent(TAB_SIZE * 2, l);
else if (decl.GetMethodType() == Declaration::MethodType::ASYNC)
- stream << CB_INVOCATION_ASYNC_MID << NLine(1);
+ stream << ReplaceAll(CB_INVOCATION_ASYNC_MID, {
+ { "<PAYLOAD_T>", GetTransportable().Cpp().GenPayloadType() },
+ { "<GROUP_PUBLISH>", GetTransportable().Cpp().GenGroupPublish() }
+ }) << NLine(1);
}, false, false);
stream << " while (false);" << NLine(1);
const char CB_DTOR[] =
R"__cpp_cb(
<CLS_NAME>::~<CLS_NAME>() {
- if (cion_group_ != nullptr) {
- int ret = cion_group_unsubscribe(cion_group_);
- if (ret != CION_ERROR_NONE)
- _E("Failed to unsubscribe. error(%d)", ret);
- cion_group_destroy(cion_group_);
- }
-
- if (cion_security_ != nullptr)
- cion_security_destroy(cion_security_);
+ <GROUP_DESTROY>
}
)__cpp_cb";
throw InvalidIOException();
}
- cion_payload_h pl;
- ret = cion_payload_create(&pl, CION_PAYLOAD_TYPE_DATA);
- if (ret != CION_ERROR_NONE) {
- _E("Failed to cion_payload_create : %d", ret);
- rpc_port_parcel_destroy(p);
- throw InvalidIOException();
- }
-
- ret = cion_payload_set_data(pl, (const unsigned char*)data, size);
- if (ret != CION_ERROR_NONE) {
- _E("Failed to cion_payload_set_data : %d", ret);
- rpc_port_parcel_destroy(p);
- cion_payload_destroy(pl);
- throw InvalidIOException();
- }
-
- ret = cion_group_publish(cion_group_, pl);
- if (ret != CION_ERROR_NONE) {
- _E("Failed to cion_group_publish : %d", ret);
- rpc_port_parcel_destroy(p);
- cion_payload_destroy(pl);
- throw InvalidIOException();
- }
-
- cion_payload_destroy(pl);
+ <PAYLOAD_T> pl;
+ <GROUP_PUBLISH>
)__cpp_cb";
const char CB_INVOCATION_END[] =
const char CB_GROUP_ON_PAYLOAD_RECEIVED_CB_FRONT[] =
R"__cpp_cb(
-void <CLS_NAME>::OnPayloadReceivedCB(const cion_peer_info_h peer_info,
- const cion_payload_h payload) {
- cion_payload_type_e type;
- int ret = cion_payload_get_type(payload, &type);
- if (ret != CION_ERROR_NONE) {
+void <CLS_NAME>::OnPayloadReceivedCB(const <PEER_INFO_T> peer_info,
+ const <PAYLOAD_T> payload) {
+ <PAYLOAD_TYPE_E> type;
+ int ret;
+ <PAYLOAD_GET_TYPE>
+ if (ret != <ERROR_NONE>) {
_E("Failed to cion_payload_get_type. error(%d)", ret);
return;
}
- if (type != CION_PAYLOAD_TYPE_DATA) {
+ if (type != <PAYLOAD_TYPE_DATA>) {
_E("Wrong payload type, only data payload is available");
return;
}
unsigned char *data;
unsigned int size;
- ret = cion_payload_get_data(payload, &data, &size);
- if (ret != CION_ERROR_NONE) {
+ <PAYLOAD_GET_DATA>
+ if (ret != <ERROR_NONE>) {
_E("Failed to cion_payload_get_data. error(%d)", ret);
return;
}
const char CB_GROUP_INTERFACE_CTOR[] =
R"__cpp_cb(
<CLS_NAME>::<CLS_NAME>(std::string topic) : topic_name_(std::move(topic)) {
- cion_security_h security;
- int ret = cion_security_create(&security);
- if (ret != CION_ERROR_NONE) {
- _E("Failed to create security handle. error(%d)", ret);
- throw InvalidIOException();
- }
-
- auto security_auto = std::unique_ptr<
- std::remove_pointer<cion_security_h>::type, decltype(cion_security_destroy)*>(
- security, cion_security_destroy);
-<SET_SECURITY>
- cion_group_h group = nullptr;
- ret = cion_group_create(&group, topic_name_.c_str(), security);
- if (ret != CION_ERROR_NONE) {
- _E("Failed to create handle. error(%d)", ret);
- throw InvalidIOException();
- }
- auto group_auto = std::unique_ptr<
- std::remove_pointer<cion_group_h>::type, decltype(cion_group_destroy)*>(
- group, cion_group_destroy);
-
- ret = cion_group_add_joined_cb(group,
- [](const char *topic_name, const cion_peer_info_h peer_info,
- void *user_data) {
- <CLS_NAME> *gr = static_cast<<CLS_NAME>*>(user_data);
- gr->OnJoined(peer_info);
- },
- this);
- if (ret != CION_ERROR_NONE) {
- _E("Failed to cion_group_add_joined_cb. error(%d)", ret);
- throw InvalidIOException();
- }
-
- ret = cion_group_add_left_cb(group,
- [](const char *topic_name, const cion_peer_info_h peer_info,
- void *user_data) {
- <CLS_NAME> *gr = static_cast<<CLS_NAME>*>(user_data);
- gr->OnLeft(peer_info);
- },
- this);
- if (ret != CION_ERROR_NONE) {
- _E("Failed to cion_group_add_left_cb. error(%d)", ret);
- throw InvalidIOException();
- }
-
- ret = cion_group_add_payload_received_cb(group,
- [](const char *topic_name, const cion_peer_info_h peer_info,
- const cion_payload_h payload, void *user_data) {
- <CLS_NAME> *gr = static_cast<<CLS_NAME>*>(user_data);
- gr->OnPayloadReceivedCB(peer_info, payload);
- },
- this);
- if (ret != CION_ERROR_NONE) {
- _E("Failed to cion_group_add_payload_received_cb. error(%d)", ret);
- throw InvalidIOException();
- }
-
- ret = cion_group_subscribe(group);
- if (ret != CION_ERROR_NONE) {
- _E("Failed to subscribe. error(%d)", ret);
- switch (ret) {
- case CION_ERROR_PERMISSION_DENIED :
- throw UnauthorizedAccessException();
- break;
- case CION_ERROR_INVALID_PARAMETER :
- throw NotConnectedSocketException();
- break;
- default :
- throw InvalidIOException();
- }
- }
-
- cion_security_ = security_auto.release();
- cion_group_ = group_auto.release();
+ <GROUP_CREATE>
}
)__cpp_cb";
stream << NLine(1) << "class " << iface.GetID() << " ";
GenBrace(stream, 0, [&]() {
stream << " public:" << NLine(1);
- stream << ReplaceAll(CB_PUBLIC_MEMBERS, "<CLS_NAME>", iface.GetID())
+ stream << ReplaceAll(CB_PUBLIC_MEMBERS, {
+ { "<CLS_NAME>", iface.GetID() },
+ { "<PEER_INFO_T>", GetTransportable().Cpp().GenPeerInfoType() }
+ })
<< NLine(1);
GenMethods(stream, iface);
GenMethodHandlers(stream, iface);
stream << NLine(1) << " private:" << NLine(1);
GenMethodId(stream, iface, true);
- stream << CB_PRIVATE_MEMBERS;
+ stream << ReplaceAll(CB_PRIVATE_MEMBERS, {
+ { "<PEER_INFO_T>", GetTransportable().Cpp().GenPeerInfoType() },
+ { "<PAYLOAD_T>", GetTransportable().Cpp().GenPayloadType() },
+ { "<CLIENT_T>", GetTransportable().Cpp().GenClientType() },
+ { "<SECURITY_T>", GetTransportable().Cpp().GenSecurityType() }
+ });
}, false, false);
stream << ";" << NLine(1);
}
for (const auto& i : decls) {
stream << Tab(1) << "virtual " << ConvertTypeToString(i->GetType()) << " On"
- << i->GetID() << "(const cion_peer_info_h peer_info, ";
+ << i->GetID() << ReplaceAll("(const <PEER_INFO_T> peer_info, ",
+ "<PEER_INFO_T>", GetTransportable().Cpp().GenPeerInfoType());
GenParameters(stream, i->GetParameters());
stream << ") = 0;" << NLine(1);
}
/// <summary>
/// This method will be invoked when the peer group app is joined to the topic.
/// </summary>
- virtual void OnJoined(const cion_peer_info_h peer_info) = 0;
+ virtual void OnJoined(const <PEER_INFO_T> peer_info) = 0;
/// <summary>
/// This method will be invoked after the peer group app was left from the topic.
/// </summary>
- virtual void OnLeft(const cion_peer_info_h peer_info) = 0;
+ virtual void OnLeft(const <PEER_INFO_T> peer_info) = 0;
)__cpp_cb";
const char CB_PRIVATE_MEMBERS[] =
-R"__cpp_cb( void OnPayloadReceivedCB(const cion_peer_info_h peer_info,
- const cion_payload_h payload);
- cion_client_h cion_group_ = nullptr;
- cion_security_h cion_security_ = nullptr;
+R"__cpp_cb( void OnPayloadReceivedCB(const <PEER_INFO_T> peer_info,
+ const <PAYLOAD_T> payload);
+ <CLIENT_T> cion_group_ = nullptr;
+ <SECURITY_T> cion_security_ = nullptr;
std::string topic_name_;
std::recursive_mutex mutex_;
)__cpp_cb";
const Interface& iface) {
ReplaceAll(CB_PROXY_INTERFACE_CTOR)
.Change("$$", iface.GetID())
+ .Change("<CLIENT_CREATE>", GetTransportable().Cpp().GenClientCreate())
.Change("<SET_SECURITY>", GenSecurity(iface))
+ .Change("<CLIENT_T>", GetTransportable().Cpp().GenClientType())
+ .Change("<SECURITY_T>", GetTransportable().Cpp().GenSecurityType())
.Out(stream);
}
void CppCionProxyBodyGen::GenDestructor(std::ofstream& stream,
const Interface& iface) {
- GenTemplate(CB_DTOR, stream,
+ GenTemplate(std::string(ReplaceAll(CB_DTOR, {
+ { "<PEER_INFO_DESTROY>",
+ GetTransportable().Cpp().GenPeerInfoDestroy("peer_") },
+ { "<CLIENT_DESTROY>", GetTransportable().Cpp().GenClientDestroy() }
+ })), stream,
[&]()->std::string {
return iface.GetID();
},
void CppCionProxyBodyGen::GenHelperMethods(std::ofstream& stream,
const Interface& iface) {
- stream << ReplaceAll(CB_PROXY_HELPER_METHODS, "##", iface.GetID())
- << NLine(1);
+ stream << ReplaceAll(CB_PROXY_HELPER_METHODS, {
+ { "##", iface.GetID() },
+ { "<PEER_INFO_T>", GetTransportable().Cpp().GenPeerInfoType() },
+ { "<PAYLOAD_T>", GetTransportable().Cpp().GenPayloadType() },
+ { "<PAYLOAD_TRANSFER_STATUS_T>",
+ GetTransportable().Cpp().GenPayloadTransferStatusType() },
+ { "<CLIENT_TRY_CONNECT>",
+ GetTransportable().Cpp().GenClientTryConnect(
+ "cion_client_", "peer_") },
+ { "<CLIENT_DISCONNECT>", GetTransportable().Cpp()
+ .GenClientDisconnect("cion_client_") },
+ { "<CLIENT_TRY_DISCOVERY>", GetTransportable().Cpp()
+ .GenClientTryDiscovery("cion_client_") },
+ { "<CLIENT_STOP_DISCOVERY>", GetTransportable().Cpp()
+ .GenClientStopDiscovery("cion_client_") },
+ { "<PAYLOAD_TYPE_E>", GetTransportable().Cpp().GenPayloadTypeEnum() },
+ { "<PAYLOAD_GET_TYPE>",
+ GetTransportable().Cpp().GenPayloadGetType() },
+ { "<ERROR_NONE>", GetTransportable().Cpp().GenErrorNone() },
+ { "<PAYLOAD_TYPE_DATA>",
+ GetTransportable().Cpp().GenPayloadTypeData() },
+ { "<PAYLOAD_TYPE_FILE>",
+ GetTransportable().Cpp().GenPayloadTypeFile() },
+ { "<PAYLOAD_GET_DATA>",
+ GetTransportable().Cpp().GenPayloadGetData() },
+ { "<PEER_INFO_CLONE>", GetTransportable().Cpp()
+ .GenPeerInfoClone("peer_info", "&cl->peer_") },
+ { "<PEER_INFO_GET_APPID>", GetTransportable().Cpp()
+ .GenPeerInfoGetAppID("peer_info", "&app_id") }
+ }) << NLine(1);
}
void CppCionProxyBodyGen::GenMethods(std::ofstream& stream,
void CppCionProxyBodyGen::GenFilePayloadSend(std::ofstream& stream,
const Interface& iface) {
- GenTemplate(CB_PROXY_FILE_PAYLOAD_SEND, stream,
+ GenTemplate(std::string(ReplaceAll(CB_PROXY_FILE_PAYLOAD_SEND, {
+ { "<FILE_PAYLOAD_SEND>", GetTransportable().Cpp()
+ .GenClientFileSend("path", "cion_client_") },
+ { "<PAYLOAD_T>", GetTransportable().Cpp().GenPayloadType() }
+ })), stream,
[&]()->std::string {
return iface.GetID();
});
if (!l.empty())
stream << AddIndent(TAB_SIZE * 2, l);
if (decl.GetMethodType() == Declaration::MethodType::SYNC)
- stream << CB_INVOCATION_SYNC_MID << NLine(1);
+ stream << ReplaceAll(CB_INVOCATION_SYNC_MID, "<CLIENT_SEND>",
+ GetTransportable().Cpp().GenClientSend("cion_client_", "data",
+ "size", "return_data", "return_data_size")) << NLine(1);
else if (decl.GetMethodType() == Declaration::MethodType::ASYNC)
- stream << CB_INVOCATION_ASYNC_MID << NLine(1);
+ stream << ReplaceAll(CB_INVOCATION_ASYNC_MID, {
+ { "<PAYLOAD_T>", GetTransportable().Cpp().GenPayloadType() },
+ { "<CLIENT_SEND_ASYNC>",
+ GetTransportable().Cpp().GenClientSendAsync(
+ "cion_client_", "pl", "size") }
+ }) << NLine(1);
}, false, false);
stream << " while (false);" << NLine(1);
R"__cpp_cb(
$$::~$$() {
if (peer_ != nullptr)
- cion_peer_info_destroy(peer_);
-
- if (cion_client_ != nullptr)
- cion_client_destroy(cion_client_);
-
- if (cion_security_ != nullptr)
- cion_security_destroy(cion_security_);
+ <PEER_INFO_DESTROY>
+<CLIENT_DESTROY>
}
)__cpp_cb";
rpc_port_parcel_destroy(p);
throw InvalidIOException();
}
-
- ret = cion_client_send_data(cion_client_, (unsigned char *)data, size,
- 100, &return_data, &return_data_size);
- if (ret != RPC_PORT_ERROR_NONE) {
- _E("Failed to cion_client_send_data : error(%d)", ret);
- rpc_port_parcel_destroy(p);
- throw InvalidIOException();
- }
+<CLIENT_SEND>
)__cpp_cb";
throw InvalidIOException();
}
- cion_payload_h pl;
- ret = cion_payload_create(&pl, CION_PAYLOAD_TYPE_DATA);
- if (ret != CION_ERROR_NONE) {
- _E("Failed to cion_payload_create : %d", ret);
- rpc_port_parcel_destroy(p);
- throw InvalidIOException();
- }
-
- ret = cion_payload_set_data(pl, (const unsigned char*)data, size);
- if (ret != CION_ERROR_NONE) {
- _E("Failed to cion_payload_set_data : %d", ret);
- rpc_port_parcel_destroy(p);
- cion_payload_destroy(pl);
- throw InvalidIOException();
- }
-
- ret = cion_client_send_payload_async(cion_client_, pl, nullptr, nullptr);
- if (ret != CION_ERROR_NONE) {
- _E("Failed to cion_client_send_payload_async : %d", ret);
- rpc_port_parcel_destroy(p);
- cion_payload_destroy(pl);
- throw InvalidIOException();
- }
-
- cion_payload_destroy(pl);
+ <PAYLOAD_T> pl;
+<CLIENT_SEND_ASYNC>
)__cpp_cb";
const char CB_INVOCATION_RECEIVE[] =
const char CB_PROXY_FILE_PAYLOAD_SEND[] = R"__cpp_cb(
void $$::FilePayloadSend(std::string path)
{
- cion_payload_h pl;
- int ret = cion_payload_create(&pl, CION_PAYLOAD_TYPE_FILE);
- if (ret != CION_ERROR_NONE) {
- _E("Failed to cion_payload_create : %d", ret);
- return;
- }
-
- ret = cion_payload_set_file_path(pl, path.c_str());
- if (ret != CION_ERROR_NONE) {
- _E("Failed to cion_payload_set_file_path : %d - %s", ret, path.c_str());
- cion_payload_destroy(pl);
- return;
- }
-
- ret = cion_client_send_payload_async(cion_client_, pl, nullptr, nullptr);
- if (ret != CION_ERROR_NONE) {
- _E("Failed to cion_client_send_payload_async : %d", ret);
- cion_payload_destroy(pl);
- return;
- }
-
- cion_payload_destroy(pl);
+ <FILE_PAYLOAD_SEND>
}
)__cpp_cb";
R"__cpp_cb(
void ##::Connect() {
if (peer_) {
- int ret = cion_client_connect(cion_client_, peer_);
- if (ret != CION_ERROR_NONE) {
- _E("Failed to connect to stub. error(%d)", ret);
- switch(ret) {
- case CION_ERROR_PERMISSION_DENIED :
- throw UnauthorizedAccessException();
- break;
- case CION_ERROR_INVALID_PARAMETER :
- throw NotConnectedSocketException();
- break;
- default :
- throw InvalidIOException();
- }
- }
+ <CLIENT_TRY_CONNECT>
} else {
_E("Not discovered");
}
}
void ##::Disconnect() {
- int ret = cion_client_disconnect(cion_client_);
- if (ret != CION_ERROR_NONE) {
- _E("Failed to disconnect to stub. error(%d)", ret);
- throw NotConnectedSocketException();
- }
+ <CLIENT_DISCONNECT>
}
void ##::Discovery() {
- int ret = cion_client_try_discovery(cion_client_, OnDiscoveredCB, this);
- if (ret != CION_ERROR_NONE) {
- _E("Failed to discovery to stub. error(%d)", ret);
- switch(ret) {
- case CION_ERROR_PERMISSION_DENIED :
- throw UnauthorizedAccessException();
- break;
- default :
- throw InvalidIOException();
- }
- }
+ <CLIENT_TRY_DISCOVERY>
}
void ##::StopDiscovery() {
- int ret = cion_client_stop_discovery(cion_client_);
- if (ret != CION_ERROR_NONE) {
- _E("Failed to stop discovery. error(%d)", ret);
- return;
- }
+ <CLIENT_STOP_DISCOVERY>
}
void ##::OnConnectionResultCB(const char *service_name,
- const cion_peer_info_h peer_info, const cion_connection_result_h result,
+ const <PEER_INFO_T> peer_info, const cion_connection_result_h result,
void *user_data) {
## *cl = static_cast<##*>(user_data);
cion_connection_status_e status;
}
void ##::OnDisconnectedCB(const char *service_name,
- const cion_peer_info_h peer_info, void *user_data) {
+ const <PEER_INFO_T> peer_info, void *user_data) {
## *cl = static_cast<##*>(user_data);
cl->delegate_list_.clear();
cl->listener_->OnDisconnected();
}
void ##::OnDiscoveredCB(const char *service_name,
- const cion_peer_info_h peer_info, void *user_data) {
+ const <PEER_INFO_T> peer_info, void *user_data) {
## *cl = static_cast<##*>(user_data);
char *app_id;
- int ret = cion_peer_info_get_app_id(peer_info, &app_id);
+ int ret = <PEER_INFO_GET_APPID>
if (ret != CION_ERROR_NONE) {
_E("Failed to cion_peer_info_get_app_id. error(%d)", ret);
return;
auto app_id_auto = std::unique_ptr<char, decltype(std::free)*>(
app_id, std::free);
if (std::string(app_id) == cl->target_appid_) {
- ret = cion_peer_info_clone(peer_info, &cl->peer_);
+ ret = <PEER_INFO_CLONE>
if (ret != CION_ERROR_NONE) {
_E("Failed to cion_peer_info_clone. error(%d)", ret);
return;
}
void ##::OnPayloadReceivedCB(const char *service_name,
- const cion_peer_info_h peer_info, const cion_payload_h payload,
- cion_payload_transfer_status_e status,
+ const <PEER_INFO_T> peer_info, const <PAYLOAD_T> payload,
+ <PAYLOAD_TRANSFER_STATUS_T> status,
void *user_data) {
## *cl = static_cast<##*>(user_data);
char *app_id;
- int ret = cion_peer_info_get_app_id(peer_info, &app_id);
+ int ret = <PEER_INFO_GET_APPID>
if (ret != CION_ERROR_NONE) {
_E("Failed to cion_peer_info_get_app_id. error(%d)", ret);
return;
return;
}
- cion_payload_type_e type;
- ret = cion_payload_get_type(payload, &type);
- if (ret != CION_ERROR_NONE) {
+ <PAYLOAD_TYPE_E> type;
+ <PAYLOAD_GET_TYPE>
+ if (ret != <ERROR_NONE>) {
_E("Failed to cion_payload_get_type. error(%d)", ret);
return;
}
- if (type == CION_PAYLOAD_TYPE_FILE) {
+ if (type == <PAYLOAD_TYPE_FILE>) {
cl->listener_->OnFileReceived(peer_info, payload, status);
return;
}
unsigned char *data;
unsigned int size;
- ret = cion_payload_get_data(payload, &data, &size);
- if (ret != CION_ERROR_NONE) {
+ <PAYLOAD_GET_DATA>
+ if (ret != <ERROR_NONE>) {
_E("Failed to cion_payload_get_data. error(%d)", ret);
return;
}
const std::string& target_appid)
: listener_(listener), service_name_(service_name),
target_appid_(target_appid) {
- cion_security_h security;
- int ret = cion_security_create(&security);
- if (ret != CION_ERROR_NONE) {
- _E("Failed to create security handle. error(%d)", ret);
- throw InvalidIOException();
- }
-
- auto security_auto = std::unique_ptr<
- std::remove_pointer<cion_security_h>::type, decltype(cion_security_destroy)*>(
- security, cion_security_destroy);
-<SET_SECURITY>
- cion_client_h client = nullptr;
- ret = cion_client_create(&client, service_name.c_str(), security);
- if (ret != CION_ERROR_NONE) {
- _E("Failed to create handle. error(%d)", ret);
- throw InvalidIOException();
- }
- auto client_auto = std::unique_ptr<
- std::remove_pointer<cion_client_h>::type, decltype(cion_client_destroy)*>(
- client, cion_client_destroy);
-
- ret = cion_client_add_disconnected_cb(client, OnDisconnectedCB,
- this);
- if (ret != CION_ERROR_NONE) {
- _E("Failed to cion_client_add_disconnected_cb. error(%d)", ret);
- throw InvalidIOException();
- }
-
-
- ret = cion_client_add_connection_result_cb(client, OnConnectionResultCB,
- this);
- if (ret != CION_ERROR_NONE) {
- _E("Failed to cion_client_add_connection_result_cb. error(%d)", ret);
- throw InvalidIOException();
- }
-
- ret = cion_client_add_payload_received_cb(client, OnPayloadReceivedCB,
- this);
- if (ret != CION_ERROR_NONE) {
- _E("Failed to cion_client_add_payload_received_cb. error(%d)", ret);
- throw InvalidIOException();
- }
-
- cion_security_ = security_auto.release();
- cion_client_ = client_auto.release();
+ <CLIENT_CREATE>
}
)__cpp_cb";
GenBrace(stream, 0, [&]() {
stream << " public:" << NLine(1);
GenHeaderCallbacks(stream, iface, true);
- GenTemplate(CB_PUBLIC_MEMBERS, stream,
+ GenTemplate(std::string(ReplaceAll(CB_PUBLIC_MEMBERS, {
+ { "<PEER_INFO_T>", GetTransportable().Cpp().GenPeerInfoType() },
+ { "<PAYLOAD_T>", GetTransportable().Cpp().GenPayloadType() },
+ { "<PAYLOAD_TRANSFER_STATUS_T>",
+ GetTransportable().Cpp().GenPayloadTransferStatusType() }
+ })), stream,
[&]()->std::string {
return iface.GetID();
},
GenDelegateId(stream, iface);
stream << NLine(1) << " private:" << NLine(1);
GenMethodId(stream, iface);
- stream << CB_PRIVATE_MEMBERS;
+ stream << ReplaceAll(CB_PRIVATE_MEMBERS, {
+ { "<PEER_INFO_T>", GetTransportable().Cpp().GenPeerInfoType() },
+ { "<PAYLOAD_T>", GetTransportable().Cpp().GenPayloadType() },
+ { "<CLIENT_T>", GetTransportable().Cpp().GenClientType() },
+ { "<PAYLOAD_TRANSFER_STATUS_T>",
+ GetTransportable().Cpp().GenPayloadTransferStatusType() },
+ { "<SECURITY_T>", GetTransportable().Cpp().GenSecurityType() }
+ });
}, false, false);
stream << ";" << NLine(1);
}
/// <summary>
/// This method will be invoked when file receieved from service.
/// </summary>
- virtual void OnFileReceived(cion_peer_info_h peer_info,
- cion_payload_h file_payload, cion_payload_transfer_status_e status) = 0;
+ virtual void OnFileReceived(<PEER_INFO_T> peer_info,
+ <PAYLOAD_T> file_payload, <PAYLOAD_TRANSFER_STATUS_T> status) = 0;
};
/// <summary>
void FilePayloadSend(std::string path);
static void OnConnectionResultCB(const char *service_name,
- const cion_peer_info_h peer_info, const cion_connection_result_h result,
+ const <PEER_INFO_T> peer_info, const cion_connection_result_h result,
void *user_data);
static void OnDisconnectedCB(const char *service_name,
- const cion_peer_info_h peer_info, void *user_data);
+ const <PEER_INFO_T> peer_info, void *user_data);
static void OnDiscoveredCB(const char *service_name,
- const cion_peer_info_h peer_info, void *user_data);
+ const <PEER_INFO_T> peer_info, void *user_data);
static void OnPayloadAsyncResultCB(const cion_payload_async_result_h result,
void *user_data);
static void OnPayloadReceivedCB(const char *service_name,
- const cion_peer_info_h peer_info, const cion_payload_h payload,
- cion_payload_transfer_status_e status,
+ const <PEER_INFO_T> peer_info, const <PAYLOAD_T> payload,
+ <PAYLOAD_TRANSFER_STATUS_T> status,
void *user_data);
- cion_client_h cion_client_ = nullptr;
- cion_security_h cion_security_ = nullptr;
- cion_peer_info_h peer_ = nullptr;
+ <CLIENT_T> cion_client_ = nullptr;
+ <SECURITY_T> cion_security_ = nullptr;
+ <PEER_INFO_T> peer_ = nullptr;
IEventListener* listener_;
std::string service_name_;
std::string target_appid_;
void CppCionStubBodyGen::GenServiceBase(std::ofstream& stream,
const Interface& iface) {
- GenTemplate(CB_CTOR_SERVICE_BASE, stream,
+ GenTemplate(std::string(ReplaceAll(CB_CTOR_SERVICE_BASE, {
+ { "<PEER_INFO_T>", GetTransportable().Cpp().GenPeerInfoType() },
+ { "<PEER_INFO_CLONE>", GetTransportable().Cpp()
+ .GenPeerInfoClone("peer", "&peer_") }
+ })), stream,
[&]()->std::string {
return iface.GetID();
});
const Interface& iface) {
ReplaceAll(CB_CTOR_FRONT)
.Change("##", iface.GetID())
+ .Change("<SERVER_REGISTER>", GetTransportable().Cpp().GenServerRegister())
.Change("<SET_SECURITY>", GenSecurity(iface))
+ .Change("<SERVER_T>", GetTransportable().Cpp().GenServerType())
+ .Change("<SECURITY_T>", GetTransportable().Cpp().GenSecurityType())
.Out(stream);
}
if (options_->IsThreadEnabled())
stream << ReplaceAll(CB_DEFAULT_THREAD_METHODS, "##", iface.GetID());
- stream << ReplaceAll(CB_DEFAULT_METHODS, "##", iface.GetID());
+ stream << ReplaceAll(CB_DEFAULT_METHODS, {
+ { "##", iface.GetID() },
+ { "<PEER_INFO_T>", GetTransportable().Cpp().GenPeerInfoType() },
+ { "<SERVER_UNREGISTER>",
+ GetTransportable().Cpp().GenServerUnregister() },
+ { "<SERVER_ACCEPT>",
+ GetTransportable().Cpp().GenServerAccept() },
+ { "<SERVER_REJECT>",
+ GetTransportable().Cpp().GenServerReject() },
+ { "<SERVER_SET_DISPLAY_NAME>",
+ GetTransportable().Cpp().GenServerSetDisplayName() },
+ { "<SERVER_SET_ONDEMAND_LAUNCH_ENABLED>",
+ GetTransportable().Cpp().GenServerSetOnDemandLaunchEnabled() },
+ { "<SERVER_LISTEN>",
+ GetTransportable().Cpp().GenServerListen() },
+ { "<SERVER_DISCONNECT>", GetTransportable().Cpp()
+ .GenServerDisconnect("cion_server_", "p") },
+ { "<PEER_INFO_GET_APPID1>", GetTransportable().Cpp()
+ .GenPeerInfoGetAppID("peer_info", "&peer_app_id") },
+ { "<PEER_INFO_GET_APPID2>", GetTransportable().Cpp()
+ .GenPeerInfoGetAppID("s->get()->GetPeer()", "&service_app_id") },
+ { "<PEER_INFO_GET_UUID1>", GetTransportable().Cpp()
+ .GenPeerInfoGetUUID("peer_info", "&peer_uuid") },
+ { "<PEER_INFO_GET_UUID2>", GetTransportable().Cpp()
+ .GenPeerInfoGetUUID("s->get()->GetPeer()", "&service_uuid") }
+ });
}
void CppCionStubBodyGen::GenCionDataReceivedEvent(std::ofstream& stream,
return iface.GetID();
});
} else {
- GenTemplate(CB_CION_ON_DATA_RECEIVED_CB_FRONT, stream,
+ GenTemplate(std::string(ReplaceAll(CB_CION_ON_DATA_RECEIVED_CB_FRONT, {
+ { "<PEER_INFO_T>", GetTransportable().Cpp().GenPeerInfoType() },
+ { "<PEER_INFO_GET_APPID1>", GetTransportable().Cpp()
+ .GenPeerInfoGetAppID("peer_info", "&peer_app_id") },
+ { "<PEER_INFO_GET_APPID2>", GetTransportable().Cpp()
+ .GenPeerInfoGetAppID("s->GetPeer()", "&service_app_id") },
+ { "<PEER_INFO_GET_UUID1>", GetTransportable().Cpp()
+ .GenPeerInfoGetUUID("peer_info", "&peer_uuid") },
+ { "<PEER_INFO_GET_UUID2>", GetTransportable().Cpp()
+ .GenPeerInfoGetUUID("s->GetPeer()", "&service_uuid") }
+ })), stream,
[&]()->std::string {
return iface.GetID();
},
void CppCionStubBodyGen::GenCionPayloadReceivedEvent(std::ofstream& stream,
const Interface& iface) {
- GenTemplate(CB_CION_ON_PAYLOAD_RECEIVED_CB_FRONT, stream,
+ GenTemplate(std::string(ReplaceAll(CB_CION_ON_PAYLOAD_RECEIVED_CB_FRONT, {
+ { "<PEER_INFO_T>", GetTransportable().Cpp().GenPeerInfoType() },
+ { "<PAYLOAD_T>", GetTransportable().Cpp().GenPayloadType() },
+ { "<PAYLOAD_TRANSFER_STATUS_T>",
+ GetTransportable().Cpp().GenPayloadTransferStatusType() },
+ { "<PAYLOAD_TYPE_E>", GetTransportable().Cpp().GenPayloadTypeEnum() },
+ { "<PAYLOAD_GET_TYPE>",
+ GetTransportable().Cpp().GenPayloadGetType() },
+ { "<ERROR_NONE>", GetTransportable().Cpp().GenErrorNone() },
+ { "<PAYLOAD_TYPE_DATA>",
+ GetTransportable().Cpp().GenPayloadTypeData() },
+ { "<PAYLOAD_TYPE_FILE>",
+ GetTransportable().Cpp().GenPayloadTypeFile() },
+ { "<PAYLOAD_GET_DATA>",
+ GetTransportable().Cpp().GenPayloadGetData() },
+ { "<PEER_INFO_GET_APPID1>", GetTransportable().Cpp()
+ .GenPeerInfoGetAppID("peer_info", "&peer_app_id") },
+ { "<PEER_INFO_GET_APPID2>", GetTransportable().Cpp()
+ .GenPeerInfoGetAppID("s->GetPeer()", "&service_app_id") },
+ { "<PEER_INFO_GET_UUID1>", GetTransportable().Cpp()
+ .GenPeerInfoGetUUID("peer_info", "&peer_uuid") },
+ { "<PEER_INFO_GET_UUID2>", GetTransportable().Cpp()
+ .GenPeerInfoGetUUID("s->GetPeer()", "&service_uuid") }
+ })), stream,
[&]()->std::string {
return iface.GetID();
},
void CppCionStubBodyGen::GenFilePayloadSend(std::ofstream& stream,
const Interface& iface) {
- GenTemplate(CB_FILE_PAYLOAD_SEND, stream,
+ GenTemplate(std::string(ReplaceAll(CB_FILE_PAYLOAD_SEND, {
+ { "<PEER_INFO_T>", GetTransportable().Cpp().GenPeerInfoType() },
+ { "<FILE_PAYLOAD_SEND>", GetTransportable().Cpp()
+ .GenServerFileSend("path", "cion_server_", "peer") },
+ { "<PAYLOAD_T>", GetTransportable().Cpp().GenPayloadType() }
+ })), stream,
[&]()->std::string {
return iface.GetID();
});
const char CB_CTOR_FRONT[] =
R"__cpp_cb(
##::##(const std::string& service_name, const std::string& display_name) {
- cion_security_h security;
- int ret = cion_security_create(&security);
- if (ret != CION_ERROR_NONE) {
- _E("Failed to create security handle. error(%d)", ret);
- throw InvalidIOException();
- }
-
- auto security_auto = std::unique_ptr<
- std::remove_pointer<cion_security_h>::type, decltype(cion_security_destroy)*>(
- security, cion_security_destroy);
-<SET_SECURITY>
- cion_server_h server;
- ret = cion_server_create(&server, service_name.c_str(),
- display_name.c_str(), security);
- if (ret != CION_ERROR_NONE) {
- _E("Failed to create handle. error(%d)", ret);
- throw InvalidIOException();
- }
- auto server_auto = std::unique_ptr<
- std::remove_pointer<cion_server_h>::type, decltype(cion_server_destroy)*>(
- server, cion_server_destroy);
-
- ret = cion_server_add_connection_result_cb(server, OnConnectionResultCB,
- this);
- if (ret != CION_ERROR_NONE) {
- _E("Failed to cion_server_add_connection_result_cb. error(%d)", ret);
- throw InvalidIOException();
- }
-
- ret = cion_server_add_payload_received_cb(server, OnPayloadReceivedCB,
- this);
- if (ret != CION_ERROR_NONE) {
- _E("Failed to cion_server_add_payload_received_cb. error(%d)", ret);
- throw InvalidIOException();
- }
-
- ret = cion_server_set_data_received_cb(server, OnDataReceivedCB, this);
- if (ret != CION_ERROR_NONE) {
- _E("Failed to cion_server_set_data_received_cb. error(%d)", ret);
- throw InvalidIOException();
- }
-
- ret = cion_server_add_disconnected_cb(server, OnDisconnectedCB, this);
- if (ret != CION_ERROR_NONE) {
- _E("Failed to cion_server_add_disconnected_cb. error(%d)", ret);
- throw InvalidIOException();
- }
-
- cion_security_ = security_auto.release();
- cion_server_ = server_auto.release();
+ <SERVER_REGISTER>
}
)__cpp_cb";
for (auto& i : services_) {
i->OnTerminate();
}
-
- if (cion_server_ != nullptr)
- cion_server_destroy(cion_server_);
-
- if (cion_security_ != nullptr)
- cion_security_destroy(cion_security_);
+<SERVER_UNREGISTER>
}
void ##::Listen(std::shared_ptr<##::ServiceBase::Factory> service_factory) {
service_factory_ = std::move(service_factory);
- int ret = cion_server_listen(cion_server_, OnConnectionRequestCB, this);
- if (ret != CION_ERROR_NONE) {
- _E("Failed to cion_server_listen. error(%d)", ret);
- switch(ret) {
- case CION_ERROR_PERMISSION_DENIED :
- throw UnauthorizedAccessException();
- break;
- default :
- throw InvalidIOException();
- }
- }
+ <SERVER_LISTEN>
}
void ##::Accept(std::shared_ptr<ServiceBase> service) {
- auto p = service->GetPeer();
- int ret = cion_server_accept(cion_server_, p);
- if (ret != CION_ERROR_NONE) {
- _E("Failed to cion_server_accept. error(%d)", ret);
- throw InvalidIOException();
- }
-
- service->OnCreate();
- services_.emplace_back(std::move(service));
+ <SERVER_ACCEPT>
}
void ##::Reject(std::shared_ptr<ServiceBase> service, std::string reason) {
- auto p = service->GetPeer();
- int ret = cion_server_reject(cion_server_, p, reason.c_str());
- if (ret != CION_ERROR_NONE) {
- _E("Failed to cion_server_reject. error(%d)", ret);
- throw InvalidIOException();
- }
+ <SERVER_REJECT>
}
void ##::Disconnect(std::shared_ptr<ServiceBase> service) {
auto p = service->GetPeer();
- int ret = cion_server_disconnect(cion_server_, p);
- if (ret != CION_ERROR_NONE) {
- _E("Failed to cion_server_disconnect. error(%d)", ret);
- throw InvalidIOException();
- }
+ <SERVER_DISCONNECT>
}
void ##::SetDisplayName(std::string display_name) {
- int ret = cion_server_set_display_name(cion_server_, display_name.c_str());
- if (ret != CION_ERROR_NONE) {
- _E("Failed to cion_server_set_display_name. error(%d)", ret);
- InvalidIOException();
- }
+ <SERVER_SET_DISPLAY_NAME>
}
void ##::SetOndemandLaunchEnable(bool enabled) {
- int ret = cion_server_set_on_demand_launch_enabled(cion_server_, enabled);
- if (ret != CION_ERROR_NONE) {
- _E("Failed to cion_server_set_on_demand_launch_enabled. error(%d)", ret);
- switch(ret) {
- case CION_ERROR_PERMISSION_DENIED :
- throw UnauthorizedAccessException();
- break;
- default :
- throw InvalidIOException();
- }
- }
+ <SERVER_SET_ONDEMAND_LAUNCH_ENABLED>
}
void ##::OnConnectionResultCB(const char *service_name,
- const cion_peer_info_h peer_info, const cion_connection_result_h result,
+ const <PEER_INFO_T> peer_info, const cion_connection_result_h result,
void *user_data) {
}
void ##::OnDisconnectedCB(const char *service_name,
- const cion_peer_info_h peer_info, void *user_data) {
+ const <PEER_INFO_T> peer_info, void *user_data) {
##* stub = static_cast<##*>(user_data);
char* peer_app_id = nullptr;
- int ret = cion_peer_info_get_app_id(peer_info, &peer_app_id);
+ int ret = <PEER_INFO_GET_APPID1>
if (ret != CION_ERROR_NONE) {
_E("cion_peer_info_get_app_id() is failed. error(%d)", ret);
return;
auto perr_app_id_auto = std::unique_ptr<char, decltype(std::free)*>(peer_app_id, std::free);
char* peer_uuid = nullptr;
- ret = cion_peer_info_get_uuid(peer_info, &peer_uuid);
+ ret = <PEER_INFO_GET_UUID1>
if (ret != CION_ERROR_NONE) {
_E("cion_peer_info_get_uuid() is failed. error(%d)", ret);
return;
for (auto s = stub->services_.begin(); s != stub->services_.end(); s++) {
char* service_app_id = nullptr;
- ret = cion_peer_info_get_app_id(s->get()->GetPeer(), &service_app_id);
+ ret = <PEER_INFO_GET_APPID2>
if (ret != CION_ERROR_NONE) {
_E("cion_peer_info_get_app_id() is failed. error(%d)", ret);
return;
auto service_app_id_auto = std::unique_ptr<char, decltype(std::free)*>(service_app_id, std::free);
char* service_uuid = nullptr;;
- ret = cion_peer_info_get_uuid(s->get()->GetPeer(), &service_uuid);
+ ret = <PEER_INFO_GET_UUID2>
if (ret != CION_ERROR_NONE) {
_E("cion_peeer_info_get_uuid() is failed. error(%d)", ret);
return;
}
void ##::OnConnectionRequestCB(const char *service_name,
- const cion_peer_info_h peer_info, void *user_data) {
+ const <PEER_INFO_T> peer_info, void *user_data) {
##* stub = static_cast<##*>(user_data);
auto s = stub->service_factory_->CreateService(peer_info);
s->OnRequested(s);
)__cpp_cb";
const char CB_CTOR_SERVICE_BASE[] =
-R"__cpp_cb($$::ServiceBase::ServiceBase(cion_peer_info_h peer)
+R"__cpp_cb($$::ServiceBase::ServiceBase(<PEER_INFO_T> peer)
: active_object_(new ActiveObject()) {
- int ret = cion_peer_info_clone(peer, &peer_);
+ int ret = <PEER_INFO_CLONE>
if (ret != CION_ERROR_NONE) {
_E("Failed to cion_peer_info_clone. error(%d)", ret);
return;
const char CB_FILE_PAYLOAD_SEND[] = R"__cpp_cb(
-void $$::FilePayloadSend(std::string path, cion_peer_info_h peer)
+void $$::FilePayloadSend(std::string path, <PEER_INFO_T> peer)
{
- cion_payload_h pl;
- int ret = cion_payload_create(&pl, CION_PAYLOAD_TYPE_FILE);
- if (ret != CION_ERROR_NONE) {
- _E("Failed to cion_payload_create : %d", ret);
- return;
- }
-
- ret = cion_payload_set_file_path(pl, path.c_str());
- if (ret != CION_ERROR_NONE) {
- _E("Failed to cion_payload_set_file_path : %d - %s", ret, path.c_str());
- cion_payload_destroy(pl);
- return;
- }
-
- ret = cion_server_send_payload_async(cion_server_, peer, pl, nullptr, nullptr);
- if (ret != CION_ERROR_NONE) {
- _E("Failed to cion_server_send_payload_async : %d", ret);
- cion_payload_destroy(pl);
- return;
- }
-
- cion_payload_destroy(pl);
+ <FILE_PAYLOAD_SEND>
}
)__cpp_cb";
const char CB_CION_ON_PAYLOAD_RECEIVED_CB_FRONT[] =
R"__cpp_cb(
void $$::OnPayloadReceivedCB(const char *service_name,
- const cion_peer_info_h peer_info, const cion_payload_h payload,
- cion_payload_transfer_status_e status,
+ const <PEER_INFO_T> peer_info, const <PAYLOAD_T> payload,
+ <PAYLOAD_TRANSFER_STATUS_T> status,
void *user_data) {
$$* stub = static_cast<$$*>(user_data);
std::shared_ptr<ServiceBase> b;
rpc_port_parcel_h p;
char* peer_app_id = nullptr;
- int ret = cion_peer_info_get_app_id(peer_info, &peer_app_id);
+ int ret = <PEER_INFO_GET_APPID1>
if (ret != CION_ERROR_NONE) {
_E("cion_peer_info_get_app_id() is failed. error(%d)", ret);
return;
auto peer_app_id_auto = std::unique_ptr<char, decltype(std::free)*>(peer_app_id, std::free);
char* peer_uuid = nullptr;;
- ret = cion_peer_info_get_uuid(peer_info, &peer_uuid);
+ ret = <PEER_INFO_GET_UUID1>
if (ret != CION_ERROR_NONE) {
_E("cion_peer_info_get_uuid() is failed. error(%d)", ret);
return;
for (auto& s : stub->services_) {
char* service_app_id = nullptr;
- ret = cion_peer_info_get_app_id(s->GetPeer(), &service_app_id);
+ ret = <PEER_INFO_GET_APPID2>
if (ret != CION_ERROR_NONE) {
_E("cion_peer_info_get_app_id() is failed. error(%d)", ret);
return;
auto service_app_id_auto = std::unique_ptr<char, decltype(std::free)*>(service_app_id, std::free);
char* service_uuid = nullptr;
- ret = cion_peer_info_get_uuid(s->GetPeer(), &service_uuid);
+ ret = <PEER_INFO_GET_UUID2>
if (ret != CION_ERROR_NONE) {
_E("cion_peer_info_get_uuid() is failed. error(%d)", ret);
return;
return;
}
- cion_payload_type_e type;
- ret = cion_payload_get_type(payload, &type);
- if (ret != CION_ERROR_NONE) {
+ <PAYLOAD_TYPE_E> type;
+ <PAYLOAD_GET_TYPE>
+ if (ret != <ERROR_NONE>) {
_E("Failed to cion_payload_get_type. error(%d)", ret);
return;
}
- if (type == CION_PAYLOAD_TYPE_FILE) {
+ if (type == <PAYLOAD_TYPE_FILE>) {
b->OnFileReceived(peer_info, payload, status);
return;
}
unsigned char *data;
unsigned int size;
- ret = cion_payload_get_data(payload, &data, &size);
- if (ret != CION_ERROR_NONE) {
+ <PAYLOAD_GET_DATA>
+ if (ret != <ERROR_NONE>) {
_E("Failed to cion_payload_get_data. error(%d)", ret);
return;
}
const char CB_CION_ON_DATA_RECEIVED_CB_FRONT[] =
R"__cpp_cb(
void $$::OnDataReceivedCB(const char *service_name,
- const cion_peer_info_h peer_info, const unsigned char *data,
+ const <PEER_INFO_T> peer_info, const unsigned char *data,
unsigned int data_size, unsigned char **return_data,
unsigned int *return_data_size, void *user_data) {
$$* stub = static_cast<$$*>(user_data);
std::shared_ptr<ServiceBase> b;
rpc_port_parcel_h p;
char* peer_app_id = nullptr;
- int ret = cion_peer_info_get_app_id(peer_info, &peer_app_id);
+ int ret = <PEER_INFO_GET_APPID1>
if (ret != CION_ERROR_NONE) {
_E("cion_peer_info_get_app_id() is failed. error(%d)", ret);
return;
auto peer_app_id_auto = std::unique_ptr<char, decltype(std::free)*>(peer_app_id, std::free);
char* peer_uuid = nullptr;
- ret = cion_peer_info_get_uuid(peer_info, &peer_uuid);
+ ret = <PEER_INFO_GET_UUID1>
if (ret != CION_ERROR_NONE) {
_E("cion_peer_info_get_uuid() is failed. error(%d)", ret);
return;
for (auto& s : stub->services_) {
char* service_app_id = nullptr;
- ret = cion_peer_info_get_app_id(s->GetPeer(), &service_app_id);
+ ret = <PEER_INFO_GET_APPID2>
if (ret != CION_ERROR_NONE) {
_E("cion_peer_info_get_app_id() is failed. error(%d)", ret);
return;
auto service_app_id_auto = std::unique_ptr<char, decltype(std::free)*>(service_app_id, std::free);
char* service_uuid = nullptr;
- ret = cion_peer_info_get_uuid(s->GetPeer(), &service_uuid);
+ ret = <PEER_INFO_GET_UUID2>
if (ret != CION_ERROR_NONE) {
_E("cion_peer_info_get_uuid() is failed. error(%d)", ret);
return;
stream << " private:" << NLine(1);
GenMethodId(stream, iface);
GenDelegateId(stream, iface);
- stream << CB_PRIVATE_MEMBERS;
+ stream << ReplaceAll(CB_PRIVATE_MEMBERS, {
+ { "<PEER_INFO_T>", GetTransportable().Cpp().GenPeerInfoType() },
+ { "<PAYLOAD_T>", GetTransportable().Cpp().GenPayloadType() },
+ { "<SERVER_T>", GetTransportable().Cpp().GenServerType() },
+ { "<PAYLOAD_TRANSFER_STATUS_T>",
+ GetTransportable().Cpp().GenPayloadTransferStatusType() },
+ { "<SECURITY_T>", GetTransportable().Cpp().GenSecurityType() }
+ });
}
void CppCionStubHeaderGen::GenServiceBase(std::ofstream& stream,
const Interface& iface) {
- stream << CB_SERVICE_BASE_FRONT;
+ stream << ReplaceAll(CB_SERVICE_BASE_FRONT, {
+ { "<PEER_INFO_T>", GetTransportable().Cpp().GenPeerInfoType() },
+ { "<PAYLOAD_T>", GetTransportable().Cpp().GenPayloadType() },
+ { "<PAYLOAD_TRANSFER_STATUS_T>",
+ GetTransportable().Cpp().GenPayloadTransferStatusType() }
+ });
auto& decls = iface.GetDeclarations();
for (const auto& i : decls) {
stream << ") = 0;" << NLine(1);
}
- stream << CB_SERVICE_BASE_BACK << NLine(2);
+ stream << ReplaceAll(CB_SERVICE_BASE_BACK, "<PEER_INFO_T>",
+ GetTransportable().Cpp().GenPeerInfoType()) << NLine(2);
}
void CppCionStubHeaderGen::GenPublicMethods(std::ofstream& stream,
const char CB_PRIVATE_MEMBERS[] =
R"__cpp_cb(
- void FilePayloadSend(std::string path, cion_peer_info_h peer);
+ void FilePayloadSend(std::string path, <PEER_INFO_T> peer);
static void OnConnectionResultCB(const char *service_name,
- const cion_peer_info_h peer_info, const cion_connection_result_h result,
+ const <PEER_INFO_T> peer_info, const cion_connection_result_h result,
void *user_data);
static void OnDisconnectedCB(const char *service_name,
- const cion_peer_info_h peer_info, void *user_data);
+ const <PEER_INFO_T> peer_info, void *user_data);
static void OnConnectionRequestCB(const char *service_name,
- const cion_peer_info_h peer_info, void *user_data);
+ const <PEER_INFO_T> peer_info, void *user_data);
static void OnDataReceivedCB(const char *service_name,
- const cion_peer_info_h peer_info, const unsigned char *data,
+ const <PEER_INFO_T> peer_info, const unsigned char *data,
unsigned int data_size, unsigned char **return_data,
unsigned int *return_data_size, void *user_data);
static void OnPayloadReceivedCB(const char *service_name,
- const cion_peer_info_h peer_info, const cion_payload_h payload,
- cion_payload_transfer_status_e status,
+ const <PEER_INFO_T> peer_info, const <PAYLOAD_T> payload,
+ <PAYLOAD_TRANSFER_STATUS_T> status,
void *user_data);
std::shared_ptr<ServiceBase::Factory> service_factory_;
std::list<std::shared_ptr<ServiceBase>> services_;
- cion_security_h cion_security_ = nullptr;
- cion_server_h cion_server_ = nullptr;
+ <SECURITY_T> cion_security_ = nullptr;
+ <SERVER_T> cion_server_ = nullptr;
)__cpp_cb";
const char CB_SERVICE_BASE_FRONT[] =
/// The method for making service instances
/// </summary>
/// <param name="peer">The client peer info</param>
- virtual std::shared_ptr<ServiceBase> CreateService(cion_peer_info_h peer) = 0;
+ virtual std::shared_ptr<ServiceBase> CreateService(<PEER_INFO_T> peer) = 0;
};
virtual ~ServiceBase() = default;
/// <summary>
/// Gets peer info
/// </summary>
- const cion_peer_info_h GetPeer() const {
+ const <PEER_INFO_T> GetPeer() const {
return peer_;
}
/// <summary>
/// This method will be called when file receieved from client app
/// </summary>
- virtual void OnFileReceived(cion_peer_info_h peer_info,
- cion_payload_h file_payload, cion_payload_transfer_status_e status) = 0;
+ virtual void OnFileReceived(<PEER_INFO_T> peer_info,
+ <PAYLOAD_T> file_payload, <PAYLOAD_TRANSFER_STATUS_T> status) = 0;
/// <summary>
/// This method will be called when the client is connection requested
const char CB_SERVICE_BASE_BACK[] =
R"__cpp_cb(
protected:
- ServiceBase(cion_peer_info_h peer);
+ ServiceBase(<PEER_INFO_T> peer);
private:
- cion_peer_info_h peer_;
+ <PEER_INFO_T> peer_;
std::unique_ptr<ActiveObject> active_object_;
};)__cpp_cb";
std::string peer) const = 0;
virtual std::string GenClientFileSend(std::string path,
std::string client) const = 0;
+ virtual std::string GenGroupType() const = 0;
virtual std::string GenPayloadTransferStatusType() const = 0;
virtual std::string GenPeerInfoType() const = 0;
+ virtual std::string GenPeerInfoDestroy(std::string peer) const = 0;
virtual std::string GenPayloadType() const = 0;
virtual std::string GenClientType() const = 0;
virtual std::string GenSecurityType() const = 0;
virtual std::string GenServerAccept() const = 0;
virtual std::string GenServerReject() const = 0;
virtual std::string GenServerSetDisplayName() const = 0;
+ virtual std::string GenGroupPublish() const = 0;
+ virtual std::string GenPayloadTypeEnum() const = 0;
+ virtual std::string GenPayloadTypeData() const = 0;
+ virtual std::string GenPayloadTypeFile() const = 0;
+ virtual std::string GenPayloadGetType() const = 0;
+ virtual std::string GenErrorNone() const = 0;
+ virtual std::string GenPayloadGetData() const = 0;
+ virtual std::string GenClientCreate() const = 0;
+ virtual std::string GenGroupCreate() const = 0;
+ virtual std::string GenGroupDestroy() const = 0;
+ virtual std::string GenClientDestroy() const = 0;
+ virtual std::string GenSetSecurityCA(std::string arg) const = 0;
+ virtual std::string GenSetSecurityCert(std::string arg) const = 0;
+ virtual std::string GenSetSecurityPrivateKey(std::string arg) const = 0;
+ virtual std::string GenPeerInfoClone(std::string src_peer,
+ std::string dest_peer) const = 0;
+ virtual std::string GenServerSetOnDemandLaunchEnabled() const = 0;
+ virtual std::string GenServerListen() const = 0;
+ virtual std::string GenServerDisconnect(std::string server,
+ std::string peer) const = 0;
+ virtual std::string GenPeerInfoGetAppID(std::string peer,
+ std::string appid) const = 0;
+ virtual std::string GenPeerInfoGetUUID(std::string peer,
+ std::string uuid) const = 0;
};
} // namespace tidl
--- /dev/null
+/*
+ * Copyright (c) 2022 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 "idlc/gen_cion/default_cpp_transportable.h"
+
+#include <utility>
+
+#include "idlc/gen/replace_all.h"
+
+namespace {
+
+constexpr const char __CLINET_FILE_SEND[] =
+R"__cpp_cb(<PAYLOAD_T> pl;
+ int ret = cion_payload_create(&pl, CION_PAYLOAD_TYPE_FILE);
+ if (ret != CION_ERROR_NONE) {
+ _E("Failed to cion_payload_create : %d", ret);
+ return;
+ }
+
+ ret = cion_payload_set_file_path(pl, <FILE_PATH>.c_str());
+ if (ret != CION_ERROR_NONE) {
+ _E("Failed to cion_payload_set_file_path : %d - %s", ret, <FILE_PATH>.c_str());
+ cion_payload_destroy(pl);
+ return;
+ }
+
+ ret = cion_client_send_payload_async(<CLIENT_H>, pl, nullptr, nullptr);
+ if (ret != CION_ERROR_NONE) {
+ _E("Failed to cion_client_send_payload_async : %d", ret);
+ cion_payload_destroy(pl);
+ return;
+ }
+
+ cion_payload_destroy(pl);
+)__cpp_cb";
+
+constexpr const char __SERVER_FILE_SEND[] =
+R"__cpp_cb(<PAYLOAD_T> pl;
+ int ret = cion_payload_create(&pl, CION_PAYLOAD_TYPE_FILE);
+ if (ret != CION_ERROR_NONE) {
+ _E("Failed to cion_payload_create : %d", ret);
+ return;
+ }
+
+ ret = cion_payload_set_file_path(pl, <FILE_PATH>.c_str());
+ if (ret != CION_ERROR_NONE) {
+ _E("Failed to cion_payload_set_file_path : %d - %s", ret, <FILE_PATH>.c_str());
+ cion_payload_destroy(pl);
+ return;
+ }
+
+ ret = cion_server_send_payload_async(<SERVER_H>, <PEER_H>, pl, nullptr, nullptr);
+ if (ret != CION_ERROR_NONE) {
+ _E("Failed to cion_server_send_payload_async : %d", ret);
+ cion_payload_destroy(pl);
+ return;
+ }
+
+ cion_payload_destroy(pl);
+)__cpp_cb";
+
+constexpr const char __SERVER_REGISTER[] =
+R"__cpp_cb(<SECURITY_T> security;
+ int ret = cion_security_create(&security);
+ if (ret != CION_ERROR_NONE) {
+ _E("Failed to create security handle. error(%d)", ret);
+ throw InvalidIOException();
+ }
+
+ auto security_auto = std::unique_ptr<
+ std::remove_pointer<<SECURITY_T>>::type, decltype(cion_security_destroy)*>(
+ security, cion_security_destroy);
+<SET_SECURITY>
+ <SERVER_T> server;
+ ret = cion_server_create(&server, service_name.c_str(),
+ display_name.c_str(), security);
+ if (ret != CION_ERROR_NONE) {
+ _E("Failed to create handle. error(%d)", ret);
+ throw InvalidIOException();
+ }
+ auto server_auto = std::unique_ptr<
+ std::remove_pointer<<SERVER_T>>::type, decltype(cion_server_destroy)*>(
+ server, cion_server_destroy);
+
+ ret = cion_server_add_connection_result_cb(server, OnConnectionResultCB,
+ this);
+ if (ret != CION_ERROR_NONE) {
+ _E("Failed to cion_server_add_connection_result_cb. error(%d)", ret);
+ throw InvalidIOException();
+ }
+
+ ret = cion_server_add_payload_received_cb(server, OnPayloadReceivedCB,
+ this);
+ if (ret != CION_ERROR_NONE) {
+ _E("Failed to cion_server_add_payload_received_cb. error(%d)", ret);
+ throw InvalidIOException();
+ }
+
+ ret = cion_server_set_data_received_cb(server, OnDataReceivedCB, this);
+ if (ret != CION_ERROR_NONE) {
+ _E("Failed to cion_server_set_data_received_cb. error(%d)", ret);
+ throw InvalidIOException();
+ }
+
+ ret = cion_server_add_disconnected_cb(server, OnDisconnectedCB, this);
+ if (ret != CION_ERROR_NONE) {
+ _E("Failed to cion_server_add_disconnected_cb. error(%d)", ret);
+ throw InvalidIOException();
+ }
+
+ cion_security_ = security_auto.release();
+ cion_server_ = server_auto.release();
+)__cpp_cb";
+
+
+
+constexpr const char __SERVER_UNREGISTER[] =
+R"__cpp_cb(
+ if (cion_server_ != nullptr)
+ cion_server_destroy(cion_server_);
+
+ if (cion_security_ != nullptr)
+ cion_security_destroy(cion_security_);
+)__cpp_cb";
+
+constexpr const char __SERVER_ACCEPT[] =
+R"__cpp_cb(auto p = service->GetPeer();
+ int ret = cion_server_accept(cion_server_, p);
+ if (ret != CION_ERROR_NONE) {
+ _E("Failed to cion_server_accept. error(%d)", ret);
+ throw InvalidIOException();
+ }
+
+ service->OnCreate();
+ services_.emplace_back(std::move(service));
+)__cpp_cb";
+
+constexpr const char __SERVER_REJECT[] =
+R"__cpp_cb(auto p = service->GetPeer();
+ int ret = cion_server_reject(cion_server_, p, reason.c_str());
+ if (ret != CION_ERROR_NONE) {
+ _E("Failed to cion_server_reject. error(%d)", ret);
+ throw InvalidIOException();
+ }
+)__cpp_cb";
+
+constexpr const char __SERVER_SET_DISPLAY_NAME[] =
+R"__cpp_cb(int ret = cion_server_set_display_name(cion_server_, display_name.c_str());
+ if (ret != CION_ERROR_NONE) {
+ _E("Failed to cion_server_set_display_name. error(%d)", ret);
+ InvalidIOException();
+ }
+)__cpp_cb";
+
+constexpr const char __CLIENT_TRY_CONNECT[] =
+R"__cpp_cb(int ret = cion_client_connect(<CLIENT>, <PEER>);
+ if (ret != CION_ERROR_NONE) {
+ _E("Failed to connect to stub. error(%d)", ret);
+ switch(ret) {
+ case CION_ERROR_PERMISSION_DENIED :
+ throw UnauthorizedAccessException();
+ break;
+ case CION_ERROR_INVALID_PARAMETER :
+ throw NotConnectedSocketException();
+ break;
+ default :
+ throw InvalidIOException();
+ }
+ }
+)__cpp_cb";
+
+constexpr const char __CLIENT_DISCONNECT[] =
+R"__cpp_cb(int ret = cion_client_disconnect(<CLIENT>);
+ if (ret != CION_ERROR_NONE) {
+ _E("Failed to disconnect to stub. error(%d)", ret);
+ throw NotConnectedSocketException();
+ }
+)__cpp_cb";
+
+constexpr const char __CLIENT_TRY_DISCOVERY[] =
+R"__cpp_cb(int ret = cion_client_try_discovery(<CLIENT>, OnDiscoveredCB, this);
+ if (ret != CION_ERROR_NONE) {
+ _E("Failed to discovery to stub. error(%d)", ret);
+ switch(ret) {
+ case CION_ERROR_PERMISSION_DENIED :
+ throw UnauthorizedAccessException();
+ break;
+ default :
+ throw InvalidIOException();
+ }
+ }
+)__cpp_cb";
+
+constexpr const char __CLIENT_STOP_DISCOVERY[] =
+R"__cpp_cb(int ret = cion_client_stop_discovery(<CLIENT>);
+ if (ret != CION_ERROR_NONE) {
+ _E("Failed to stop discovery. error(%d)", ret);
+ return;
+ }
+)__cpp_cb";
+
+constexpr const char __CLIENT_SEND_ASYNC[] =
+R"__cpp_cb(
+ ret = cion_payload_create(&<PAYLOAD>, CION_PAYLOAD_TYPE_DATA);
+ if (ret != CION_ERROR_NONE) {
+ _E("Failed to cion_payload_create : %d", ret);
+ rpc_port_parcel_destroy(p);
+ throw InvalidIOException();
+ }
+
+ ret = cion_payload_set_data(<PAYLOAD>, (const unsigned char*)data, <SIZE>);
+ if (ret != CION_ERROR_NONE) {
+ _E("Failed to cion_payload_set_data : %d", ret);
+ rpc_port_parcel_destroy(p);
+ cion_payload_destroy(<PAYLOAD>);
+ throw InvalidIOException();
+ }
+
+ ret = cion_client_send_payload_async(<CLIENT>, <PAYLOAD>, nullptr, nullptr);
+ if (ret != CION_ERROR_NONE) {
+ _E("Failed to cion_client_send_payload_async : %d", ret);
+ rpc_port_parcel_destroy(p);
+ cion_payload_destroy(<PAYLOAD>);
+ throw InvalidIOException();
+ }
+
+ cion_payload_destroy(<PAYLOAD>);
+)__cpp_cb";
+
+constexpr const char __CLIENT_SEND[] =
+R"__cpp_cb(
+ ret = cion_client_send_data(<CLIENT>, (unsigned char *)<DATA>, <DATA_SIZE>,
+ 100, &<RET_DATA>, &<RET_DATA_SIZE>);
+ if (ret != RPC_PORT_ERROR_NONE) {
+ _E("Failed to cion_client_send_data : error(%d)", ret);
+ rpc_port_parcel_destroy(p);
+ throw InvalidIOException();
+ }
+)__cpp_cb";
+
+constexpr const char __SERVER_SEND_ASYNC[] =
+R"__cpp_cb(cion_ret_ = cion_payload_create(&<PAYLOAD>, CION_PAYLOAD_TYPE_DATA);
+ if (cion_ret_ != CION_ERROR_NONE) {
+ _E("Failed to cion_payload_create : %d", cion_ret_);
+ rpc_port_parcel_destroy(p);
+ return;
+ }
+
+ cion_ret_ = cion_payload_set_data(<PAYLOAD>, (const unsigned char*)data, <SIZE>);
+ if (cion_ret_ != CION_ERROR_NONE) {
+ _E("Failed to cion_payload_set_data : %d", cion_ret_);
+ rpc_port_parcel_destroy(p);
+ cion_payload_destroy(<PAYLOAD>);
+ return;
+ }
+
+ cion_ret_ = cion_server_send_payload_async(<SERVER>, service_.lock()->GetPeer(), <PAYLOAD>, nullptr, nullptr);
+ cion_payload_destroy(<PAYLOAD>);
+ if (cion_ret_ != CION_ERROR_NONE) {
+ _E("Failed to cion_client_send_payload_async : %d", cion_ret_);
+ rpc_port_parcel_destroy(p);
+ return;
+ }
+)__cpp_cb";
+
+constexpr const char __GROUP_PUBLISH[] =
+R"__c_cb(ret = cion_payload_create(&pl, CION_PAYLOAD_TYPE_DATA);
+ if (ret != CION_ERROR_NONE) {
+ _E("Failed to cion_payload_create : %d", ret);
+ rpc_port_parcel_destroy(p);
+ throw InvalidIOException();
+ }
+
+ ret = cion_payload_set_data(pl, (const unsigned char*)data, size);
+ if (ret != CION_ERROR_NONE) {
+ _E("Failed to cion_payload_set_data : %d", ret);
+ rpc_port_parcel_destroy(p);
+ cion_payload_destroy(pl);
+ throw InvalidIOException();
+ }
+
+ ret = cion_group_publish(cion_group_, pl);
+ cion_payload_destroy(pl);
+ if (ret != CION_ERROR_NONE) {
+ _E("Failed to cion_group_publish : %d", ret);
+ rpc_port_parcel_destroy(p);
+ throw InvalidIOException();
+ }
+)__c_cb";
+
+constexpr const char __CLIENT_CREATE[] =
+R"__c_cb(<SECURITY_T> security;
+ int ret = cion_security_create(&security);
+ if (ret != CION_ERROR_NONE) {
+ _E("Failed to create security handle. error(%d)", ret);
+ throw InvalidIOException();
+ }
+
+ auto security_auto = std::unique_ptr<
+ std::remove_pointer<<SECURITY_T>>::type, decltype(cion_security_destroy)*>(
+ security, cion_security_destroy);
+<SET_SECURITY>
+ <CLIENT_T> client = nullptr;
+ ret = cion_client_create(&client, service_name.c_str(), security);
+ if (ret != CION_ERROR_NONE) {
+ _E("Failed to create handle. error(%d)", ret);
+ throw InvalidIOException();
+ }
+ auto client_auto = std::unique_ptr<
+ std::remove_pointer<<CLIENT_T>>::type, decltype(cion_client_destroy)*>(
+ client, cion_client_destroy);
+
+ ret = cion_client_add_disconnected_cb(client, OnDisconnectedCB,
+ this);
+ if (ret != CION_ERROR_NONE) {
+ _E("Failed to cion_client_add_disconnected_cb. error(%d)", ret);
+ throw InvalidIOException();
+ }
+
+
+ ret = cion_client_add_connection_result_cb(client, OnConnectionResultCB,
+ this);
+ if (ret != CION_ERROR_NONE) {
+ _E("Failed to cion_client_add_connection_result_cb. error(%d)", ret);
+ throw InvalidIOException();
+ }
+
+ ret = cion_client_add_payload_received_cb(client, OnPayloadReceivedCB,
+ this);
+ if (ret != CION_ERROR_NONE) {
+ _E("Failed to cion_client_add_payload_received_cb. error(%d)", ret);
+ throw InvalidIOException();
+ }
+
+ cion_security_ = security_auto.release();
+ cion_client_ = client_auto.release();
+)__c_cb";
+
+constexpr const char __GROUP_CREATE[] =
+R"__c_cb(<SECURITY_T> security;
+ int ret = cion_security_create(&security);
+ if (ret != CION_ERROR_NONE) {
+ _E("Failed to create security handle. error(%d)", ret);
+ throw InvalidIOException();
+ }
+
+ auto security_auto = std::unique_ptr<
+ std::remove_pointer<<SECURITY_T>>::type, decltype(cion_security_destroy)*>(
+ security, cion_security_destroy);
+<SET_SECURITY>
+ <GROUP_T> group = nullptr;
+ ret = cion_group_create(&group, topic_name_.c_str(), security);
+ if (ret != CION_ERROR_NONE) {
+ _E("Failed to create handle. error(%d)", ret);
+ throw InvalidIOException();
+ }
+ auto group_auto = std::unique_ptr<
+ std::remove_pointer<<GROUP_T>>::type, decltype(cion_group_destroy)*>(
+ group, cion_group_destroy);
+
+ ret = cion_group_add_joined_cb(group,
+ [](const char *topic_name, const <PEER_INFO_T> peer_info,
+ void *user_data) {
+ <CLS_NAME> *gr = static_cast<<CLS_NAME>*>(user_data);
+ gr->OnJoined(peer_info);
+ },
+ this);
+ if (ret != CION_ERROR_NONE) {
+ _E("Failed to cion_group_add_joined_cb. error(%d)", ret);
+ throw InvalidIOException();
+ }
+
+ ret = cion_group_add_left_cb(group,
+ [](const char *topic_name, const <PEER_INFO_T> peer_info,
+ void *user_data) {
+ <CLS_NAME> *gr = static_cast<<CLS_NAME>*>(user_data);
+ gr->OnLeft(peer_info);
+ },
+ this);
+ if (ret != CION_ERROR_NONE) {
+ _E("Failed to cion_group_add_left_cb. error(%d)", ret);
+ throw InvalidIOException();
+ }
+
+ ret = cion_group_add_payload_received_cb(group,
+ [](const char *topic_name, const <PEER_INFO_T> peer_info,
+ const <PAYLOAD_T> payload, void *user_data) {
+ <CLS_NAME> *gr = static_cast<<CLS_NAME>*>(user_data);
+ gr->OnPayloadReceivedCB(peer_info, payload);
+ },
+ this);
+ if (ret != CION_ERROR_NONE) {
+ _E("Failed to cion_group_add_payload_received_cb. error(%d)", ret);
+ throw InvalidIOException();
+ }
+
+ ret = cion_group_subscribe(group);
+ if (ret != CION_ERROR_NONE) {
+ _E("Failed to subscribe. error(%d)", ret);
+ switch (ret) {
+ case CION_ERROR_PERMISSION_DENIED :
+ throw UnauthorizedAccessException();
+ break;
+ case CION_ERROR_INVALID_PARAMETER :
+ throw NotConnectedSocketException();
+ break;
+ default :
+ throw InvalidIOException();
+ }
+ }
+
+ cion_security_ = security_auto.release();
+ cion_group_ = group_auto.release();
+)__c_cb";
+
+constexpr const char __GROUP_DESTROY[] =
+R"__c_cb(if (cion_group_ != nullptr) {
+ int ret = cion_group_unsubscribe(cion_group_);
+ if (ret != CION_ERROR_NONE)
+ _E("Failed to unsubscribe. error(%d)", ret);
+ cion_group_destroy(cion_group_);
+ }
+
+ if (cion_security_ != nullptr)
+ cion_security_destroy(cion_security_);
+)__c_cb";
+
+constexpr const char __CLIENT_DESTROY[] =
+R"__c_cb(
+ if (cion_client_ != nullptr)
+ cion_client_destroy(cion_client_);
+
+ if (cion_security_ != nullptr)
+ cion_security_destroy(cion_security_);
+)__c_cb";
+
+const char __SET_SECURITY_CA[] =
+R"__cpp_cb(
+ if (cion_security_set_ca_path(security, "<ARG>") != CION_ERROR_NONE) {
+ _E("Failed to set ca path.");
+ throw InvalidIOException();
+ }
+)__cpp_cb";
+
+const char __SET_SECURITY_CERT[] =
+R"__cpp_cb(
+ if (cion_security_set_cert_path(security, "<ARG>") != CION_ERROR_NONE) {
+ _E("Failed to set cert path.");
+ throw InvalidIOException();
+ }
+)__cpp_cb";
+
+const char __SET_SECURITY_PRIVATE_KEY[] =
+R"__cpp_cb(
+ if (cion_security_set_private_key_path(security, "<ARG>") != CION_ERROR_NONE) {
+ _E("Failed to set private key path.");
+ throw InvalidIOException();
+ }
+)__cpp_cb";
+
+const char __PEER_INFO_CLONE[] =
+ "cion_peer_info_clone(<SRC_PEER>, <DEST_PEER>);";
+
+constexpr const char __SERVER_SET_ONDEMAND_LAUNCH_ENABLED[] =
+R"__c_cb(int ret = cion_server_set_on_demand_launch_enabled(cion_server_, enabled);
+ if (ret != CION_ERROR_NONE) {
+ _E("Failed to cion_server_set_on_demand_launch_enabled. error(%d)", ret);
+ switch(ret) {
+ case CION_ERROR_PERMISSION_DENIED :
+ throw UnauthorizedAccessException();
+ break;
+ default :
+ throw InvalidIOException();
+ }
+ }
+)__c_cb";
+
+constexpr const char __SERVER_LISTEN[] =
+R"__c_cb(int ret = cion_server_listen(cion_server_, OnConnectionRequestCB, this);
+ if (ret != CION_ERROR_NONE) {
+ _E("Failed to cion_server_listen. error(%d)", ret);
+ switch(ret) {
+ case CION_ERROR_PERMISSION_DENIED :
+ throw UnauthorizedAccessException();
+ break;
+ default :
+ throw InvalidIOException();
+ }
+ }
+)__c_cb";
+
+constexpr const char __SERVER_DISCONNECT[] =
+R"__c_cb(int ret = cion_server_disconnect(<SERVER>, <PEER>);
+ if (ret != CION_ERROR_NONE) {
+ _E("Failed to cion_server_disconnect. error(%d)", ret);
+ throw InvalidIOException();
+ }
+)__c_cb";
+
+constexpr const char __PEER_INFO_GET_APPID[] =
+ "cion_peer_info_get_app_id(<PEER>, <APPID>);";
+
+constexpr const char __PEER_INFO_GET_UUID[] =
+ "cion_peer_info_get_uuid(<PEER>, <UUID>);";
+
+} // namespace
+
+namespace tidl {
+
+std::string DefaultCppTransportable::GenInclude() const {
+ return "#include <cion.h>";
+}
+
+std::string DefaultCppTransportable::GenClientSendAsync(std::string client,
+ std::string payload, std::string size) const {
+ return std::string(ReplaceAll(__CLIENT_SEND_ASYNC, {
+ { "<CLIENT>", client },
+ { "<PAYLOAD>", payload},
+ { "<SIZE>", size} }));
+}
+
+std::string DefaultCppTransportable::GenClientSend(std::string client,
+ std::string data, std::string data_size,
+ std::string ret_data, std::string ret_data_size) const {
+ return std::string(ReplaceAll(__CLIENT_SEND, {
+ { "<CLIENT>", client },
+ { "<DATA>", data},
+ { "<DATA_SIZE>", data_size},
+ { "<RET_DATA>", ret_data},
+ { "<RET_DATA_SIZE>", ret_data_size} }));
+}
+
+std::string DefaultCppTransportable::GenServerSendAsync(std::string server,
+ std::string client,
+ std::string payload, std::string size) const {
+ return std::string(ReplaceAll(__SERVER_SEND_ASYNC, {
+ { "<SERVER>", server },
+ { "<CLIENT>", client},
+ { "<PAYLOAD>", payload},
+ { "<SIZE>", size} }));
+}
+
+std::string DefaultCppTransportable::GenServerFileSend(std::string path,
+ std::string server, std::string peer) const {
+ return std::string(ReplaceAll(__SERVER_FILE_SEND, {
+ { "<FILE_PATH>", path },
+ { "<SERVER_H>", server },
+ { "<PEER_H>", peer } }));
+}
+
+std::string DefaultCppTransportable::GenClientFileSend(std::string path,
+ std::string client) const {
+ return std::string(ReplaceAll(__CLINET_FILE_SEND, {
+ { "<FILE_PATH>", path },
+ { "<CLIENT_H>", client } }));
+}
+
+std::string DefaultCppTransportable::GenGroupType() const {
+ return "cion_group_h";
+}
+
+std::string DefaultCppTransportable::GenPayloadTransferStatusType() const {
+ return "cion_payload_transfer_status_e";
+}
+
+std::string DefaultCppTransportable::GenPeerInfoType() const {
+ return "cion_peer_info_h";
+}
+
+std::string DefaultCppTransportable::GenPeerInfoDestroy(
+ std::string peer) const {
+ return std::string(ReplaceAll("cion_peer_info_destroy(<PEER>);", {
+ { "<PEER>", peer } }));
+}
+
+std::string DefaultCppTransportable::GenPayloadType() const {
+ return "cion_payload_h";
+}
+
+std::string DefaultCppTransportable::GenClientType() const {
+ return "cion_client_h";
+}
+
+std::string DefaultCppTransportable::GenSecurityType() const {
+ return "cion_security_h";
+}
+
+std::string DefaultCppTransportable::GenServerType() const {
+ return "cion_server_h";
+}
+
+std::string DefaultCppTransportable::GenClientTryConnect(std::string client,
+ std::string peer) const {
+ return std::string(ReplaceAll(__CLIENT_TRY_CONNECT, {
+ { "<CLIENT>", client },
+ { "<PEER>", peer } }));
+}
+
+std::string DefaultCppTransportable::GenClientDisconnect(
+ std::string client) const {
+ return std::string(ReplaceAll(__CLIENT_DISCONNECT, {
+ { "<CLIENT>", client } }));
+}
+
+std::string DefaultCppTransportable::GenClientTryDiscovery(
+ std::string client) const {
+ return std::string(ReplaceAll(__CLIENT_TRY_DISCOVERY, {
+ { "<CLIENT>", client } }));
+}
+
+std::string DefaultCppTransportable::GenClientStopDiscovery(
+ std::string client) const {
+ return std::string(ReplaceAll(__CLIENT_STOP_DISCOVERY, {
+ { "<CLIENT>", client } }));
+}
+
+std::string DefaultCppTransportable::GenServerRegister() const {
+ return __SERVER_REGISTER;
+}
+
+std::string DefaultCppTransportable::GenServerUnregister() const {
+ return __SERVER_UNREGISTER;
+}
+
+std::string DefaultCppTransportable::GenClientExtraHeader() const {
+ return "";
+}
+
+std::string DefaultCppTransportable::GenClientExtraBody() const {
+ return "";
+}
+
+std::string DefaultCppTransportable::GenServerExtraHeader() const {
+ return "";
+}
+
+std::string DefaultCppTransportable::GenServerExtraBody() const {
+ return "";
+}
+
+std::string DefaultCppTransportable::GenServerAccept() const {
+ return __SERVER_ACCEPT;
+}
+
+std::string DefaultCppTransportable::GenServerReject() const {
+ return __SERVER_REJECT;
+}
+
+std::string DefaultCppTransportable::GenServerSetDisplayName() const {
+ return __SERVER_SET_DISPLAY_NAME;
+}
+
+std::string DefaultCppTransportable::GenGroupPublish() const {
+ return __GROUP_PUBLISH;
+}
+
+std::string DefaultCppTransportable::GenPayloadTypeEnum() const {
+ return "cion_payload_type_e";
+}
+
+std::string DefaultCppTransportable::GenPayloadTypeData() const {
+ return "CION_PAYLOAD_TYPE_DATA";
+}
+
+std::string DefaultCppTransportable::GenPayloadTypeFile() const {
+ return "CION_PAYLOAD_TYPE_FILE";
+}
+
+std::string DefaultCppTransportable::GenPayloadGetType() const {
+ return "ret = cion_payload_get_type(payload, &type);";
+}
+
+std::string DefaultCppTransportable::GenErrorNone() const {
+ return "CION_ERROR_NONE";
+}
+
+std::string DefaultCppTransportable::GenPayloadGetData() const {
+ return "ret = cion_payload_get_data(payload, &data, &size);";
+}
+
+std::string DefaultCppTransportable::GenClientCreate() const {
+ return __CLIENT_CREATE;
+}
+
+std::string DefaultCppTransportable::GenGroupCreate() const {
+ return __GROUP_CREATE;
+}
+
+std::string DefaultCppTransportable::GenGroupDestroy() const {
+ return __GROUP_DESTROY;
+}
+
+std::string DefaultCppTransportable::GenClientDestroy() const {
+ return __CLIENT_DESTROY;
+}
+
+std::string DefaultCppTransportable::GenSetSecurityCA(std::string arg) const {
+ return std::string(ReplaceAll(__SET_SECURITY_CA, {
+ { "<ARG>", arg } }));
+}
+
+std::string DefaultCppTransportable::GenSetSecurityCert(std::string arg) const {
+ return std::string(ReplaceAll(__SET_SECURITY_CERT, {
+ { "<ARG>", arg } }));
+}
+
+std::string DefaultCppTransportable::GenSetSecurityPrivateKey(
+ std::string arg) const {
+ return std::string(ReplaceAll(__SET_SECURITY_PRIVATE_KEY, {
+ { "<ARG>", arg } }));
+}
+
+std::string DefaultCppTransportable::GenPeerInfoClone(std::string src_peer,
+ std::string dest_peer) const {
+ return std::string(ReplaceAll(__PEER_INFO_CLONE, {
+ { "<SRC_PEER>", src_peer },
+ { "<DEST_PEER>", dest_peer } }));
+}
+
+std::string DefaultCppTransportable::GenServerSetOnDemandLaunchEnabled() const {
+ return __SERVER_SET_ONDEMAND_LAUNCH_ENABLED;
+}
+
+std::string DefaultCppTransportable::GenServerListen() const {
+ return __SERVER_LISTEN;
+}
+
+std::string DefaultCppTransportable::GenServerDisconnect(std::string server,
+ std::string peer) const {
+ return std::string(ReplaceAll(__SERVER_DISCONNECT, {
+ { "<SERVER>", server },
+ { "<PEER>", peer } }));
+}
+
+std::string DefaultCppTransportable::GenPeerInfoGetAppID(std::string peer,
+ std::string appid) const {
+ return std::string(ReplaceAll(__PEER_INFO_GET_APPID, {
+ { "<PEER>", peer},
+ { "<APPID>", appid} }));
+}
+
+std::string DefaultCppTransportable::GenPeerInfoGetUUID(std::string peer,
+ std::string uuid) const {
+ return std::string(ReplaceAll(__PEER_INFO_GET_UUID, {
+ { "<PEER>", peer},
+ { "<UUID>", uuid} }));
+}
+
+} // namespace tidl
--- /dev/null
+/*
+ * Copyright (c) 2022 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 IDLC_GEN_CION_DEFAULT_CPP_TRANSPORTABLE_H_
+#define IDLC_GEN_CION_DEFAULT_CPP_TRANSPORTABLE_H_
+
+#include <string>
+
+#include "idlc/gen_cion/cpp_transportable.h"
+
+namespace tidl {
+
+class DefaultCppTransportable : public CppTransportable {
+ public:
+ virtual ~DefaultCppTransportable() = default;
+ std::string GenInclude() const override;
+ std::string GenClientSendAsync(std::string client,
+ std::string payload, std::string size) const override;
+ std::string GenClientSend(std::string client, std::string data,
+ std::string data_size, std::string ret_data,
+ std::string ret_data_size) const override;
+ std::string GenServerSendAsync(std::string server, std::string client,
+ std::string payload, std::string size) const override;
+ std::string GenServerFileSend(std::string path,
+ std::string server, std::string peer) const override;
+ std::string GenClientFileSend(std::string path,
+ std::string client) const override;
+ std::string GenGroupType() const override;
+ std::string GenPayloadTransferStatusType() const override;
+ std::string GenPeerInfoType() const override;
+ std::string GenPeerInfoDestroy(std::string peer) const override;
+ std::string GenPayloadType() const override;
+ std::string GenClientType() const override;
+ std::string GenSecurityType() const override;
+ std::string GenServerType() const override;
+ std::string GenClientTryConnect(std::string client,
+ std::string peer) const override;
+ std::string GenClientDisconnect(std::string client) const override;
+ std::string GenClientTryDiscovery(std::string client) const override;
+ std::string GenClientStopDiscovery(std::string client) const override;
+ std::string GenServerRegister() const override;
+ std::string GenServerUnregister() const override;
+ std::string GenClientExtraHeader() const override;
+ std::string GenClientExtraBody() const override;
+ std::string GenServerExtraHeader() const override;
+ std::string GenServerExtraBody() const override;
+ std::string GenServerAccept() const override;
+ std::string GenServerReject() const override;
+ std::string GenServerSetDisplayName() const override;
+ std::string GenGroupPublish() const override;
+ std::string GenPayloadTypeEnum() const override;
+ std::string GenPayloadTypeData() const override;
+ std::string GenPayloadTypeFile() const override;
+ std::string GenPayloadGetType() const override;
+ std::string GenErrorNone() const override;
+ std::string GenPayloadGetData() const override;
+ std::string GenClientCreate() const override;
+ std::string GenGroupCreate() const override;
+ std::string GenGroupDestroy() const override;
+ std::string GenClientDestroy() const override;
+ std::string GenSetSecurityCA(std::string arg) const override;
+ std::string GenSetSecurityCert(std::string arg) const override;
+ std::string GenSetSecurityPrivateKey(std::string arg) const override;
+ std::string GenPeerInfoClone(std::string src_peer,
+ std::string dest_peer) const override;
+ std::string GenServerSetOnDemandLaunchEnabled() const override;
+ std::string GenServerListen() const override;
+ std::string GenServerDisconnect(std::string server,
+ std::string peer) const override;
+ std::string GenPeerInfoGetAppID(std::string peer,
+ std::string appid) const override;
+ std::string GenPeerInfoGetUUID(std::string peer,
+ std::string uuid) const override;
+};
+
+} // namespace tidl
+
+#endif // IDLC_GEN_CION_DEFAULT_CPP_TRANSPORTABLE_H_
#include "idlc/gen_cion/plugin_loader.h"
#include "idlc/gen_cion/default_c_transportable.h"
+#include "idlc/gen_cion/default_cpp_transportable.h"
namespace tidl {
PluginLoader::PluginLoader(const std::string& plugin_path) {
if (plugin_path.empty()) {
C_.reset(new DefaultCTransportable());
- // Cpp_.reset(new DefaultCppTransportable());
+ Cpp_.reset(new DefaultCppTransportable());
// Cs_.reset(new DefaultCsTransportable());
// Java_.reset(new DefaultJavaTransportable());
} else {