+/*
+ * Copyright (c) 2018 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.
+ */
+
const char CB_BUNDLE[] = R"__cls_bundle(class Bundle final {
public:
Bundle() {
return h;
}
-)__cpp_cb";
\ No newline at end of file
+)__cpp_cb";
+/*
+ * Copyright (c) 2018 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.
+ */
+
const char CB_PROXY_HELPER_METHODS[] =
R"__cpp_cb(
int $$::Connect() {
#include "idlc/cpp_gen/cpp_proxy_header_gen.h"
+namespace {
+#include "cpp_proxy_header_gen_cb.h"
+}
+
namespace tidl {
CppProxyHeaderGen::CppProxyHeaderGen(std::shared_ptr<Document> doc)
}
void CppProxyHeaderGen::GenExceptions(std::ofstream& stream) {
- const char cb[] =
-R"__cpp_cb(
-class Exception {};
-class NotConnectedSocketException : public Exception {};
-class InvalidProtocolException : public Exception {};
-)__cpp_cb";
- stream << cb << NLine(1);
+ stream << CB_EXCEPTIONS << NLine(1);
}
void CppProxyHeaderGen::GenInterfaces(std::ofstream& stream) {
void CppProxyHeaderGen::GenInterface(std::ofstream& stream,
const Interface& iface) {
- const char* pub =
- "class IEventListener {\n" \
- " public:\n" \
- " virtual void OnConnected() = 0;\n" \
- " virtual void OnDisconnected() = 0;\n" \
- " virtual void OnRejected() = 0;\n" \
- "};\n"
- "\n" \
- "$$(IEventListener* listener, const std::string& target_appid);\n" \
- "virtual ~$$();\n" \
- "\n" \
- "int Connect();\n";
-
- const char* priv =
- "static void OnConnectedCB(const char *ep, const char *port_name,\n" \
- " rpc_port_h port, void *data);\n" \
- "static void OnDisconnectedCB(const char *ep, const char *port_name,\n" \
- " void *data);\n" \
- "static void OnRejectedCB(const char *ep, const char *port_name, void *data);\n" \
- "static void OnReceivedCB(const char *ep, const char *port_name, void *data);\n" \
- "\n" \
- "rpc_port_h port_;\n" \
- "rpc_port_proxy_h proxy_;\n" \
- "IEventListener* listener_;\n" \
- "std::recursive_mutex mutex_;\n" \
- "std::list<std::unique_ptr<CallbackBase>> delegate_list_;\n" \
- "std::string target_appid_;\n";
-
stream << NLine(1) << "class " << iface.GetID() << " ";
GenBrace(stream, 0, [&]() {
stream << " public:" << NLine(1);
GenHeaderCallbacks(stream, iface, true);
- GenTemplate(AddIndent(TAB_SIZE, pub), stream,
+ GenTemplate(CB_PUBLIC_MEMBERS, stream,
[&]()->std::string {
return iface.GetID();
},
stream << NLine(1) << " private:" << NLine(1);
GenMethodId(stream, iface);
GenDelegateId(stream, iface);
- GenHelperMethods(stream);
- stream << AddIndent(TAB_SIZE, priv);
+ stream << CB_PRIVATE_MEMBERS;
}, false, false);
stream << ";" << NLine(1);
}
-void CppProxyHeaderGen::GenHelperMethods(std::ofstream& stream) {
- const char* func =
- "void ProcessReceivedEvent(rpc_port_parcel_h parcel);\n" \
- "void ConsumeCommand(rpc_port_parcel_h* parcel, rpc_port_h port);\n";
- stream << AddIndent(TAB_SIZE, func) << NLine(1);
-}
-
void CppProxyHeaderGen::GenMethods(std::ofstream& stream,
const Interface& iface) {
auto& decls = iface.GetDeclarations();
void GenInterface(std::ofstream& stream, const Interface& iface);
void GenMethods(std::ofstream& stream, const Interface& iface);
void GenDeclaration(std::ofstream& stream, const Declaration& decl);
- void GenHelperMethods(std::ofstream& stream);
};
} // namespace tidl
--- /dev/null
+/*
+ * Copyright (c) 2018 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.
+ */
+
+const char CB_EXCEPTIONS[] =
+R"__cpp_cb(
+class Exception {};
+class NotConnectedSocketException : public Exception {};
+class InvalidProtocolException : public Exception {};
+)__cpp_cb";
+
+const char CB_PUBLIC_MEMBERS[] =
+R"__cpp_cb( class IEventListener {
+ public:
+ virtual void OnConnected() = 0;
+ virtual void OnDisconnected() = 0;
+ virtual void OnRejected() = 0;
+ };
+
+ $$(IEventListener* listener, const std::string& target_appid);
+ virtual ~$$();
+
+ int Connect();
+)__cpp_cb";
+
+const char CB_PRIVATE_MEMBERS[] =
+R"__cpp_cb( void ProcessReceivedEvent(rpc_port_parcel_h parcel);
+ void ConsumeCommand(rpc_port_parcel_h* parcel, rpc_port_h port);
+
+ static void OnConnectedCB(const char *ep, const char *port_name,
+ rpc_port_h port, void *data);
+ static void OnDisconnectedCB(const char *ep, const char *port_name,
+ void *data);
+ static void OnRejectedCB(const char *ep, const char *port_name, void *data);
+ static void OnReceivedCB(const char *ep, const char *port_name, void *data);
+
+ rpc_port_h port_;
+ rpc_port_proxy_h proxy_;
+ IEventListener* listener_;
+ std::recursive_mutex mutex_;
+ std::list<std::unique_ptr<CallbackBase>> delegate_list_;
+ std::string target_appid_;
+)__cpp_cb";
#include "idlc/cpp_gen/cpp_stub_body_gen.h"
+namespace {
+#include "cpp_stub_body_gen_cb.h"
+}
+
namespace tidl {
CppStubBodyGen::CppStubBodyGen(std::shared_ptr<Document> doc)
void CppStubBodyGen::GenServiceBase(std::ofstream& stream,
const Interface& iface) {
- const char cb[] =
- "$$::ServiceBase::ServiceBase(std::string sender, std::string instance)\n" \
- " : sender_(std::move(sender)), instance_(std::move(instance)) {}\n" \
- "\n";
-
- GenTemplate(cb, stream,
+ GenTemplate(CB_CTOR_SERVICE_BASE, stream,
[&]()->std::string {
return iface.GetID();
}
void CppStubBodyGen::GenConstructor(std::ofstream& stream,
const Interface& iface) {
- const char cb[] =
-R"__cpp_cb(
-$$::$$() {
- rpc_port_stub_create(&stub_, "$$");
- rpc_port_stub_add_connected_event_cb(stub_, OnConnectedCB, this);
- rpc_port_stub_add_disconnected_event_cb(stub_, OnDisconnectedCB, this);
- rpc_port_stub_add_received_event_cb(stub_, OnReceivedCB, this);
-)__cpp_cb";
-
- GenTemplate(cb, stream,
+ GenTemplate(CB_CTOR_FRONT, stream,
[&]()->std::string { return iface.GetID(); },
[&]()->std::string { return iface.GetID(); },
[&]()->std::string { return iface.GetID(); }
void CppStubBodyGen::GenDefaultMethods(std::ofstream& stream,
const Interface& iface) {
- const char cb[] =
-R"__cpp_cb(
-$$::~$$() {
- if (stub_) {
- rpc_port_stub_destroy(stub_);
- }
-}
-
-void $$::Listen(
- std::shared_ptr<$$::ServiceBase::Factory> service_factory) {
- service_factory_ = std::move(service_factory);
- rpc_port_stub_listen(stub_);
-}
-
-void $$::OnConnectedCB(const char* sender, const char* instance, void *data) {
- $$* stub = static_cast<$$*>(data);
- auto s = stub->service_factory_->CreateService(sender, instance);
- s->OnCreate();
- stub->services_.emplace_back(std::move(s));
-}
-
-void $$::OnDisconnectedCB(const char* sender, const char* instance, void *data) {
- $$* stub = static_cast<$$*>(data);
-
- for (auto& i : stub->services_) {
- if (i->GetInstance() == instance) {
- i->OnTerminate();
- stub->services_.remove(i);
- return;
- }
- }
-}
-)__cpp_cb";
-
GenConstructor(stream, iface);
- GenTemplate(cb, stream,
+ GenTemplate(CB_DEFAULT_METHODS, stream,
[&]()->std::string { return iface.GetID(); },
[&]()->std::string { return iface.GetID(); },
[&]()->std::string { return iface.GetID(); },
void CppStubBodyGen::GenReceivedEvent(std::ofstream& stream,
const Interface& iface) {
- const char method_front[] =
- "int $$::OnReceivedCB(const char* sender, const char* instance, rpc_port_h port, void *data)\n" \
- "{\n" \
- " auto* cxt = static_cast<$$*>(data);"
- " rpc_port_parcel_h p;\n" \
- " rpc_port_parcel_h result;\n" \
- " int cmd;\n" \
- " int ret = rpc_port_parcel_create_from_port(&p, port);\n" \
- "\n" \
- " if (ret != 0)\n" \
- " return ret;\n" \
- "\n" \
- " rpc_port_parcel_create(&result);\n" \
- " rpc_port_parcel_read_int32(p, &cmd);\n" \
- " std::shared_ptr<ServiceBase> b;\n" \
- "\n" \
- " for (auto& i : cxt->services_) {\n" \
- " if (i->GetInstance() == instance) {\n" \
- " b = i;\n" \
- " break;\n" \
- " }\n" \
- " }\n" \
- "\n" \
- " if (b.get() == nullptr)\n" \
- " return -1;\n" \
- "\n"
- " switch (cmd) {\n";
-
- const char method_back[] =
- " default:\n" \
- " return -1;\n" \
- " }\n" \
- "\n" \
- " rpc_port_parcel_destroy(p);\n" \
- " rpc_port_parcel_destroy(result);\n" \
- "\n" \
- " return 0;\n" \
- "}\n";
-
- GenTemplate(method_front, stream,
+ GenTemplate(CB_ON_RECEIVED_CB_FRONT, stream,
[&]()->std::string {
return iface.GetID();
},
}, false);
stream << NLine(1);
}
- stream << method_back << NLine(1);
+ stream << CB_ON_RECEIVED_CB_BACK << NLine(1);
}
void CppStubBodyGen::GenInvocation(std::ofstream& stream, const Declaration& decl) {
--- /dev/null
+/*
+ * Copyright (c) 2018 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.
+ */
+
+const char CB_CTOR_FRONT[] =
+R"__cpp_cb(
+$$::$$() {
+ rpc_port_stub_create(&stub_, "$$");
+ rpc_port_stub_add_connected_event_cb(stub_, OnConnectedCB, this);
+ rpc_port_stub_add_disconnected_event_cb(stub_, OnDisconnectedCB, this);
+ rpc_port_stub_add_received_event_cb(stub_, OnReceivedCB, this);
+)__cpp_cb";
+
+const char CB_DEFAULT_METHODS[] =
+R"__cpp_cb(
+$$::~$$() {
+ if (stub_) {
+ rpc_port_stub_destroy(stub_);
+ }
+}
+
+void $$::Listen(
+ std::shared_ptr<$$::ServiceBase::Factory> service_factory) {
+ service_factory_ = std::move(service_factory);
+ rpc_port_stub_listen(stub_);
+}
+
+void $$::OnConnectedCB(const char* sender, const char* instance, void *data) {
+ $$* stub = static_cast<$$*>(data);
+ auto s = stub->service_factory_->CreateService(sender, instance);
+ s->OnCreate();
+ stub->services_.emplace_back(std::move(s));
+}
+
+void $$::OnDisconnectedCB(const char* sender, const char* instance, void *data) {
+ $$* stub = static_cast<$$*>(data);
+
+ for (auto& i : stub->services_) {
+ if (i->GetInstance() == instance) {
+ i->OnTerminate();
+ stub->services_.remove(i);
+ return;
+ }
+ }
+}
+)__cpp_cb";
+
+const char CB_ON_RECEIVED_CB_FRONT[] =
+R"__cpp_cb(int $$::OnReceivedCB(const char* sender, const char* instance, rpc_port_h port, void *data)
+{
+ auto* cxt = static_cast<$$*>(data);
+ rpc_port_parcel_h p;
+ rpc_port_parcel_h result;
+ int cmd;
+ int ret = rpc_port_parcel_create_from_port(&p, port);
+
+ if (ret != 0)
+ return ret;
+
+ rpc_port_parcel_create(&result);
+ rpc_port_parcel_read_int32(p, &cmd);
+ std::shared_ptr<ServiceBase> b;
+
+ for (auto& i : cxt->services_) {
+ if (i->GetInstance() == instance) {
+ b = i;
+ break;
+ }
+ }
+
+ if (b.get() == nullptr)
+ return -1;
+
+ switch (cmd) {
+)__cpp_cb";
+
+const char CB_ON_RECEIVED_CB_BACK[] =
+R"__cpp_cb( default:
+ return -1;
+ }
+
+ rpc_port_parcel_destroy(p);
+ rpc_port_parcel_destroy(result);
+
+ return 0;
+}
+)__cpp_cb";
+
+const char CB_CTOR_SERVICE_BASE[] =
+R"__cpp_cb($$::ServiceBase::ServiceBase(std::string sender, std::string instance)
+ : sender_(std::move(sender)), instance_(std::move(instance)) {})__cpp_cb";
#include "idlc/cpp_gen/cpp_stub_header_gen.h"
+namespace {
+#include "cpp_stub_header_gen_cb.h"
+}
+
namespace tidl {
CppStubHeaderGen::CppStubHeaderGen(std::shared_ptr<Document> doc)
}
void CppStubHeaderGen::GenExceptions(std::ofstream& stream) {
- const char cb[] =
-R"__cpp_cb(
-class Exception {};
-class NotConnectedSocketException : public Exception {};
-class InvalidProtocolException : public Exception {};
-)__cpp_cb";
- stream << cb << NLine(1);
+ stream << CB_EXCEPTIONS << NLine(1);
}
void CppStubHeaderGen::GenInterfaces(std::ofstream& stream) {
stream << " private:" << NLine(1);
GenMethodId(stream, iface);
GenDelegateId(stream, iface);
-
- const char cb[] =
- "static void OnConnectedCB(const char* sender, const char* instance, void* data);\n" \
- "static void OnDisconnectedCB(const char* sender, const char* instance, void* data);\n" \
- "static int OnReceivedCB(const char* sender, const char* instance, rpc_port_h port, void* data);\n" \
- "\n" \
- "rpc_port_stub_h stub_;\n" \
- "std::shared_ptr<ServiceBase::Factory> service_factory_;\n" \
- "std::list<std::shared_ptr<ServiceBase>> services_;\n";
-
- stream << AddIndent(TAB_SIZE, cb);
+ stream << CB_PRIVATE_MEMBERS;
}
void CppStubHeaderGen::GenServiceBase(std::ofstream& stream,
const Interface& iface) {
- const char cb1[] = R"__cpp_cb( class ServiceBase {
- public:
- class Factory {
- public:
- virtual std::unique_ptr<ServiceBase> CreateService(std::string sender, std::string instance) = 0;
- };
-
- virtual ~ServiceBase() = default;
-
- const std::string& GetSender() const {
- return sender_;
- }
-
- const std::string& GetInstance() const {
- return instance_;
- }
-
- virtual void OnCreate() = 0;
- virtual void OnTerminate() = 0;
-)__cpp_cb";
-
- const char cb2[] = R"__cpp_cb(
- protected:
- ServiceBase(std::string sender, std::string instance);
-
- private:
- std::string sender_;
- std::string instance_;
- };)__cpp_cb";
-
- stream << cb1;
+ stream << CB_SERVICE_BASE_FRONT;
auto& decls = iface.GetDeclarations();
for (auto& i : decls.GetDecls()) {
stream << ") = 0;" << NLine(1);
}
- stream << cb2 << NLine(2);
+ stream << CB_SERVICE_BASE_BACK << NLine(2);
}
void CppStubHeaderGen::GenPublicMethods(std::ofstream& stream,
const Interface& iface) {
- const char cb[] =
- "$$();\n" \
- "~$$();\n" \
- "void Listen(std::shared_ptr<ServiceBase::Factory> service_factory);\n" \
- "const std::list<std::shared_ptr<ServiceBase>>& GetServices() const {\n" \
- " return services_;\n" \
- "}\n";
-
- GenTemplate(AddIndent(TAB_SIZE, cb), stream,
+ GenTemplate(CB_PUBLIC_METHODS, stream,
[&]()->std::string {
return iface.GetID();
},
return iface.GetID();
}
);
- stream << NLine(1);
}
} // namespace tidl
--- /dev/null
+/*
+ * Copyright (c) 2018 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.
+ */
+
+const char CB_EXCEPTIONS[] =
+R"__cpp_cb(
+class Exception {};
+class NotConnectedSocketException : public Exception {};
+class InvalidProtocolException : public Exception {};
+)__cpp_cb";
+
+const char CB_PRIVATE_MEMBERS[] =
+R"__cpp_cb( static void OnConnectedCB(const char* sender, const char* instance, void* data);
+ static void OnDisconnectedCB(const char* sender, const char* instance, void* data);
+ static int OnReceivedCB(const char* sender, const char* instance, rpc_port_h port, void* data);
+
+ rpc_port_stub_h stub_;
+ std::shared_ptr<ServiceBase::Factory> service_factory_;
+ std::list<std::shared_ptr<ServiceBase>> services_;
+)__cpp_cb";
+
+const char CB_SERVICE_BASE_FRONT[] = R"__cpp_cb( class ServiceBase {
+ public:
+ class Factory {
+ public:
+ virtual std::unique_ptr<ServiceBase> CreateService(std::string sender, std::string instance) = 0;
+ };
+
+ virtual ~ServiceBase() = default;
+
+ const std::string& GetSender() const {
+ return sender_;
+ }
+
+ const std::string& GetInstance() const {
+ return instance_;
+ }
+
+ virtual void OnCreate() = 0;
+ virtual void OnTerminate() = 0;
+)__cpp_cb";
+
+const char CB_SERVICE_BASE_BACK[] =
+R"__cpp_cb(
+ protected:
+ ServiceBase(std::string sender, std::string instance);
+
+ private:
+ std::string sender_;
+ std::string instance_;
+ };)__cpp_cb";
+
+const char CB_PUBLIC_METHODS[] =
+R"__cpp_cb( $$();
+ ~$$();
+
+ void Listen(std::shared_ptr<ServiceBase::Factory> service_factory);
+ const std::list<std::shared_ptr<ServiceBase>>& GetServices() const {
+ return services_;
+ }
+
+)__cpp_cb";