SET(TARGET_RPC_PORT "rpc-port")
SET(TARGET_RPC_PORT_UNITTESTS "rpc-port_unittests")
SET(TARGET_RPC_PORT_UTIL "rpc-port-util")
-SET(TARGET_BENCHMARK_SERVER_TIDL "rpc-port-benchmark-server-tidl")
-SET(TARGET_BENCHMARK_SERVER_DBUS "rpc-port-benchmark-server-dbus")
-SET(TARGET_BENCHMARK_SERVER_GRPC "rpc-port-benchmark-server-grpc")
-SET(TARGET_BENCHMARK_TOOL "rpc-port-benchmark-tool")
ENABLE_TESTING()
ADD_TEST(NAME ${TARGET_RPC_PORT_UNITTESTS}
PKG_CHECK_MODULES(PKGMGR_INFO_DEPS REQUIRED pkgmgr-info)
PKG_CHECK_MODULES(TIZEN_SHARED_QUEUE_DEPS REQUIRED tizen-shared-queue)
PKG_CHECK_MODULES(UUID_DEPS REQUIRED uuid)
-PKG_CHECK_MODULES(GRPC_DEPS REQUIRED grpc)
-PKG_CHECK_MODULES(PROTOBUF_DEPS REQUIRED protobuf)
ADD_SUBDIRECTORY(src)
-ADD_SUBDIRECTORY(benchmark)
ADD_SUBDIRECTORY(utils)
ADD_SUBDIRECTORY(test)
+++ /dev/null
-ADD_SUBDIRECTORY(tool)
-ADD_SUBDIRECTORY(server)
+++ /dev/null
-ADD_SUBDIRECTORY(tidl)
-ADD_SUBDIRECTORY(dbus)
-ADD_SUBDIRECTORY(grpc)
+++ /dev/null
-AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR} BENCHMARK_SERVER_DBUS_SRCS)
-
-ADD_EXECUTABLE(${TARGET_BENCHMARK_SERVER_DBUS} ${BENCHMARK_SERVER_DBUS_SRCS})
-
-TARGET_INCLUDE_DIRECTORIES(${TARGET_BENCHMARK_SERVER_DBUS} PUBLIC
- ${CMAKE_CURRENT_SOURCE_DIR}
- ${CMAKE_CURRENT_SOURCE_DIR}/../../../include/)
-
-APPLY_PKG_CONFIG(${TARGET_BENCHMARK_SERVER_DBUS} PUBLIC
- DLOG_DEPS
- GLIB_DEPS
- GIO_DEPS
-)
-
-TARGET_LINK_LIBRARIES(${TARGET_BENCHMARK_SERVER_DBUS} PUBLIC
- ${TARGET_RPC_PORT} "-lpthread")
-SET_TARGET_PROPERTIES(${TARGET_BENCHMARK_SERVER_DBUS} PROPERTIES
- COMPILE_FLAGS "-fPIE")
-SET_TARGET_PROPERTIES(${TARGET_BENCHMARK_SERVER_DBUS} PROPERTIES
- LINK_FLAGS "-pie")
-
-INSTALL(TARGETS ${TARGET_BENCHMARK_SERVER_DBUS} DESTINATION bin)
-INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/rpc-port-benchmark.conf DESTINATION /etc/dbus-1/system.d)
+++ /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 LOG_PRIVATE_HH_
-#define LOG_PRIVATE_HH_
-
-#include <dlog.h>
-
-#undef LOG_TAG
-#define LOG_TAG "RPC_PORT_BENCHMARK_SERVER_DBUS"
-
-#undef _E
-#define _E LOGE
-
-#undef _W
-#define _W LOGW
-
-#undef _I
-#define _I LOGI
-
-#undef _D
-#define _D LOGD
-
-#endif // LOG_PRIVATE_HH_
+++ /dev/null
-/*
- * Copyright (c) 2024 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 <glib.h>
-#include <gio/gio.h>
-
-#include <string_view>
-#include <string>
-
-#include "log-private.hh"
-
-namespace {
-
-constexpr const char BUS_NAME[] = "tizen.appfw.rpcport.benchmark.dbus";
-constexpr const char OBJECT_PATH[] = "/tizen/appfw/rpcport/benchmark/dbus";
-
-constexpr const char INTROSPECTION_XML[] = R"__dbus(
-<node>
- <interface name='tizen.appfw.rpcport.benchmark.dbus'>
- <method name='Test'>
- <arg type='s' name='data' direction='in'/>
- <arg type='i' name='ret' direction='out'/>
- </method>
- <method name='Start'>
- <arg type='i' name='caller_pid' direction='in'/>
- <arg type='i' name='ret' direction='out'/>
- </method>
- <method name='Stop'>
- <arg type='i' name='caller_pid' direction='in'/>
- <arg type='i' name='ret' direction='out'/>
- </method>
- </interface>
-</node>
-)__dbus";
-
-class MainLoop {
- public:
- MainLoop() {
- loop_ = g_main_loop_new(nullptr, FALSE);
- }
-
- ~MainLoop() {
- g_main_loop_unref(loop_);
- if (introspection_data_)
- g_dbus_node_info_unref(introspection_data_);
- }
-
- int OnTest(std::string data) {
- return 0;
- }
-
- void OnBusAcquired(GDBusConnection* connection, const gchar* name) {
- _I("bus acquired(%s)", name);
-
- static const GDBusInterfaceVTable interface_vtable = {
- [](GDBusConnection *connection,
- const gchar *sender, const gchar *object_path,
- const gchar *interface_name, const gchar *method_name,
- GVariant *parameters, GDBusMethodInvocation *invocation,
- gpointer user_data) {
- if (std::string_view(method_name) == "Test") {
- char* data = nullptr;
- g_variant_get(parameters, "(&s)", &data);
- auto* obj = static_cast<MainLoop*>(user_data);
- int ret = obj->OnTest(data);
-
- GVariant* param = g_variant_new("(i)", ret);
- g_dbus_method_invocation_return_value(invocation, param);
- } else if (std::string_view(method_name) == "Stop") {
- gint caller_pid = -1;
- g_variant_get(parameters, "(i)", &caller_pid);
- _D("Stop request received from caller(%d)", caller_pid);
- auto* main_loop = static_cast<MainLoop*>(user_data);
- int ret = main_loop->SetTermTimer();
-
- GVariant* param = g_variant_new("(i)", ret);
- g_dbus_method_invocation_return_value(invocation, param);
- } else if (std::string_view(method_name) == "Start") {
- gint caller_pid = -1;
- g_variant_get(parameters, "(i)", &caller_pid);
- _D("Start request received from caller(%d)", caller_pid);
- auto* main_loop = static_cast<MainLoop*>(user_data);
- int ret = main_loop->UnsetTermTimer();
-
- GVariant* param = g_variant_new("(i)", ret);
- g_dbus_method_invocation_return_value(invocation, param);
- }
- },
- nullptr,
- nullptr
- };
-
- GError* error = nullptr;
- guint reg_id = g_dbus_connection_register_object(connection,
- OBJECT_PATH,
- introspection_data_->interfaces[0],
- &interface_vtable,
- this, nullptr, &error);
- if (reg_id == 0) {
- _E("g_dbus_connection_register_object error(%s)",
- error ? error->message : "");
- g_error_free(error);
- }
- }
-
- void Run() {
- GError* error = nullptr;
- introspection_data_ = g_dbus_node_info_new_for_xml(INTROSPECTION_XML,
- &error);
- if (!introspection_data_) {
- _E("g_dbus_node_info_new_for_xml error(%s)", error ? error->message : "");
- g_error_free(error);
- return;
- }
-
- guint owner_id = g_bus_own_name(G_BUS_TYPE_SYSTEM,
- BUS_NAME,
- G_BUS_NAME_OWNER_FLAGS_NONE,
- [](GDBusConnection* connection, const gchar* name,
- gpointer user_data) {
- auto* obj = static_cast<MainLoop*>(user_data);
- obj->OnBusAcquired(connection, name);
- },
- [](GDBusConnection* connection,
- const gchar* name, gpointer user_data) {
- _I("name acquired(%s)", name);
- },
- [](GDBusConnection* connection,
- const gchar* name, gpointer user_data) {
- _I("name lost(%s)", name);
- },
- this, nullptr);
- if (!owner_id) {
- _E("g_bus_own_name error");
- g_dbus_node_info_unref(introspection_data_);
- return;
- }
-
- g_main_loop_run(loop_);
- }
-
- void Quit() {
- g_main_loop_quit(loop_);
- }
-
- int SetTermTimer() {
- if (timer_) return 0;
-
- timer_ = g_timeout_add(
- 5000, [](gpointer user_data) {
- auto* main_loop = static_cast<MainLoop*>(user_data);
- main_loop->Quit();
- main_loop->timer_ = 0;
- return G_SOURCE_REMOVE;
- }, this);
-
- return 0;
- }
-
- int UnsetTermTimer() {
- if (timer_) {
- g_source_remove(timer_);
- timer_ = 0;
- }
-
- return 0;
- }
-
- private:
- GMainLoop* loop_ = nullptr;
- GDBusNodeInfo* introspection_data_ = nullptr;
- guint timer_ = 0;
-};
-
-} // namespace
-
-int main(int argc, char** argv) {
- MainLoop loop;
- loop.Run();
- return 0;
-}
+++ /dev/null
-<!DOCTYPE busconfig PUBLIC
-"-//freedesktop//DTD D-BUS Bus Configuration 1.0//EN"
-"http://www.freedesktop.org/standards/dbus/1.0/busconfig.dtd">
-
-<busconfig>
- <policy user="root">
- <allow own="tizen.appfw.rpcport.benchmark.dbus"/>
- <allow send_destination="tizen.appfw.rpcport.benchmark.dbus"
- send_interface="tizen.appfw.rpcport.benchmark.dbus" send_type="method_call" />
- </policy>
- <policy context="default">
- <deny own="tizen.appfw.rpcport.benchmark.dbus"/>
- <deny send_destination="tizen.appfw.rpcport.benchmark.dbus"/>
- </policy>
-</busconfig>
+++ /dev/null
-
-# Proto file
-get_filename_component(hw_proto "./grpcbench.proto" ABSOLUTE)
-get_filename_component(hw_proto_path "${hw_proto}" PATH)
-
-# Generated sources
-SET(hw_proto_srcs "${CMAKE_CURRENT_BINARY_DIR}/grpcbench.pb.cc")
-SET(hw_proto_hdrs "${CMAKE_CURRENT_BINARY_DIR}/grpcbench.pb.h")
-SET(hw_grpc_srcs "${CMAKE_CURRENT_BINARY_DIR}/grpcbench.grpc.pb.cc")
-SET(hw_grpc_hdrs "${CMAKE_CURRENT_BINARY_DIR}/grpcbench.grpc.pb.h")
-ADD_CUSTOM_COMMAND(
- OUTPUT "${hw_proto_srcs}" "${hw_proto_hdrs}" "${hw_grpc_srcs}" "${hw_grpc_hdrs}"
- COMMAND protoc
- ARGS --grpc_out "${CMAKE_CURRENT_BINARY_DIR}"
- --cpp_out "${CMAKE_CURRENT_BINARY_DIR}"
- -I "${hw_proto_path}"
- --plugin=protoc-gen-grpc=`which grpc_cpp_plugin`
- "${hw_proto}"
- DEPENDS "${hw_proto}")
-
-AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR} BENCHMARK_SERVER_GRPC_SRCS)
-ADD_EXECUTABLE(${TARGET_BENCHMARK_SERVER_GRPC}
- ${hw_proto_srcs}
- ${hw_grpc_srcs}
- ${BENCHMARK_SERVER_GRPC_SRCS}
-)
-
-TARGET_INCLUDE_DIRECTORIES(${TARGET_BENCHMARK_SERVER_GRPC} PUBLIC
- ${CMAKE_CURRENT_SOURCE_DIR}
- ${CMAKE_CURRENT_SOURCE_DIR}/../../../include/)
-
-APPLY_PKG_CONFIG(${TARGET_BENCHMARK_SERVER_GRPC} PUBLIC
- DLOG_DEPS
- GLIB_DEPS
- GIO_DEPS
- GRPC_DEPS
- PROTOBUF_DEPS
-)
-
-TARGET_LINK_LIBRARIES(${TARGET_BENCHMARK_SERVER_GRPC} PUBLIC
- ${TARGET_RPC_PORT} "-lpthread" grpc++)
-SET_TARGET_PROPERTIES(${TARGET_BENCHMARK_SERVER_GRPC} PROPERTIES
- COMPILE_FLAGS "-fPIE")
-SET_TARGET_PROPERTIES(${TARGET_BENCHMARK_SERVER_GRPC} PROPERTIES
- LINK_FLAGS "-pie")
-
-INSTALL(TARGETS ${TARGET_BENCHMARK_SERVER_GRPC} DESTINATION bin)
+++ /dev/null
-/*
- * Copyright (c) 2024 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 <iostream>
-#include <memory>
-#include <string>
-
-#include <grpcpp/grpcpp.h>
-
-#include "grpcbench.grpc.pb.h"
-
-using grpc::Server;
-using grpc::ServerBuilder;
-using grpc::ServerContext;
-using grpc::Status;
-using grpcbench::Benchmark;
-using grpcbench::TestReply;
-using grpcbench::TestRequest;
-
-class BenchmarkServiceImpl final : public Benchmark::Service {
- Status Test(ServerContext* context, const TestRequest* request,
- TestReply* reply) override {
- reply->set_ret(0);
- return Status::OK;
- }
-};
-
-int main(int argc, char** argv) {
- std::string server_address("unix:///tmp/test.socket");
-
- BenchmarkServiceImpl service;
- ServerBuilder builder;
-
- builder.AddListeningPort(server_address, grpc::InsecureServerCredentials());
- builder.RegisterService(&service);
- std::unique_ptr<Server> server(builder.BuildAndStart());
- std::cout << "Server listening on " << server_address << std::endl;
-
- server->Wait();
-
- return 0;
-}
+++ /dev/null
-syntax = "proto3";
-
-package grpcbench;
-
-// The greeting service definition.
-service Benchmark {
- rpc Test (TestRequest) returns (TestReply) {}
-}
-
-// The request message containing the user's name.
-message TestRequest {
- string data = 1;
-}
-
-// The response message containing the greetings
-message TestReply {
- int32 ret = 1;
-}
+++ /dev/null
-/*
- * Generated by tidlc 2.0.4.
- */
-
-#include <stdlib.h>
-#include <assert.h>
-#include <libgen.h>
-#include <dlog.h>
-
-#include "BenchmarkStub.h"
-
-
-#ifdef LOG_TAG
-#undef LOG_TAG
-#endif
-
-#define LOG_TAG "RPC_PORT_STUB"
-
-#ifdef _E
-#undef _E
-#endif
-
-#ifdef _W
-#undef _W
-#endif
-
-#ifdef _I
-#undef _I
-#endif
-
-#ifdef _D
-#undef _D
-#endif
-
-#define _E(fmt, ...) dlog_print(DLOG_ERROR, LOG_TAG, "%s: %s(%d) > " fmt, basename(const_cast<char*>(__FILE__)), __FUNCTION__, __LINE__, ##__VA_ARGS__)
-#define _W(fmt, ...) dlog_print(DLOG_WARN, LOG_TAG, "%s: %s(%d) > " fmt, basename(const_cast<char*>(__FILE__)), __FUNCTION__, __LINE__, ##__VA_ARGS__)
-#define _I(fmt, ...) dlog_print(DLOG_INFO, LOG_TAG, "%s: %s(%d) > " fmt, basename(const_cast<char*>(__FILE__)), __FUNCTION__, __LINE__, ##__VA_ARGS__)
-#define _D(fmt, ...) dlog_print(DLOG_DEBUG, LOG_TAG, "%s: %s(%d) > " fmt, basename(const_cast<char*>(__FILE__)), __FUNCTION__, __LINE__, ##__VA_ARGS__)
-
-#ifndef TIDL_VERSION
-#define TIDL_VERSION "2.0.4"
-#endif
-
-namespace rpc_port {
-namespace BenchmarkStub {
-
-namespace stub {
-
-Benchmark::ServiceBase::ServiceBase(std::string sender, std::string instance)
- : sender_(std::move(sender)), instance_(std::move(instance)),
- active_object_(new ActiveObject()) {}
-
-void Benchmark::ServiceBase::SetPort(rpc_port_h port) {
- port_ = port;
-}
-
-void Benchmark::ServiceBase::Disconnect() {
- int ret = rpc_port_disconnect(port_);
- if (ret == RPC_PORT_ERROR_NONE) {
- _E("Failed to disconnect the port(%d)", ret);
- return;
- }
-
- port_ = nullptr;
-}
-
-
-std::atomic<int> Benchmark::CallbackBase::seq_num_ { 0 };
-
-Benchmark::CallbackBase::CallbackBase(int delegate_id, bool once)
- : id_(delegate_id), once_(once) {
- seq_id_ = seq_num_++;
-}
-
-int Benchmark::CallbackBase::GetId() const {
- return id_;
-}
-
-int Benchmark::CallbackBase::GetSeqId() const {
- return seq_id_;
-}
-
-bool Benchmark::CallbackBase::IsOnce() const {
- return once_;
-}
-
-std::string Benchmark::CallbackBase::GetTag() const {
- return std::to_string(id_) + "::" + std::to_string(seq_id_);
-}
-
-rpc_port_parcel_h operator << (rpc_port_parcel_h h, const Benchmark::CallbackBase& cb) {
- rpc_port_parcel_write_int32(h, cb.id_);
- rpc_port_parcel_write_int32(h, cb.seq_id_);
- rpc_port_parcel_write_bool(h, cb.once_);
-
- return h;
-}
-
-rpc_port_parcel_h operator >> (rpc_port_parcel_h h, Benchmark::CallbackBase& cb) {
- rpc_port_parcel_read_int32(h, &cb.id_);
- rpc_port_parcel_read_int32(h, &cb.seq_id_);
- rpc_port_parcel_read_bool(h, &cb.once_);
-
- return h;
-}
-
-Benchmark::Benchmark() {
- int r = rpc_port_stub_create(&stub_, "Benchmark");
- if (r != RPC_PORT_ERROR_NONE) {
- _E("Failed to create stub handle");
- throw InvalidIOException();
- }
- 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);
-}
-
-Benchmark::~Benchmark() {
- for (auto& i : services_) {
- i->OnTerminate();
- }
-
- if (stub_) {
- rpc_port_stub_destroy(stub_);
- }
-}
-
-void Benchmark::Listen(std::shared_ptr<Benchmark::ServiceBase::Factory> service_factory) {
- service_factory_ = std::move(service_factory);
- int r = rpc_port_stub_listen(stub_);
- if (r != RPC_PORT_ERROR_NONE) {
- _E("Failed to listen stub");
- switch (r) {
- case RPC_PORT_ERROR_INVALID_PARAMETER:
- case RPC_PORT_ERROR_IO_ERROR:
- throw InvalidIOException();
- }
- }
-}
-
-void Benchmark::OnConnectedCB(const char* sender, const char* instance, void* data) {
- Benchmark* stub = static_cast<Benchmark*>(data);
- auto s = stub->service_factory_->CreateService(sender, instance);
-
- rpc_port_h port;
- int ret = rpc_port_stub_get_port(stub->stub_, RPC_PORT_PORT_CALLBACK, instance, &port);
- if (ret != RPC_PORT_ERROR_NONE) {
- _E("Failed to get the port(%d)", ret);
- return;
- }
-
- s->SetPort(port);
- s->OnCreate();
- stub->services_.emplace_back(std::move(s));
-}
-
-void Benchmark::OnDisconnectedCB(const char* sender, const char* instance, void *data) {
- Benchmark* stub = static_cast<Benchmark*>(data);
-
- for (auto& i : stub->services_) {
- if (i->GetInstance() == instance) {
- i->OnTerminate();
- stub->services_.remove(i);
- return;
- }
- }
-}
-
-int Benchmark::OnReceivedCB(const char* sender, const char* instance, rpc_port_h port, void *data)
-{
- auto* cxt = static_cast<Benchmark*>(data);
- rpc_port_parcel_h p;
- rpc_port_parcel_h result;
- rpc_port_parcel_header_h header;
- int seq_num = -1;
- int cmd;
- int ret;
- std::shared_ptr<ServiceBase> b;
- rpc_port_h callback_port;
-
- for (auto& i : cxt->services_) {
- if (i->GetInstance() == instance) {
- b = i;
- break;
- }
- }
-
- if (b.get() == nullptr) {
- _E("Failed to find Benchmark context(%s)", instance);
- return -1;
- }
-
- ret = rpc_port_stub_get_port(cxt->stub_, RPC_PORT_PORT_CALLBACK, instance,
- &callback_port);
- if (ret != 0) {
- _E("Failed to get callback port");
- }
-
- ret = rpc_port_parcel_create_from_port(&p, port);
- if (ret != 0) {
- _E("Failed to create parcel from port");
- return ret;
- }
-
- rpc_port_parcel_get_header(p, &header);
- rpc_port_parcel_header_get_seq_num(header, &seq_num);
-
- rpc_port_parcel_create(&result);
- rpc_port_parcel_get_header(result, &header);
- rpc_port_parcel_header_set_tag(header, TIDL_VERSION);
- rpc_port_parcel_header_set_seq_num(header, seq_num);
-
- rpc_port_parcel_read_int32(p, &cmd);
-
- switch (cmd) {
- case static_cast<int>(MethodId::Test): {
- char* param1_raw = nullptr;
- rpc_port_parcel_read_string(p, ¶m1_raw);
- std::string param1(param1_raw);
- free(param1_raw);
- auto retVal = b->Test(std::move(param1));
- rpc_port_parcel_write_int32(result, static_cast<int>(MethodId::__Result));
- rpc_port_parcel_write_int32(result, retVal);
- rpc_port_parcel_send(result, port);
- break;
- }
-
- default:
- _E("Unknown command(%d)", cmd);
- rpc_port_parcel_destroy(p);
- rpc_port_parcel_destroy(result);
- return -1;
- }
-
- rpc_port_parcel_destroy(p);
- rpc_port_parcel_destroy(result);
-
- return ret;
-}
-
-} // namespace stub
-} // namespace BenchmarkStub
-} // namespace rpc_port
+++ /dev/null
-/*
- * Generated by tidlc 2.0.4.
- */
-
-#pragma once
-
-#include <bundle.h>
-#include <rpc-port-parcel.h>
-#include <rpc-port.h>
-
-#include <memory>
-#include <string>
-#include <vector>
-#include <list>
-#include <atomic>
-#include <condition_variable>
-#include <mutex>
-#include <deque>
-#include <thread>
-
-namespace rpc_port {
-namespace BenchmarkStub {
-
-class Bundle final {
- public:
- Bundle() {
- raw_ = bundle_create();
- }
-
- Bundle(bundle* b) {
- raw_ = b;
- }
-
- ~Bundle() {
- if (raw_)
- bundle_free(raw_);
- }
-
- Bundle(Bundle&& b) : raw_(b.raw_) {
- b.raw_ = nullptr;
- }
-
- Bundle& operator = (Bundle&& b) {
- if (this != &b) {
- if (raw_)
- bundle_free(raw_);
-
- raw_ = b.raw_;
- b.raw_ = nullptr;
- }
- return *this;
- }
-
- Bundle(const Bundle& b) : raw_(bundle_dup(b.GetHandle())) {}
-
- Bundle& operator = (const Bundle& b) {
- if (this != &b) {
- if (raw_)
- bundle_free(raw_);
-
- raw_ = bundle_dup(b.GetHandle());
- }
- return *this;
- }
-
- bundle* GetHandle() const {
- return raw_;
- }
-
- private:
- bundle* raw_;
-};
-
-class File final {
- public:
- File() {
- }
-
- File(std::string filename) {
- filename_ = filename;
- }
-
- std::string GetFileName() const {
- return filename_;
- }
-
- private:
- std::string filename_;
-};
-
-namespace stub {
-
-class Exception {};
-class NotConnectedSocketException : public Exception {};
-class InvalidProtocolException : public Exception {};
-class InvalidIOException : public Exception {};
-class InvalidCallbackException : public Exception {};
-class Job {
- public:
- class IEvent {
- public:
- virtual ~IEvent() = default;
- virtual void Run() = 0;
- };
-
- Job() : handler_(nullptr) {
- }
-
- Job(IEvent* handler) : handler_(handler) {
- }
- virtual ~Job() = default;
-
- Job(const Job& job) {
- handler_ = job.handler_;
- }
-
- Job& operator = (const Job& job) {
- if (this != &job)
- handler_ = job.handler_;
- return *this;
- }
- Job(Job&& job) noexcept {
- handler_ = job.handler_;
- job.handler_ = nullptr;
- }
-
- Job& operator = (Job&& job) noexcept {
- if (this != &job) {
- handler_ = job.handler_;
- job.handler_ = nullptr;
- }
- return *this;
- }
-
- void Invoke() {
- if (handler_)
- handler_->Run();
- }
-
- private:
- IEvent* handler_;
-};
-
-
-template <class T>
-class SharedQueue {
- public:
- SharedQueue() = default;
- virtual ~SharedQueue() = default;
-
- void Push(T item) {
- std::lock_guard<std::mutex> lock(mutex_);
- queue_.push_back(item);
- cond_var_.notify_one();
- }
-
- void PushFront(T item) {
- std::lock_guard<std::mutex> lock(mutex_);
- queue_.push_front(item);
- cond_var_.notify_one();
- }
-
- bool TryAndPop(T& item) {
- std::lock_guard<std::mutex> lock(mutex_);
- if (queue_.empty())
- return false;
-
- item = queue_.front();
- queue_.pop_front();
-
- return true;
- }
-
- void WaitAndPop(T& item) {
- std::unique_lock<std::mutex> lock(mutex_);
- while (queue_.empty())
- cond_var_.wait(lock);
-
- item = queue_.front();
- queue_.pop_front();
- }
-
- bool Empty() {
- std::lock_guard<std::mutex> lock(mutex_);
- return queue_.empty();
- }
-
- int Size() {
- std::lock_guard<std::mutex> lock(mutex_);
- return queue_.size();
- }
-
- private:
- std::deque<T> queue_;
- mutable std::mutex mutex_;
- std::condition_variable cond_var_;
-};
-
-class ActiveObject : public Job::IEvent {
- public:
- ActiveObject() {
- thread_ = std::thread([&]{
- do {
- std::shared_ptr<Job> item;
- queue_.WaitAndPop(item);
- item->Invoke();
- } while (!done_);
- });
- }
- virtual ~ActiveObject() {
- Quit();
- thread_.join();
- }
-
- public:
- void Send(std::shared_ptr<Job> job) {
- queue_.Push(std::move(job));
- }
-
- private:
- void Quit() {
- Send(std::shared_ptr<Job>(new (std::nothrow) Job(this)));
- }
- void Run() override {
- done_ = true;
- }
-
- private:
- std::thread thread_;
- bool done_ = false;
- SharedQueue<std::shared_ptr<Job>> queue_;
-};
-
-
-class Benchmark final {
- public:
- class ServiceBase;
-
- class CallbackBase {
- public:
- CallbackBase(int delegate_id, bool once);
- virtual ~CallbackBase() = default;
-
- int GetId() const;
- int GetSeqId() const;
- bool IsOnce() const;
- std::string GetTag() const;
-
- private:
- friend rpc_port_parcel_h operator << (rpc_port_parcel_h h, const CallbackBase& cb);
- friend rpc_port_parcel_h operator >> (rpc_port_parcel_h h, CallbackBase& cb);
-
- static std::atomic<int> seq_num_;
- int id_;
- int seq_id_;
- bool once_;
- };
-
- class ServiceBase {
- public:
- class Factory {
- public:
- virtual ~Factory() = default;
-
- /// <summary>
- /// The method for making service instances
- /// </summary>
- /// <param name="sender">The client app ID</param>
- /// <param name="instance">The client instance ID</param>
- virtual std::unique_ptr<ServiceBase> CreateService(std::string sender, std::string instance) = 0;
- };
-
- virtual ~ServiceBase() = default;
-
- /// <summary>
- /// Gets client app ID
- /// </summary>
- const std::string& GetSender() const {
- return sender_;
- }
-
- /// <summary>
- /// Gets client instance ID
- /// </summary>
- const std::string& GetInstance() const {
- return instance_;
- }
-
- /// <summary>
- /// Sets the client app port
- /// </summary>
- /// <param name="port">The port of the client</param>
- void SetPort(rpc_port_h port);
-
- /// <summary>
- /// Disconnects from the client app
- /// </summary>
- /// <exception cref="InvalidIOException">
- /// Thrown when internal I/O error happen.
- /// </exception>
- void Disconnect();
-
- /// <summary>
- /// This method will be called when the client is connected
- /// </summary>
- virtual void OnCreate() = 0;
-
- /// <summary>
- /// This method will be called when the client is disconnected
- /// </summary>
- virtual void OnTerminate() = 0;
-
- void Dispatch(rpc_port_h port, rpc_port_h callback_port,
- rpc_port_parcel_h parcel, std::shared_ptr<ServiceBase> service);
-
- virtual int Test(std::string data) = 0;
-
- protected:
- ServiceBase(std::string sender, std::string instance);
-
- private:
- std::string sender_;
- std::string instance_;
- rpc_port_h port_ = nullptr;
- std::unique_ptr<ActiveObject> active_object_;
- };
-
- Benchmark();
- ~Benchmark();
-
- /// <summary>
- /// Listens to client apps
- /// </summary>
- /// <param name="service_factory">The factory object for making service instances</param>
- /// <exception cref="InvalidIOException">
- /// Thrown when internal I/O error happen.
- /// </exception>
- void Listen(std::shared_ptr<ServiceBase::Factory> service_factory);
-
- /// <summary>
- /// Gets service objects which are connected
- /// </summary>
- /// <returns>The list of service objects which are connected</returns>
- const std::list<std::shared_ptr<ServiceBase>>& GetServices() const {
- return services_;
- }
-
- private:
- enum class MethodId : int {
- __Result = 0,
- __Callback = 1,
- Test = 2,
-
- };
-
- enum class DelegateId : int {
-
- };
- 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_ = nullptr;
- std::shared_ptr<ServiceBase::Factory> service_factory_;
- std::list<std::shared_ptr<ServiceBase>> services_;
-};
-} // namespace stub
-} // namespace BenchmarkStub
-} // namespace rpc_port
+++ /dev/null
-AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR} BENCHMARK_SERVER_TIDL_SRCS)
-
-ADD_EXECUTABLE(${TARGET_BENCHMARK_SERVER_TIDL} ${BENCHMARK_SERVER_TIDL_SRCS})
-
-TARGET_INCLUDE_DIRECTORIES(${TARGET_BENCHMARK_SERVER_TIDL} PUBLIC
- ${CMAKE_CURRENT_SOURCE_DIR}
- ${CMAKE_CURRENT_SOURCE_DIR}/../../../include/)
-
-APPLY_PKG_CONFIG(${TARGET_BENCHMARK_SERVER_TIDL} PUBLIC
- AUL_DEPS
- DLOG_DEPS
- GLIB_DEPS
-)
-
-TARGET_LINK_LIBRARIES(${TARGET_BENCHMARK_SERVER_TIDL} PUBLIC
- ${TARGET_RPC_PORT} "-lpthread")
-SET_TARGET_PROPERTIES(${TARGET_BENCHMARK_SERVER_TIDL} PROPERTIES
- COMPILE_FLAGS "-fPIE")
-SET_TARGET_PROPERTIES(${TARGET_BENCHMARK_SERVER_TIDL} PROPERTIES
- LINK_FLAGS "-pie")
-
-INSTALL(TARGETS ${TARGET_BENCHMARK_SERVER_TIDL} DESTINATION bin)
+++ /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 LOG_PRIVATE_HH_
-#define LOG_PRIVATE_HH_
-
-#include <dlog.h>
-
-#undef LOG_TAG
-#define LOG_TAG "RPC_PORT_BENCHMARK_SERVER"
-
-#undef _E
-#define _E LOGE
-
-#undef _W
-#define _W LOGW
-
-#undef _I
-#define _I LOGI
-
-#undef _D
-#define _D LOGD
-
-#endif // LOG_PRIVATE_HH_
+++ /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 <glib.h>
-#include <sys/types.h>
-#include <unistd.h>
-
-#include <rpc-port-internal.h>
-
-#include "BenchmarkStub.h"
-#include "log-private.hh"
-
-namespace {
-constexpr const char SERVER_PROC_NAME[] =
- "d::org.tizen.appfw.rpc_port.benchmark";
-
-namespace bs = rpc_port::BenchmarkStub::stub;
-
-class MainLoop {
- public:
- MainLoop();
- ~MainLoop();
-
- void Run();
- void Quit();
- void SetTermTimer();
- void RemoveTermTimer();
-
- private:
- GMainLoop* loop_;
- bs::Benchmark stub_;
- guint timer_ = 0;
-};
-
-class TestService : public bs::Benchmark::ServiceBase {
- public:
- class Factory : public bs::Benchmark::ServiceBase::Factory {
- public:
- explicit Factory(MainLoop* loop) : loop_(loop) {}
-
- virtual ~Factory() = default;
-
- std::unique_ptr<bs::Benchmark::ServiceBase>
- CreateService(std::string sender, std::string instance) {
- return std::unique_ptr<bs::Benchmark::ServiceBase>(
- new TestService(std::move(sender), std::move(instance), loop_));
- }
-
- private:
- MainLoop* loop_ = nullptr;
- };
-
- TestService(std::string sender, std::string instance, MainLoop* loop)
- : bs::Benchmark::ServiceBase(std::move(sender), std::move(instance)),
- loop_(loop) {}
-
- virtual ~TestService() = default;
-
- void OnCreate() override {
- loop_->RemoveTermTimer();
- }
-
- void OnTerminate() override {
- loop_->SetTermTimer();
- }
-
- int Test(std::string data) override { return 0; }
-
- private:
- MainLoop* loop_ = nullptr;
-};
-
-MainLoop::MainLoop() { loop_ = g_main_loop_new(nullptr, FALSE); }
-
-MainLoop::~MainLoop() {
- RemoveTermTimer();
- g_main_loop_unref(loop_);
-}
-
-void MainLoop::Run() {
- std::string proc_name = std::string(SERVER_PROC_NAME);
- if (getuid() >= 5000) proc_name = "u" + proc_name;
-
- int ret = rpc_port_register_proc_info(proc_name.c_str(), nullptr);
- if (ret != RPC_PORT_ERROR_NONE) {
- _E("rpc_port_register_proc_info() failed (%d)", ret);
- return;
- }
-
- try {
- stub_.Listen(std::shared_ptr<bs::Benchmark::ServiceBase::Factory>(
- new TestService::Factory(this)));
- } catch (const bs::Exception&) {
- _E("stub listen is failed");
- }
-
- g_main_loop_run(loop_);
-}
-
-void MainLoop::Quit() { g_main_loop_quit(loop_); }
-
-void MainLoop::SetTermTimer() {
- if (timer_) return;
-
- timer_ = g_timeout_add(
- 5000,
- [](gpointer data) -> gboolean {
- auto* main_loop = static_cast<MainLoop*>(data);
- main_loop->Quit();
- main_loop->timer_ = 0;
- return G_SOURCE_REMOVE;
- },
- this);
-}
-
-void MainLoop::RemoveTermTimer() {
- if (timer_) {
- g_source_remove(timer_);
- timer_ = 0;
- }
-}
-
-} // namespace
-
-int main(int argc, char** argv) {
- MainLoop loop;
- loop.Run();
- return 0;
-}
+++ /dev/null
-#!/bin/bash
-tidlc -p -l C++ -i test.tidl -o BenchmarkProxy
-mv ./BenchmarkProxy.* ../tool/
-tidlc -s -l C++ -i test.tidl -o BenchmarkStub
-mv ./BenchmarkStub.* ../server/
+++ /dev/null
-interface Benchmark {
- int Test(string data);
-}
+++ /dev/null
-/*
- * Generated by tidlc 2.0.4.
- */
-
-#include <stdlib.h>
-#include <assert.h>
-#include <dlog.h>
-
-#include "BenchmarkProxy.h"
-
-
-#ifdef LOG_TAG
-#undef LOG_TAG
-#endif
-
-#define LOG_TAG "RPC_PORT_PROXY"
-
-#ifdef _E
-#undef _E
-#endif
-
-#ifdef _W
-#undef _W
-#endif
-
-#ifdef _I
-#undef _I
-#endif
-
-#ifdef _D
-#undef _D
-#endif
-
-#define _E(fmt, ...) dlog_print(DLOG_ERROR, LOG_TAG, "%s: %s(%d) > " fmt, basename(const_cast<char*>(__FILE__)), __FUNCTION__, __LINE__, ##__VA_ARGS__)
-#define _W(fmt, ...) dlog_print(DLOG_WARN, LOG_TAG, "%s: %s(%d) > " fmt, basename(const_cast<char*>(__FILE__)), __FUNCTION__, __LINE__, ##__VA_ARGS__)
-#define _I(fmt, ...) dlog_print(DLOG_INFO, LOG_TAG, "%s: %s(%d) > " fmt, basename(const_cast<char*>(__FILE__)), __FUNCTION__, __LINE__, ##__VA_ARGS__)
-#define _D(fmt, ...) dlog_print(DLOG_DEBUG, LOG_TAG, "%s: %s(%d) > " fmt, basename(const_cast<char*>(__FILE__)), __FUNCTION__, __LINE__, ##__VA_ARGS__)
-
-#ifndef TIDL_VERSION
-#define TIDL_VERSION "2.0.4"
-#endif
-
-namespace rpc_port {
-namespace BenchmarkProxy {
-
-namespace proxy {
-
-
-std::atomic<int> Benchmark::CallbackBase::seq_num_ { 0 };
-
-Benchmark::CallbackBase::CallbackBase(int delegate_id, bool once)
- : id_(delegate_id), once_(once) {
- seq_id_ = seq_num_++;
-}
-
-int Benchmark::CallbackBase::GetId() const {
- return id_;
-}
-
-int Benchmark::CallbackBase::GetSeqId() const {
- return seq_id_;
-}
-
-bool Benchmark::CallbackBase::IsOnce() const {
- return once_;
-}
-
-std::string Benchmark::CallbackBase::GetTag() const {
- return std::to_string(id_) + "::" + std::to_string(seq_id_);
-}
-
-rpc_port_parcel_h operator << (rpc_port_parcel_h h, const Benchmark::CallbackBase& cb) {
- rpc_port_parcel_write_int32(h, cb.id_);
- rpc_port_parcel_write_int32(h, cb.seq_id_);
- rpc_port_parcel_write_bool(h, cb.once_);
-
- return h;
-}
-
-rpc_port_parcel_h operator >> (rpc_port_parcel_h h, Benchmark::CallbackBase& cb) {
- rpc_port_parcel_read_int32(h, &cb.id_);
- rpc_port_parcel_read_int32(h, &cb.seq_id_);
- rpc_port_parcel_read_bool(h, &cb.once_);
-
- return h;
-}
-
-Benchmark::Benchmark(IEventListener* listener, const std::string& target_appid)
- : port_(nullptr), callback_port_(nullptr), proxy_(nullptr),
- listener_(listener), target_appid_(target_appid) {
- int r = rpc_port_proxy_create(&proxy_);
-
- if (r != RPC_PORT_ERROR_NONE) {
- _E("Failed to create proxy");
- throw InvalidIOException();
- }
-
- rpc_port_proxy_add_connected_event_cb(proxy_, OnConnectedCB, this);
- rpc_port_proxy_add_disconnected_event_cb(proxy_, OnDisconnectedCB, this);
- rpc_port_proxy_add_rejected_event_cb(proxy_, OnRejectedCB, this);
- rpc_port_proxy_add_received_event_cb(proxy_, OnReceivedCB, this);
-}
-
-Benchmark::~Benchmark() {
- if (proxy_)
- rpc_port_proxy_destroy(proxy_);
-}
-
-void Benchmark::Connect(bool sync) {
- int ret;
- if (sync)
- ret = rpc_port_proxy_connect_sync(proxy_, target_appid_.c_str(), "Benchmark");
- else
- ret = rpc_port_proxy_connect(proxy_, target_appid_.c_str(), "Benchmark");
- if (ret != RPC_PORT_ERROR_NONE) {
- _E("Failed to connect Benchmark");
- switch (ret) {
- case RPC_PORT_ERROR_INVALID_PARAMETER:
- throw InvalidIDException();
-
- case RPC_PORT_ERROR_IO_ERROR:
- throw InvalidIOException();
-
- case RPC_PORT_ERROR_PERMISSION_DENIED:
- throw PermissionDeniedException();
- }
- }
-}
-
-void Benchmark::Disconnect() {
- int ret = rpc_port_disconnect(port_);
- if (ret != RPC_PORT_ERROR_NONE) {
- _E("Failed to disconnect Benchmark");
- throw InvalidIDException();
- }
-}
-
-void Benchmark::DisposeCallback(const std::string& tag) {
- for (auto& i : delegate_list_) {
- if (i->GetTag() == tag) {
- delegate_list_.remove(i);
- return;
- }
- }
-}
-
-void Benchmark::ProcessReceivedEvent(rpc_port_parcel_h parcel) {
- int id = 0;
- int seq_id = 0;
- bool once = false;
-
- rpc_port_parcel_read_int32(parcel, &id);
- rpc_port_parcel_read_int32(parcel, &seq_id);
- rpc_port_parcel_read_bool(parcel, &once);
-
- for (auto& i : delegate_list_) {
- if (i->GetId() == id && i->GetSeqId() == seq_id) {
- i->OnReceivedEvent(parcel);
- if (i->IsOnce())
- delegate_list_.remove(i);
- break;
- }
- }
-}
-
-void Benchmark::ConsumeCommand(rpc_port_parcel_h* parcel, rpc_port_h port) {
- do {
- rpc_port_parcel_h p;
- int ret = rpc_port_parcel_create_from_port(&p, port);
- int cmd;
-
- if (ret != 0)
- break;
- rpc_port_parcel_read_int32(p, &cmd);
- if (cmd == static_cast<int>(MethodId::__Result)) {
- *parcel = p;
- return;
- }
-
- rpc_port_parcel_destroy(p);
- *parcel = nullptr;
- } while (true);
- *parcel = nullptr;
-}
-
-void Benchmark::OnConnectedCB(const char *ep, const char *port_name, rpc_port_h port, void *data) {
- Benchmark* l = static_cast<Benchmark*>(data);
- rpc_port_h cb_port;
-
- l->port_ = port;
- rpc_port_proxy_get_port(l->proxy_, RPC_PORT_PORT_CALLBACK, &cb_port);
- l->callback_port_ = cb_port;
- l->listener_->OnConnected();
-}
-
-void Benchmark::OnDisconnectedCB(const char *ep, const char *port_name, void *data) {
- Benchmark* l = static_cast<Benchmark*>(data);
- l->delegate_list_.clear();
- l->listener_->OnDisconnected();
-}
-
-void Benchmark::OnRejectedCB(const char *ep, const char *port_name, void *data) {
- Benchmark* l = static_cast<Benchmark*>(data);
- l->listener_->OnRejected();
-}
-
-void Benchmark::OnReceivedCB(const char *ep, const char *port_name, void *data) {
- Benchmark* l = static_cast<Benchmark*>(data);
- int cmd;
- rpc_port_parcel_h parcel_received;
-
- if (rpc_port_parcel_create_from_port(&parcel_received, l->callback_port_) != 0) {
- _E("Failed to create parcel from port");
- return;
- }
-
- rpc_port_parcel_read_int32(parcel_received, &cmd);
- if (cmd != static_cast<int>(MethodId::__Callback)) {
- rpc_port_parcel_destroy(parcel_received);
- return;
- }
-
- l->ProcessReceivedEvent(parcel_received);
- rpc_port_parcel_destroy(parcel_received);
-}
-
-
-int Benchmark::Test(std::string data) {
- if (port_ == nullptr) {
- _E("Not connected");
- throw NotConnectedSocketException();
- }
-
- rpc_port_parcel_h p;
- rpc_port_parcel_create(&p);
-
- rpc_port_parcel_header_h header_;
- rpc_port_parcel_get_header(p, &header_);
- rpc_port_parcel_header_set_tag(header_, TIDL_VERSION);
- int seq_num_ = -1;
- rpc_port_parcel_header_get_seq_num(header_, &seq_num_);
- rpc_port_parcel_write_int32(p, static_cast<int>(MethodId::Test));
- rpc_port_parcel_write_string(p, data.c_str());
-
- std::lock_guard<std::recursive_mutex> lock(mutex_);
-
- // Send
- int r = rpc_port_parcel_send(p, port_);
- if (r != RPC_PORT_ERROR_NONE) {
- _E("Failed to send parcel. result(%d)", r);
- rpc_port_parcel_destroy(p);
- throw InvalidIOException();
- }
-
- int ret;
- bool done_ = false;
- do {
- rpc_port_parcel_h parcel_received = nullptr;
- // Receive
- ConsumeCommand(&parcel_received, port_);
- if (parcel_received == nullptr) {
- _E("Invalid protocol");
- throw InvalidProtocolException();
- }
-
- rpc_port_parcel_get_header(parcel_received, &header_);
- char* tag_ = nullptr;
- rpc_port_parcel_header_get_tag(header_, &tag_);
- std::unique_ptr<char, decltype(std::free)*> tag_auto_(tag_, std::free);
- if (tag_ && tag_[0] != '\0') {
- int seq_num_received_ = -1;
- rpc_port_parcel_header_get_seq_num(header_, &seq_num_received_);
- if (seq_num_received_ != seq_num_) {
- _E("Invalid protocol. %d", seq_num_received_);
- rpc_port_parcel_destroy(parcel_received);
- continue;
- }
- }
- done_ = true;
-
- rpc_port_parcel_read_int32(parcel_received, &ret);
-
- rpc_port_parcel_destroy(parcel_received);
- } while (!done_);
-
- rpc_port_parcel_destroy(p);
-
- return ret;
-
-}
-} // namespace proxy
-} // namespace BenchmarkProxy
-} // namespace rpc_port
+++ /dev/null
-/*
- * Generated by tidlc 2.0.4.
- */
-
-#pragma once
-
-#include <bundle.h>
-#include <rpc-port-parcel.h>
-#include <rpc-port.h>
-
-#include <string>
-#include <vector>
-#include <memory>
-#include <mutex>
-#include <list>
-#include <atomic>
-
-namespace rpc_port {
-namespace BenchmarkProxy {
-class Bundle final {
- public:
- Bundle() {
- raw_ = bundle_create();
- }
-
- Bundle(bundle* b) {
- raw_ = b;
- }
-
- ~Bundle() {
- if (raw_)
- bundle_free(raw_);
- }
-
- Bundle(Bundle&& b) : raw_(b.raw_) {
- b.raw_ = nullptr;
- }
-
- Bundle& operator = (Bundle&& b) {
- if (this != &b) {
- if (raw_)
- bundle_free(raw_);
-
- raw_ = b.raw_;
- b.raw_ = nullptr;
- }
- return *this;
- }
-
- Bundle(const Bundle& b) : raw_(bundle_dup(b.GetHandle())) {}
-
- Bundle& operator = (const Bundle& b) {
- if (this != &b) {
- if (raw_)
- bundle_free(raw_);
-
- raw_ = bundle_dup(b.GetHandle());
- }
- return *this;
- }
-
- bundle* GetHandle() const {
- return raw_;
- }
-
- private:
- bundle* raw_;
-};
-
-class File final {
- public:
- File() {
- }
-
- File(std::string filename) {
- filename_ = filename;
- }
-
- std::string GetFileName() const {
- return filename_;
- }
-
- private:
- std::string filename_;
-};
-
-
-namespace proxy {
-
-class Exception {};
-class NotConnectedSocketException : public Exception {};
-class InvalidProtocolException : public Exception {};
-class InvalidIOException : public Exception {};
-class PermissionDeniedException : public Exception {};
-class InvalidIDException : public Exception {};
-
-class Benchmark {
- public:
-
- class CallbackBase {
- public:
- CallbackBase(int delegate_id, bool once);
- virtual ~CallbackBase() = default;
- virtual void OnReceivedEvent(rpc_port_parcel_h port) = 0;
- int GetId() const;
- int GetSeqId() const;
- bool IsOnce() const;
- std::string GetTag() const;
-
- private:
- friend rpc_port_parcel_h operator << (rpc_port_parcel_h h, const CallbackBase& cb);
- friend rpc_port_parcel_h operator >> (rpc_port_parcel_h h, CallbackBase& cb);
-
- static std::atomic<int> seq_num_;
- int id_;
- int seq_id_;
- bool once_;
- };
-
- class IEventListener {
- public:
- /// <summary>
- /// This method will be invoked when the client app is connected to the servicece app.
- /// </summary>
- virtual void OnConnected() = 0;
-
- /// <summary>
- /// This method will be invoked after the client app was disconnected from the servicece app.
- /// </summary>
- virtual void OnDisconnected() = 0;
-
- /// <summary>
- /// This method will be invoked when the service app rejects the client app.
- /// </summary>
- virtual void OnRejected() = 0;
- };
-
- /// <summary>
- /// Constructor for this class
- /// </summary>
- /// <param name="listener">The listener for events</param>
- /// <param name="target_appid">The service app ID to connect</param>
- Benchmark(IEventListener* listener, const std::string& target_appid);
-
- /// <summary>
- /// Destructor for this class
- /// </summary>
- virtual ~Benchmark();
-
- /// <summary>
- /// Connects to the service app.
- /// </summary>
- /// <privilege>http://tizen.org/privilege/appmanager.launch</privilege>
- /// <privilege>http://tizen.org/privilege/datasharing</privilege>
- // <param name="sync">if true, connects to the service app synchornously</param>
- /// <exception cref="InvalidIDException">
- /// Thrown when the appid to connect is invalid.
- /// </exception>
- /// <exception cref="InvalidIOException">
- /// Thrown when internal I/O error happen.
- /// </exception>
- /// <exception cref="PermissionDeniedException">
- /// Thrown when the permission is denied.
- /// </exception>
- /// <remark> If you want to use this method, you must add privileges.</remark>
- void Connect(bool sync = false);
-
- /// <summary>
- /// Disconnects from the service app.
- /// </summary>
- /// <exception cref="InvalidIDException">
- /// Thrown when the stub port is invalid.
- /// </exception>
- void Disconnect();
-
- /// <summary>
- /// Disposes delegate objects in this interface
- /// </summary>
- /// <param name="tag">The tag string from delegate object</param>
- void DisposeCallback(const std::string& tag);
-
- int Test(std::string data);
-
- private:
- enum class MethodId : int {
- __Result = 0,
- __Callback = 1,
- Test = 2,
-
- };
-
- enum class DelegateId : int {
-
- };
- 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_h callback_port_;
- rpc_port_proxy_h proxy_;
- IEventListener* listener_;
- std::recursive_mutex mutex_;
- std::list<std::unique_ptr<CallbackBase>> delegate_list_;
- std::string target_appid_;
-};
-} // namespace proxy
-} // namespace BenchmarkProxy
-} // namespace rpc_port
+++ /dev/null
-# Proto file
-get_filename_component(hw_proto "./grpcbench.proto" ABSOLUTE)
-get_filename_component(hw_proto_path "${hw_proto}" PATH)
-
-# Generated sources
-SET(hw_proto_srcs "${CMAKE_CURRENT_BINARY_DIR}/grpcbench.pb.cc")
-SET(hw_proto_hdrs "${CMAKE_CURRENT_BINARY_DIR}/grpcbench.pb.h")
-SET(hw_grpc_srcs "${CMAKE_CURRENT_BINARY_DIR}/grpcbench.grpc.pb.cc")
-SET(hw_grpc_hdrs "${CMAKE_CURRENT_BINARY_DIR}/grpcbench.grpc.pb.h")
-ADD_CUSTOM_COMMAND(
- OUTPUT "${hw_proto_srcs}" "${hw_proto_hdrs}" "${hw_grpc_srcs}" "${hw_grpc_hdrs}"
- COMMAND protoc
- ARGS --grpc_out "${CMAKE_CURRENT_BINARY_DIR}"
- --cpp_out "${CMAKE_CURRENT_BINARY_DIR}"
- -I "${hw_proto_path}"
- --plugin=protoc-gen-grpc=`which grpc_cpp_plugin`
- "${hw_proto}"
- DEPENDS "${hw_proto}")
-
-AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR} BENCHMARK_SRCS)
-
-ADD_EXECUTABLE(${TARGET_BENCHMARK_TOOL}
- ${hw_proto_srcs}
- ${hw_grpc_srcs}
- ${BENCHMARK_SRCS}
-)
-
-TARGET_INCLUDE_DIRECTORIES(${TARGET_BENCHMARK_TOOL} PUBLIC
- ${CMAKE_CURRENT_SOURCE_DIR}
- ${CMAKE_CURRENT_SOURCE_DIR}/../../include/)
-
-APPLY_PKG_CONFIG(${TARGET_BENCHMARK_TOOL} PUBLIC
- AUL_DEPS
- BUNDLE_DEPS
- DLOG_DEPS
- GLIB_DEPS
- GRPC_DEPS
- PROTOBUF_DEPS
-)
-
-TARGET_LINK_LIBRARIES(${TARGET_BENCHMARK_TOOL} PUBLIC
- ${TARGET_RPC_PORT} "-lpthread" grpc++)
-SET_TARGET_PROPERTIES(${TARGET_BENCHMARK_TOOL} PROPERTIES
- COMPILE_FLAGS "-fPIE")
-SET_TARGET_PROPERTIES(${TARGET_BENCHMARK_TOOL} PROPERTIES
- LINK_FLAGS "-pie")
-
-INSTALL(TARGETS ${TARGET_BENCHMARK_TOOL} DESTINATION bin)
+++ /dev/null
-/*
- * Copyright (c) 2024 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 "dbus-proxy.hh"
-#include "log-private.hh"
-
-namespace rpc_port {
-namespace benchmark {
-
-namespace {
-
-constexpr const char BUS_NAME[] = "tizen.appfw.rpcport.benchmark.dbus";
-constexpr const char OBJECT_PATH[] = "/tizen/appfw/rpcport/benchmark/dbus";
-constexpr const char INTERFACE_NAME[] = "tizen.appfw.rpcport.benchmark.dbus";
-
-}
-
-DbusProxy::DbusProxy() {
-}
-
-void DbusProxy::Connect() {
- if (system_conn_ != nullptr)
- return;
-
- GError* error = nullptr;
- system_conn_ = g_bus_get_sync(G_BUS_TYPE_SYSTEM, nullptr, &error);
- if (system_conn_ == nullptr) {
- _E("g_bus_get_sync() is failed. error(%s)",
- error ? error->message : "Unknown");
- g_clear_error(&error);
- }
-}
-
-int DbusProxy::Test(std::string data) {
- return MethodCall("Test", g_variant_new("(s)", data.c_str()));
-}
-
-int DbusProxy::Start(pid_t caller_pid) {
- return MethodCall("Start", g_variant_new("(i)", caller_pid));
-}
-
-int DbusProxy::Stop(pid_t caller_pid) {
- return MethodCall("Stop", g_variant_new("(i)", caller_pid));
-}
-
-int DbusProxy::MethodCall(const std::string_view method_name,
- GVariant* parameters) {
- auto* msg = g_dbus_message_new_method_call(
- BUS_NAME, OBJECT_PATH, INTERFACE_NAME, method_name.data());
- if (msg == nullptr) {
- _E("g_dbus_message_new_method_call() is failed");
- return -1;
- }
- std::unique_ptr<GDBusMessage, decltype(g_object_unref)*> msg_auto(
- msg, g_object_unref);
-
- g_dbus_message_set_body(msg, parameters);
- GError* error = nullptr;
- auto* reply = g_dbus_connection_send_message_with_reply_sync(
- system_conn_, msg, G_DBUS_SEND_MESSAGE_FLAGS_NONE, -1, nullptr, nullptr,
- &error);
- if (reply == nullptr || error != nullptr) {
- _E("g_dbus_connection_send_message_with_reply_sync() is failed. error(%s)",
- error ? error->message : "Unknown");
- g_clear_error(&error);
- return -1;
- }
- std::unique_ptr<GDBusMessage, decltype(g_object_unref)*> reply_auto(
- reply, g_object_unref);
-
- auto* body = g_dbus_message_get_body(reply);
- if (body == nullptr) {
- _E("g_dbus_message_get_body() is failed");
- return -1;
- }
-
- int ret = -1;
- g_variant_get(body, "(i)", &ret);
- return ret;
-}
-
-} // namespace benchmark
-} // namespace rpc_port
+++ /dev/null
-/*
- * Copyright (c) 2024 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 DBUS_PROXY_HH_
-#define DBUS_PROXY_HH_
-
-#include <gio/gio.h>
-#include <glib.h>
-#include <sys/types.h>
-#include <unistd.h>
-
-#include <memory>
-#include <string>
-#include <string_view>
-
-namespace rpc_port {
-namespace benchmark {
-
-class DbusProxy {
- public:
- DbusProxy();
-
- void Connect();
- int Test(std::string data);
- int Start(pid_t caller_pid);
- int Stop(pid_t caller_pid);
-
- private:
- int MethodCall(const std::string_view method_name,
- GVariant* parameters);
-
- private:
- GDBusConnection* system_conn_ = nullptr;
-};
-
-} // namespace benchmark
-} // namespace rpc_port
-
-#endif // DBUS_PROXY_HH_
+++ /dev/null
-/*
- * Copyright (c) 2024 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 "grpc-proxy.hh"
-
-namespace rpc_port {
-namespace benchmark {
-
-GrpcProxy::GrpcProxy() {
-}
-
-void GrpcProxy::Connect() {
- std::string target_str("unix:///tmp/test.socket");
- channel_ = grpc::CreateChannel(target_str,
- grpc::InsecureChannelCredentials());
- stub_ = grpcbench::Benchmark::NewStub(channel_);
-}
-
-int GrpcProxy::Test(std::string data) const {
- grpcbench::TestRequest request;
- request.set_data(data);
-
- grpc::ClientContext context;
- grpcbench::TestReply response;
-
- grpc::Status status = stub_->Test(&context, request, &response);
- if (status.ok()) {
- int ret = response.ret();
- return ret;
- }
-
- return -1;
-}
-
-} // namespace benchmark
-} // namespace rpc_port
+++ /dev/null
-/*
- * Copyright (c) 2024 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 GRPC_PROXY_HH_
-#define GRPC_PROXY_HH_
-
-#include <string>
-#include <memory>
-
-#include <grpcpp/grpcpp.h>
-#include "grpcbench.grpc.pb.h"
-
-namespace rpc_port {
-namespace benchmark {
-
-class GrpcProxy {
- public:
- GrpcProxy();
-
- void Connect();
- int Test(std::string data) const;
-
- private:
- std::unique_ptr<grpcbench::Benchmark::Stub> stub_;
- std::shared_ptr<grpc::Channel> channel_;
-};
-
-} // namespace benchmark
-} // namespace rpc_port
-
-#endif // GRPC_PROXY_HH_
+++ /dev/null
-syntax = "proto3";
-
-package grpcbench;
-
-// The greeting service definition.
-service Benchmark {
- rpc Test (TestRequest) returns (TestReply) {}
-}
-
-// The request message containing the user's name.
-message TestRequest {
- string data = 1;
-}
-
-// The response message containing the greetings
-message TestReply {
- int32 ret = 1;
-}
+++ /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 LOG_PRIVATE_HH_
-#define LOG_PRIVATE_HH_
-
-#include <dlog.h>
-
-#undef LOG_TAG
-#define LOG_TAG "RPC_PORT_BENCHMARK_TOOL"
-
-#undef _E
-#define _E LOGE
-
-#undef _W
-#define _W LOGW
-
-#undef _I
-#define _I LOGI
-
-#undef _D
-#define _D LOGD
-
-#endif // LOG_PRIVATE_HH_
+++ /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 <glib.h>
-#include <signal.h>
-#include <sys/types.h>
-#include <sys/wait.h>
-#include <unistd.h>
-
-#include <chrono>
-#include <ctime>
-#include <fstream>
-#include <iostream>
-#include <sstream>
-#include <string>
-
-#include "BenchmarkProxy.h"
-#include "dbus-proxy.hh"
-#include "grpc-proxy.hh"
-#include "log-private.hh"
-#include "options.hh"
-
-namespace {
-
-#define SERVER_PROC_NAME "d::org.tizen.appfw.rpc_port.benchmark"
-#define SERVER_BIN_TIDL "/usr/bin/rpc-port-benchmark-server-tidl"
-#define SERVER_BIN_DBUS "/usr/bin/rpc-port-benchmark-server-dbus"
-#define SERVER_BIN_GRPC "/usr/bin/rpc-port-benchmark-server-grpc"
-
-namespace bp = rpc_port::BenchmarkProxy::proxy;
-
-class ConnectionListener : public bp::Benchmark::IEventListener {
- public:
- void OnConnected() override {
- }
-
- void OnDisconnected() override {
- }
-
- void OnRejected() override {
- }
-};
-
-class Tester {
- public:
- Tester() {
- }
-
- ~Tester() {
- if (server_pid_ > 0) {
- if (kill(server_pid_, SIGTERM) != 0) {
- std::cerr << "kill() is failed. errno: " << errno << std::endl;
- } else {
- int status;
- waitpid(server_pid_, &status, 0);
- }
- }
- }
-
- void Run(int argc, char** argv) {
- options_ = rpc_port::benchmark::Options::Parse(argc, argv);
- if (!options_) {
- std::cerr << "options is unllptr" << std::endl;
- return;
- }
-
- if (options_->ShouldPrintTime()) PrintStartTime();
-
- ExecuteServer();
- if (options_->IsDbus()) {
- dbus_proxy_.Connect();
- } else if (options_->IsGrpc()) {
- grpc_proxy_.Connect();
- } else {
- std::string proc_name(SERVER_PROC_NAME);
- if (getuid() >= 5000) proc_name = "u" + proc_name;
-
- proxy_.reset(new bp::Benchmark(&listener_, proc_name.c_str()));
-
- try {
- proxy_->Connect(true);
- } catch (const bp::Exception& e) {
- std::cerr << "Connect() failed" << std::endl;
- return;
- } catch (const std::exception& e) {
- std::cerr << "Connect() failed. " << e.what() << std::endl;
- return;
- }
- }
-
- printf("%15s\t%15s\t%15s\t\t%15s\t\t%15s\n", "Iterations", "Data size",
- "Time", "Throughput", "Latency");
-
- try {
- if (options_->IsAll()) {
- DoTest(4000, 10);
- DoTest(4000, 20);
- DoTest(4000, 100);
- DoTest(4000, 200);
- DoTest(2000, 1000);
- DoTest(2000, 2000);
- DoTest(1000, 10000);
- DoTest(1000, 20000);
- DoTest(1000, 30000);
- DoTest(1000, 40000);
- DoTest(1000, 50000);
- DoTest(1000, 60000);
- DoTest(500, 100000);
- } else {
- DoTest(options_->GetIters(), options_->GetSize());
- }
- } catch (const bp::Exception& e) {
- std::cerr << "test failed" << std::endl;
- }
- }
-
- private:
- void DoTest(int iters, int size) {
- bool is_func = options_->IsFunction();
- bool is_dbus = options_->IsDbus();
- bool is_grpc = options_->IsGrpc();
-
- if (is_dbus) dbus_proxy_.Start(getpid());
-
- StartTime();
- for (int i = 0; i < iters; i++) {
- if (is_func) {
- int ret = FakeFunction(std::string(size, 'a'));
- if (ret != 0) {
- std::cerr << "Invalid return" << std::endl;
- break;
- }
-
- continue;
- }
-
- if (is_dbus) {
- int ret = dbus_proxy_.Test(std::string(size, 'a'));
- if (ret != 0) {
- std::cerr << "Invalid return" << std::endl;
- break;
- }
-
- continue;
- }
-
- if (is_grpc) {
- int ret = grpc_proxy_.Test(std::string(size, 'a'));
- if (ret != 0) {
- std::cerr << "Invalid return" << std::endl;
- break;
- }
-
- continue;
- }
-
- int ret = proxy_->Test(std::string(size, 'a'));
- if (ret != 0) {
- std::cerr << "Invalid return" << std::endl;
- break;
- }
- }
- EndTime(iters, size);
-
- if (is_dbus) dbus_proxy_.Stop(getpid());
- }
-
- int FakeFunction(std::string str) {
- return 0;
- }
-
- void StartTime() {
- start_ = std::chrono::system_clock::now();
- }
-
- void EndTime(int iters, int size) {
- std::chrono::duration<double> sec =
- std::chrono::system_clock::now() - start_;
- double t = size * iters * 8 / sec.count() / 1024 / 1024;
- double l = sec.count() * 1000 / iters;
-
- printf("%10d\t%10dByte\t%15.4fs\t%15.4fMb/s\t%15.4fms\n", iters, size,
- sec.count(), t, l);
- }
-
- void ExecuteServer() {
- bool is_dbus = options_->IsDbus();
- bool is_grpc = options_->IsGrpc();
- if (!is_grpc) return;
-
- server_pid_ = fork();
- if (server_pid_ == 0) {
- setsid();
- int ret;
- if (is_dbus) {
- char bin[] = { SERVER_BIN_DBUS };
- char* argv[] = { bin, nullptr, nullptr };
- ret = execv(argv[0], argv);
- } else if (is_grpc) {
- char bin[] = { SERVER_BIN_GRPC };
- char* argv[] = { bin, nullptr, nullptr };
- ret = execv(argv[0], argv);
- } else {
- char bin[] = { SERVER_BIN_TIDL };
- char* argv[] = { bin, nullptr, nullptr };
- ret = execv(argv[0], argv);
- }
- if (ret < 0) {
- std::cerr << "execv() is failed. errno: " << errno << std::endl;
- exit(-1);
- }
- } else if (server_pid_ == -1) {
- std::cerr << "fork() is failed. errno: " << errno << std::endl;
- exit(-1);
- } else {
- _W("benchmark server is running. pid: %d", server_pid_);
- usleep(100 * 1000);
- }
- }
-
- void PrintStartTime() {
- std::ifstream stat_file("/proc/self/stat");
- if (!stat_file) {
- _E("Failed to open stat");
- return;
- }
-
- std::string line;
- getline(stat_file, line);
- std::istringstream iss(line);
-
- std::string value;
- int pos = 21;
- for (int i = 0; i < pos; ++i) iss >> value;
-
- iss >> value;
- stat_file.close();
-
- long start_time = std::stol(value) / sysconf(_SC_CLK_TCK);
- time_t start_time_seconds = start_time;
- long start_time_microseconds = (start_time - start_time_seconds) * 1000000;
-
- std::time_t start_time_utc = std::time(nullptr) - start_time_seconds;
- std::tm* start_time_tm = std::localtime(&start_time_utc);
-
- char buffer[26];
- std::strftime(buffer, sizeof(buffer), "%Y-%m %H:%M:%S", start_time_tm);
-
- std::string result = buffer;
- result += ".";
- result += std::to_string(start_time_microseconds);
- result += " UTC";
-
- std::cout << "Program start time: [" << value << "] " << result
- << std::endl;
- }
-
- private:
- std::unique_ptr<rpc_port::benchmark::Options> options_;
- std::unique_ptr<bp::Benchmark> proxy_;
- ConnectionListener listener_;
- std::chrono::system_clock::time_point start_;
- pid_t server_pid_ = -1;
- rpc_port::benchmark::DbusProxy dbus_proxy_;
- rpc_port::benchmark::GrpcProxy grpc_proxy_;
-};
-
-} // namespace
-
-int main(int argc, char** argv) {
- try {
- Tester tester;
- tester.Run(argc, argv);
- } catch (const rpc_port::BenchmarkProxy::proxy::InvalidIOException& ie) {
- _E("InvalidIOException occurs");
- return -1;
- } catch (const std::bad_weak_ptr& be) {
- _E("bad_weak_ptr occurs. error(%s)", be.what());
- return -1;
- }
-
- return 0;
-}
+++ /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 <getopt.h>
-
-#include <iostream>
-#include <cstring>
-#include <memory>
-
-#include "options.hh"
-
-namespace rpc_port {
-namespace benchmark {
-
-Options::Options() {
- help_ = R"__option_cb(
-Usage:
- rpc-port-benchmark-tool [OPTION...]
-
-Help Options:
- -h, --help Show help options
-
-Additional Options:
- -f, --funct ion Use function call instead of RPC
- -d, --dbus Use Dbus method instead of TIDL RPC
- -g, --grpc Use gRPC over UDS instead of TIDL RPC
- -a, --all Test pre-defined test-cases
- -i, --interations=<Iterations> Iterations
- -s, --size=<Data size> Data size (byte)
- -t, --time Print starting time of this tool
-
-Application Options:
- -v, --version Show version information
-)__option_cb";
-}
-
-void Options::PrintUsage() {
- std::cerr << help_ << std::endl;
-}
-
-void Options::PrintVersion() {
- std::cerr << "rpc-port-benchmark-tool " << FULLVER << std::endl;
-}
-
-void Options::PrintSample() {
- std::cerr << "rpc-port-benchmark-tool -i 1000 -s 10000" << std::endl;
-}
-
-std::unique_ptr<Options> Options::Parse(int argc, char** argv) {
- bool cmd[CMD_MAX] = { false, };
- bool opt[OPT_MAX] = { false, };
- auto options = std::unique_ptr<Options>(new Options());
- int option_index = 0;
-
- struct option long_options[] = {
- {"version", no_argument, nullptr, 'v'},
- {"help", no_argument, nullptr, 'h'},
- {"iterations", required_argument, nullptr, 'i'},
- {"size", required_argument, nullptr, 's'},
- {"function", no_argument, nullptr, 'f'},
- {"dbus", no_argument, nullptr, 'd'},
- {"grpc", no_argument, nullptr, 'g'},
- {"all", no_argument, nullptr, 'a'},
- {"time", no_argument, nullptr, 't'},
- {0, 0, 0, 0}
- };
-
- while (true) {
- int c = getopt_long(argc, argv, "vhfdgati:s:", long_options,
- &option_index);
- if (c == -1)
- break;
-
- switch (c) {
- case 0:
- break;
-
- case 'v':
- cmd[CMD_VERSION] = true;
- break;
-
- case 'h':
- cmd[CMD_HELP] = true;
- break;
-
- case 'i':
- opt[OPT_ITER] = true;
- options->iters_ = std::stoi(optarg);
- break;
-
- case 's':
- opt[OPT_SIZE] = true;
- options->size_ = std::stoi(optarg);
- break;
-
- case 'f':
- opt[OPT_FUNCTION] = true;
- options->is_function_ = true;
- break;
-
- case 'd':
- opt[OPT_DBUS] = true;
- options->is_dbus_ = true;
- break;
-
- case 'g':
- opt[OPT_GRPC] = true;
- options->is_grpc_ = true;
- break;
-
- case 'a':
- opt[OPT_ALL] = true;
- options->is_all_ = true;
- break;
-
- case 't':
- opt[OPT_TIME] = true,
- options->should_print_time_ = true;
- break;
-
- default:
- cmd[CMD_HELP] = true;
- }
- }
-
- if (cmd[CMD_VERSION]) {
- options->PrintVersion();
- return std::unique_ptr<Options>(nullptr);
- }
-
- if (cmd[CMD_HELP]) {
- options->PrintUsage();
- return std::unique_ptr<Options>(nullptr);
- } else if (opt[OPT_ALL]) {
- return options;
- } else if (!opt[OPT_ITER] || !opt[OPT_SIZE]) {
- options->PrintSample();
- return std::unique_ptr<Options>(nullptr);
- }
-
- return options;
-}
-
-} // namespace benchmark
-} // namespace rpc_port
+++ /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 OPTIONS_HH_
-#define OPTIONS_HH_
-
-#include <string>
-#include <memory>
-
-namespace rpc_port {
-namespace benchmark {
-
-class Options {
- public:
- Options();
- ~Options() = default;
-
- static std::unique_ptr<Options> Parse(int argc, char** argv);
-
- int GetIters() const {
- return iters_;
- }
-
- int GetSize() const {
- return size_;
- }
-
- bool IsFunction() const {
- return is_function_;
- }
-
- bool IsAll() const {
- return is_all_;
- }
-
- bool IsDbus() const {
- return is_dbus_;
- }
-
- bool IsGrpc() const {
- return is_grpc_;
- }
-
- bool ShouldPrintTime() const {
- return should_print_time_;
- }
-
- private:
- enum Cmd {
- CMD_VERSION,
- CMD_HELP,
- CMD_MAX
- };
-
- enum Opt {
- OPT_ITER,
- OPT_SIZE,
- OPT_ALL,
- OPT_FUNCTION,
- OPT_DBUS,
- OPT_GRPC,
- OPT_TIME,
- OPT_MAX
- };
-
- void PrintUsage();
- void PrintVersion();
- void PrintSample();
-
- private:
- int iters_ = 0;
- int size_ = 0;
- std::string help_;
- bool is_function_ = false;
- bool is_all_ = false;
- bool is_dbus_ = false;
- bool is_grpc_ = false;
- bool should_print_time_ = false;
-};
-
-} // namespace benchmark
-} // namespace rpc_port
-
-#endif // OPTIONS_HH_
int rpc_port_parcel_reset_reader(rpc_port_parcel_h h);
-int rpc_port_parcel_to_array(rpc_port_parcel_h h, void **array,
- unsigned int *size);
+int rpc_port_parcel_to_array(rpc_port_parcel_h h, void** array,
+ unsigned int* size);
-int rpc_port_parcel_from_array(rpc_port_parcel_h h, const void *array,
- unsigned int size);
+int rpc_port_parcel_from_array(rpc_port_parcel_h h, const void* array,
+ unsigned int size);
int rpc_port_parcel_create_from_raw_without_header(rpc_port_parcel_h* h,
const void* raw,
unsigned int size);
int rpc_port_parcel_create_from_port_without_header(rpc_port_parcel_h* h,
- rpc_port_h port);
+ rpc_port_h port);
+int rpc_port_parcel_reserve(rpc_port_parcel_h h, unsigned int size);
+
+int rpc_port_parcel_create_from_parcel(rpc_port_parcel_h* h,
+ rpc_port_parcel_h origin_parcel,
+ unsigned int start_pos,
+ unsigned int size);
+int rpc_port_parcel_set_data_size(rpc_port_parcel_h h, unsigned int size);
+int rpc_port_parcel_get_data_size(rpc_port_parcel_h h, unsigned int* size);
+int rpc_port_parcel_pin(rpc_port_parcel_h h);
+int rpc_port_parcel_get_reader(rpc_port_parcel_h h, unsigned int* reader_pos);
+int rpc_port_parcel_set_reader(rpc_port_parcel_h h, unsigned int reader_pos);
#ifdef __cplusplus
}
+++ /dev/null
-[Unit]
-Description=RPC-Port Benchmark Client (DBus)
-
-[Service]
-SmackProcessLabel=System
-ExecStart=/bin/sh -l -c '/usr/bin/rpc-port-benchmark-tool -d -a -t > /tmp/rpc-port-benchmark-tool-dbus.log'
-
-[Install]
-WantedBy=sysinit.target
+++ /dev/null
-[Unit]
-Description=RPC-Port Benchmark Client (TIDL)
-After=rpc-port-benchmark-server-tidl.socket
-Requires=rpc-port-benchmark-server-tidl.socket
-
-[Service]
-SmackProcessLabel=System
-ExecStart=/bin/sh -l -c '/usr/bin/rpc-port-benchmark-tool -a -t > /tmp/rpc-port-benchmark-tool-tidl.log'
-
-[Install]
-WantedBy=sysinit.target
+++ /dev/null
-[Unit]
-Description=RPC-Port Benchmark Server (DBus)
-
-[Service]
-BusName=tizen.appfw.rpcport.benchmark.dbus
-Type=dbus
-SmackProcessLabel=System
-ExecStart=/usr/bin/rpc-port-benchmark-server-dbus
-
-[Install]
-WantedBy=sysinit.target
\ No newline at end of file
+++ /dev/null
-[Unit]
-Description=RPC-Port Benchmark Server (TIDL)
-After=rpc-port-benchmark-server-tidl.socket
-Requires=rpc-port-benchmark-server-tidl.socket
-
-[Service]
-User=app_fw
-Group=app_fw
-SmackProcessLabel=System
-ExecStart=/usr/bin/rpc-port-benchmark-server-tidl
-
-[Install]
-WantedBy=sysinit.target
\ No newline at end of file
+++ /dev/null
-[Unit]
-Description=RPC Port Benchmark Server (TIDL)
-DefaultDependencies=no
-Before=sockets.target
-
-[Socket]
-ListenStream=/run/aul/rpcport/.d::org.tizen.appfw.rpc_port.benchmark::Benchmark
-SocketMode=0666
-SmackLabelIPIn=*
-SmackLabelIPOut=@
-
-[Install]
-WantedBy=sockets.target
\ No newline at end of file
License: Apache-2.0
Source0: %{name}-%{version}.tar.gz
Source1001: %{name}.manifest
-Source1002: rpc-port-benchmark-server-dbus.service
-Source1003: rpc-port-benchmark-server-tidl.service
-Source1004: rpc-port-benchmark-server-tidl.socket
-Source1005: tizen.appfw.rpcport.benchmark.dbus.busname
-Source1006: tizen.appfw.rpcport.benchmark.dbus.service
-Source1007: rpc-port-benchmark-client-dbus.service
-Source1008: rpc-port-benchmark-client-tidl.service
BuildRequires: cmake
BuildRequires: pkgconfig(aul)
BuildRequires: pkgconfig(bundle)
BuildRequires: pkgconfig(pkgmgr-info)
BuildRequires: pkgconfig(tizen-shared-queue)
BuildRequires: pkgconfig(uuid)
-BuildRequires: pkgconfig(grpc)
-BuildRequires: pkgconfig(protobuf)
BuildRequires: pkgconfig(libsystemd)
BuildRequires: rust-tizen-bundle
BuildRequires: rust-mockall_double
BuildRequires: rust-mockall
BuildRequires: rust
-
%if 0%{?gcov:1}
BuildRequires: lcov
BuildRequires: zip
RPC Port gcov objects
%endif
-%package benchmark
-Summary: Benchmark tool for rpc-port
-Group: Application Framework/Testing
-Requires: %{name}
-
-%description benchmark
-Benchmark tool for rpc-port
-
%package -n rust-rpc-port
Summary: rpc-port for rust
Group: Rust/Libraries
%prep
%setup -q
cp %{SOURCE1001} .
-cp %{SOURCE1002} .
-cp %{SOURCE1003} .
-cp %{SOURCE1004} .
-cp %{SOURCE1005} .
-cp %{SOURCE1006} .
-cp %{SOURCE1007} .
-cp %{SOURCE1008} .
%build
%if 0%{?gcov:1}
%make_install
-mkdir -p %{buildroot}%{_unitdir}
-install -m 0644 %{SOURCE1002} %{buildroot}%{_unitdir}/rpc-port-benchmark-server-dbus.service
-install -m 0644 %{SOURCE1003} %{buildroot}%{_unitdir}/rpc-port-benchmark-server-tidl.service
-
-mkdir -p %{buildroot}%{_unitdir}/sockets.target.wants
-install -m 0644 %{SOURCE1004} %{buildroot}%{_unitdir}/rpc-port-benchmark-server-tidl.socket
-ln -sf ../rpc-port-benchmark-server-tidl.socket %{buildroot}%{_unitdir}/sockets.target.wants/rpc-port-benchmark-server-tidl.socket
-
-mkdir -p %{buildroot}%{_unitdir}/busnames.target.wants
-install -m 0644 %{SOURCE1005} %{buildroot}%{_unitdir}/tizen.appfw.rpcport.benchmark.dbus.busname
-ln -sf ../tizen.appfw.rpcport.benchmark.dbus.busname %{buildroot}%{_unitdir}/busnames.target.wants/tizen.appfw.rpcport.benchmark.dbus.busname
-
-mkdir -p %{buildroot}%{_datadir}/dbus-1/system-services
-install -m 0644 %{SOURCE1006} %{buildroot}%{_datadir}/dbus-1/system-services/tizen.appfw.rpcport.benchmark.dbus.service
-
-mkdir -p %{buildroot}%{_unitdir}/sysinit.target.wants
-install -m 0644 %{SOURCE1007} %{buildroot}%{_unitdir}/rpc-port-benchmark-client-dbus.service
-ln -sf ../rpc-port-benchmark-client-dbus.service %{buildroot}%{_unitdir}/sysinit.target.wants/rpc-port-benchmark-client-dbus.service
-
-install -m 0644 %{SOURCE1008} %{buildroot}%{_unitdir}/rpc-port-benchmark-client-tidl.service
-ln -sf ../rpc-port-benchmark-client-tidl.service %{buildroot}%{_unitdir}/sysinit.target.wants/rpc-port-benchmark-client-tidl.service
-
%if 0%{?gcov:1}
builddir=$(basename $PWD)
gcno_obj_dir=%{buildroot}%{_datadir}/gcov/obj/%{name}/"$builddir"
%{_datadir}/gcov/*
%endif
-%files benchmark
-%manifest %{name}.manifest
-%config %{_sysconfdir}/dbus-1/system.d/rpc-port-benchmark.conf
-%{_bindir}/rpc-port-benchmark-server-tidl
-%{_bindir}/rpc-port-benchmark-server-dbus
-%{_bindir}/rpc-port-benchmark-server-grpc
-%{_bindir}/rpc-port-benchmark-tool
-%attr(0644,root,root) %{_unitdir}/rpc-port-benchmark-server-tidl.service
-%attr(0644,root,root) %{_unitdir}/rpc-port-benchmark-server-tidl.socket
-%attr(0644,root,root) %{_unitdir}/sockets.target.wants/rpc-port-benchmark-server-tidl.socket
-%attr(0644,root,root) %{_unitdir}/rpc-port-benchmark-server-dbus.service
-%attr(0644,root,root) %{_unitdir}/tizen.appfw.rpcport.benchmark.dbus.busname
-%attr(0644,root,root) %{_unitdir}/busnames.target.wants/tizen.appfw.rpcport.benchmark.dbus.busname
-%attr(0644,root,root) %{_datadir}/dbus-1/system-services/tizen.appfw.rpcport.benchmark.dbus.service
-%attr(0644,root,root) %{_unitdir}/rpc-port-benchmark-client-tidl.service
-%attr(0644,root,root) %{_unitdir}/sysinit.target.wants/rpc-port-benchmark-client-tidl.service
-%attr(0644,root,root) %{_unitdir}/rpc-port-benchmark-client-dbus.service
-%attr(0644,root,root) %{_unitdir}/sysinit.target.wants/rpc-port-benchmark-client-dbus.service
-
%files -n rust-rpc-port
%manifest %{name}.manifest
%{_rust_dylibdir}/lib%{real_crate_name}.so
+++ /dev/null
-[Unit]
-Description=DBUS1:tizen.appfw.rpcport.benchmark.dbus
-Documentation=man:systemd
-DefaultDependencies=no
-
-[BusName]
-Name=tizen.appfw.rpcport.benchmark.dbus
-Service=rpc-port-benchmark-server-dbus.service
-AllowWorld=talk
\ No newline at end of file
+++ /dev/null
-[D-BUS Service]
-Name=tizen.appfw.rpcport.benchmark.dbus
-Exec=/bin/false
-SystemdService=rpc-port-benchmark-server-dbus.service
\ No newline at end of file
Parcel::Parcel(bool without_header)
: header_(without_header ? nullptr : new ParcelHeader()) {
+ handle_.reset(new tizen_base::Parcel());
+}
+
+Parcel::Parcel(bool without_header, tizen_base::Parcel* parcel)
+ : header_(without_header ? nullptr : new ParcelHeader()) {
+ handle_.reset(parcel);
}
Parcel::~Parcel() {}
void Parcel::WriteToParcel(tizen_base::Parcel* parcel) const {
if (header_.get() != nullptr) {
parcel->WriteParcelable(*header_.get());
- parcel->WriteUInt32(handle_.GetDataSize());
+ parcel->WriteUInt32(handle_->GetDataSize());
}
- parcel->Write(handle_.GetData(), handle_.GetDataSize());
+ parcel->Write(handle_->GetData(), handle_->GetDataSize());
}
void Parcel::ReadFromParcel(tizen_base::Parcel* parcel) {
auto* buf = static_cast<uint8_t*>(malloc(size));
if (buf == nullptr) {
_E("Out of memory"); // LCOV_EXEC_LINE
- return; // LCOV_EXCL_LINE
+ return; // LCOV_EXCL_LINE
}
parcel->Read(buf, size);
- handle_ = std::move(tizen_base::Parcel(buf, size, false));
+ handle_.reset(new tizen_base::Parcel(buf, size, false));
}
} else {
// LCOV_EXCL_START
- handle_ = std::move(
- tizen_base::Parcel(parcel->GetData(), parcel->GetDataSize()));
+ handle_.reset(
+ new tizen_base::Parcel(parcel->GetData(), parcel->GetDataSize()));
// LCOV_EXCL_STOP
}
}
-const ParcelHeader* Parcel::GetParcelHeader() {
- return header_.get();
-}
+const ParcelHeader* Parcel::GetParcelHeader() { return header_.get(); }
parcel_h Parcel::GetHandle() const {
- return static_cast<parcel_h>(const_cast<tizen_base::Parcel*>(&handle_));
+ return static_cast<parcel_h>(handle_.get());
}
void Parcel::SetRawParcel(tizen_base::Parcel* raw_parcel) {
raw_parcel_.reset(raw_parcel);
}
-// LCOV_EXCL_START
-tizen_base::Parcel* Parcel::GetRawParcel() const {
- return raw_parcel_.get();
-}
-// LCOV_EXCL_STOP
+tizen_base::Parcel* Parcel::GetRawParcel() const { return raw_parcel_.get(); }
} // namespace internal
} // namespace rpc_port
class Parcel : public tizen_base::Parcelable {
public:
Parcel(bool without_header = false);
+ Parcel(bool without_header, tizen_base::Parcel* parcel);
~Parcel();
void WriteToParcel(tizen_base::Parcel* parcel) const override;
const ParcelHeader* GetParcelHeader();
parcel_h GetHandle() const;
-
void SetRawParcel(tizen_base::Parcel* raw_parcel);
tizen_base::Parcel* GetRawParcel() const;
private:
std::unique_ptr<ParcelHeader> header_;
- tizen_base::Parcel handle_;
+ std::unique_ptr<tizen_base::Parcel> handle_;
std::unique_ptr<tizen_base::Parcel> raw_parcel_ { nullptr };
};
*h = static_cast<rpc_port_parcel_h>(parcel);
return RPC_PORT_ERROR_NONE;
}
+
+RPC_API int rpc_port_parcel_reserve(rpc_port_parcel_h h, unsigned int size) {
+ if (h == nullptr) return RPC_PORT_ERROR_INVALID_PARAMETER;
+
+ auto* parcel = static_cast<internal::Parcel*>(h);
+ auto* ih = static_cast<tizen_base::Parcel*>(parcel->GetHandle());
+ ih->Reserve(size);
+
+ return RPC_PORT_ERROR_NONE;
+}
+
+RPC_API int rpc_port_parcel_create_from_parcel(rpc_port_parcel_h* h,
+ rpc_port_parcel_h origin_parcel,
+ unsigned int start_pos,
+ unsigned int size) {
+ if (h == nullptr || origin_parcel == nullptr || size == 0)
+ return RPC_PORT_ERROR_INVALID_PARAMETER;
+
+ auto* parcel = static_cast<internal::Parcel*>(origin_parcel);
+ auto* ih = static_cast<tizen_base::Parcel*>(parcel->GetHandle());
+
+ try {
+ auto* new_parcel = new internal::Parcel(
+ true, new tizen_base::Parcel(*ih, start_pos, size));
+ *h = static_cast<rpc_port_parcel_h>(new_parcel);
+ } catch (...) {
+ return RPC_PORT_ERROR_OUT_OF_MEMORY;
+ }
+
+ return RPC_PORT_ERROR_NONE;
+}
+
+RPC_API int rpc_port_parcel_set_data_size(rpc_port_parcel_h h,
+ unsigned int size) {
+ if (h == nullptr) return RPC_PORT_ERROR_INVALID_PARAMETER;
+
+ auto* parcel = static_cast<internal::Parcel*>(h);
+ auto* ih = static_cast<tizen_base::Parcel*>(parcel->GetHandle());
+
+ if (!ih->SetDataSize(size)) return RPC_PORT_ERROR_INVALID_PARAMETER;
+
+ return RPC_PORT_ERROR_NONE;
+}
+
+RPC_API int rpc_port_parcel_get_data_size(rpc_port_parcel_h h,
+ unsigned int* size) {
+ if (h == nullptr || size == nullptr) return RPC_PORT_ERROR_INVALID_PARAMETER;
+
+ auto* parcel = static_cast<internal::Parcel*>(h);
+ auto* ih = static_cast<tizen_base::Parcel*>(parcel->GetHandle());
+ *size = ih->GetDataSize();
+
+ return RPC_PORT_ERROR_NONE;
+}
+
+RPC_API int rpc_port_parcel_pin(rpc_port_parcel_h h) {
+ if (h == nullptr) return RPC_PORT_ERROR_INVALID_PARAMETER;
+
+ auto* parcel = static_cast<internal::Parcel*>(h);
+ auto* ih = static_cast<tizen_base::Parcel*>(parcel->GetHandle());
+ ih->Pin();
+
+ return RPC_PORT_ERROR_NONE;
+}
+
+RPC_API int rpc_port_parcel_get_reader(rpc_port_parcel_h h,
+ unsigned int* reader_pos) {
+ if (h == nullptr || reader_pos == nullptr)
+ return RPC_PORT_ERROR_INVALID_PARAMETER;
+
+ auto* parcel = static_cast<internal::Parcel*>(h);
+ auto* ih = static_cast<tizen_base::Parcel*>(parcel->GetHandle());
+ *reader_pos = ih->GetReader();
+
+ return RPC_PORT_ERROR_NONE;
+}
+
+RPC_API int rpc_port_parcel_set_reader(rpc_port_parcel_h h,
+ unsigned int reader_pos) {
+ if (h == nullptr) return RPC_PORT_ERROR_INVALID_PARAMETER;
+
+ auto* parcel = static_cast<internal::Parcel*>(h);
+ auto* ih = static_cast<tizen_base::Parcel*>(parcel->GetHandle());
+
+ if (!ih->SetReader(reader_pos)) return RPC_PORT_ERROR_INVALID_PARAMETER;
+
+ return RPC_PORT_ERROR_NONE;
+}
* limitations under the License.
*/
-#include <dlog.h>
#include <gmock/gmock.h>
#include <gtest/gtest.h>
-#include <stdarg.h>
#include <stdio.h>
-// LCOV_EXCL_START
-extern "C" int __dlog_sec_print(log_id_t log_id, int prio, const char* tag,
- const char* fmt, ...) {
- printf("%s:", tag);
- va_list ap;
- va_start(ap, fmt);
- vprintf(fmt, ap);
- va_end(ap);
- printf("\n");
- return 0;
-}
-
-extern "C" int dlog_vprint(log_priority prio, const char* tag, const char* fmt,
- va_list ap) {
- printf("%s:", tag);
- vprintf(fmt, ap);
- printf("\n");
- return 0;
-}
+#ifdef LOG_INTERNAL
+#include <dlog.h>
extern "C" int __dlog_print(log_id_t log_id, int prio, const char* tag,
const char* fmt, ...) {
vprintf(fmt, ap);
va_end(ap);
printf("\n");
+
return 0;
}
-// LCOV_EXCL_STOP
+#endif
int main(int argc, char** argv) {
testing::InitGoogleTest(&argc, argv);
* limitations under the License.
*/
-#include <gtest/gtest.h>
#include <gmock/gmock.h>
+#include <gtest/gtest.h>
+#include <stdbool.h>
+
#include <iostream>
#include <memory>
-#include <stdbool.h>
#include <stdexcept>
-#include "rpc-port-parcel.h"
#include "rpc-port-parcel-internal.h"
+#include "rpc-port-parcel.h"
using ::testing::AtLeast;
namespace {
class CStringHolder {
public:
- explicit CStringHolder(char* ptr) noexcept
- : ptr_(ptr) {}
+ explicit CStringHolder(char* ptr) noexcept : ptr_(ptr) {}
~CStringHolder() {
- if (ptr_)
- free(ptr_);
+ if (ptr_) free(ptr_);
}
- const char* Get() const {
- return ptr_;
- }
+ const char* Get() const { return ptr_; }
private:
char* ptr_;
}
TEST_F(ParcelTest, rpc_port_parcel_read_write_P) {
- rpc_port_parcelable_t p = {
- .to = WriteParcelable,
- .from = ReadParcelable
- };
+ rpc_port_parcelable_t p = {.to = WriteParcelable, .from = ReadParcelable};
int ret = rpc_port_parcel_write(handle_, &p, this);
ASSERT_EQ(ret, 0);
}
TEST_F(ParcelTest, rpc_port_parcel_burst_read_write_P) {
- unsigned char buf[] = { 0, 1, 2, 3, 4 };
+ unsigned char buf[] = {0, 1, 2, 3, 4};
int ret = rpc_port_parcel_burst_write(handle_, buf, sizeof(buf));
ASSERT_EQ(ret, 0);
- unsigned char buf2[5] = { 0, };
+ unsigned char buf2[5] = {
+ 0,
+ };
ret = rpc_port_parcel_burst_read(handle_, buf2, sizeof(buf));
ASSERT_EQ(ret, 0);
for (int i = 0; i < 5; i++) {
int ret = rpc_port_parcel_get_header(handle_, &header);
ASSERT_EQ(ret, RPC_PORT_ERROR_NONE);
- struct timespec timestamp = { 0, };
+ struct timespec timestamp = {
+ 0,
+ };
ret = rpc_port_parcel_header_get_timestamp(header, ×tamp);
ASSERT_EQ(ret, RPC_PORT_ERROR_NONE);
ASSERT_EQ(ret, RPC_PORT_ERROR_NONE);
std::unique_ptr<std::remove_pointer<rpc_port_parcel_h>::type,
- decltype(rpc_port_parcel_destroy)*> parcel_auto(
- parcel, rpc_port_parcel_destroy);
+ decltype(rpc_port_parcel_destroy)*>
+ parcel_auto(parcel, rpc_port_parcel_destroy);
char* str = nullptr;
ret = rpc_port_parcel_read_string(parcel, &str);
ASSERT_NE(parcel, nullptr);
std::unique_ptr<std::remove_pointer<rpc_port_parcel_h>::type,
- decltype(rpc_port_parcel_destroy)*> parcel_auto(
- parcel, rpc_port_parcel_destroy);
+ decltype(rpc_port_parcel_destroy)*>
+ parcel_auto(parcel, rpc_port_parcel_destroy);
rpc_port_parcel_header_h header = nullptr;
ret = rpc_port_parcel_get_header(parcel, &header);
char* array = nullptr;
unsigned int size = 0;
ret = rpc_port_parcel_to_array(handle_, reinterpret_cast<void**>(&array),
- &size);
+ &size);
std::unique_ptr<char, decltype(std::free)*> array_auto(array, std::free);
ASSERT_EQ(ret, RPC_PORT_ERROR_NONE);
ASSERT_NE(array, nullptr);
int ret = rpc_port_parcel_to_array(nullptr, nullptr, nullptr);
ASSERT_EQ(ret, RPC_PORT_ERROR_INVALID_PARAMETER);
}
+
+TEST_F(ParcelTest, rpc_port_parcel_get_set_data_size) {
+ int ret = rpc_port_parcel_write_string(handle_, "test");
+ ASSERT_EQ(ret, RPC_PORT_ERROR_NONE);
+
+ ret = rpc_port_parcel_set_data_size(handle_, 4);
+ ASSERT_EQ(ret, RPC_PORT_ERROR_NONE);
+
+ unsigned int size = 0;
+ ret = rpc_port_parcel_get_data_size(handle_, &size);
+ ASSERT_EQ(ret, RPC_PORT_ERROR_NONE);
+ ASSERT_EQ(size, 4);
+}
+
+TEST_F(ParcelTest, rpc_port_parcel_reserve) {
+ int ret = rpc_port_parcel_write_string(handle_, "test");
+ ASSERT_EQ(ret, RPC_PORT_ERROR_NONE);
+ ret = rpc_port_parcel_set_data_size(handle_, 0);
+ ASSERT_EQ(ret, RPC_PORT_ERROR_NONE);
+
+ ret = rpc_port_parcel_reserve(handle_, 4);
+ ASSERT_EQ(ret, RPC_PORT_ERROR_NONE);
+
+ unsigned int new_size = 0;
+ ret = rpc_port_parcel_get_data_size(handle_, &new_size);
+ ASSERT_EQ(ret, RPC_PORT_ERROR_NONE);
+
+ ASSERT_EQ(new_size, 4);
+}
+
+TEST_F(ParcelTest, rpc_port_parcel_pin) {
+ int ret = rpc_port_parcel_write_string(handle_, "test");
+ ASSERT_EQ(ret, RPC_PORT_ERROR_NONE);
+ ret = rpc_port_parcel_pin(handle_);
+ ASSERT_EQ(ret, RPC_PORT_ERROR_NONE);
+
+ rpc_port_parcel_h new_handle = nullptr;
+ ret = rpc_port_parcel_create_from_parcel(&new_handle, handle_, 0, 4);
+ ASSERT_EQ(ret, RPC_PORT_ERROR_NONE);
+
+ ret = rpc_port_parcel_destroy(new_handle);
+ ASSERT_EQ(ret, RPC_PORT_ERROR_NONE);
+}
+
+TEST_F(ParcelTest, rpc_port_parcel_create_from_parcel) {
+ unsigned int data_size1 = 0;
+ unsigned int data_size2 = 0;
+ rpc_port_parcel_write_string(handle_, "test");
+ rpc_port_parcel_get_data_size(handle_, &data_size1);
+ rpc_port_parcel_write_string(handle_, "str1");
+ rpc_port_parcel_get_data_size(handle_, &data_size2);
+ rpc_port_parcel_pin(handle_);
+
+ rpc_port_parcel_h new_handle = nullptr;
+ int ret = rpc_port_parcel_create_from_parcel(&new_handle, handle_, data_size1,
+ data_size2 - data_size1);
+ ASSERT_EQ(ret, RPC_PORT_ERROR_NONE);
+ rpc_port_parcel_reserve(new_handle, data_size2 - data_size1);
+
+ char* str = nullptr;
+ ret = rpc_port_parcel_read_string(new_handle, &str);
+ ASSERT_EQ(ret, RPC_PORT_ERROR_NONE);
+ ASSERT_STREQ(str, "str1");
+ free(str);
+
+ ret = rpc_port_parcel_destroy(new_handle);
+ ASSERT_EQ(ret, RPC_PORT_ERROR_NONE);
+}
+
+TEST_F(ParcelTest, rpc_port_parcel_create_from_parcel_N) {
+ int ret = rpc_port_parcel_write_string(handle_, "test");
+ ASSERT_EQ(ret, RPC_PORT_ERROR_NONE);
+
+ rpc_port_parcel_h new_handle = nullptr;
+ ret = rpc_port_parcel_create_from_parcel(&new_handle, handle_, 0, 4);
+ ASSERT_EQ(ret, RPC_PORT_ERROR_OUT_OF_MEMORY);
+}