" <method name='ExchangeCapabilities'>"
" <arg type='b' name='result' direction='out'/>"
" </method>"
- " <method name='GetRemoteCapabilities'>"
- " <arg type='v' name='result' direction='out'/>"
- " </method>"
" <method name='SendRemoteAppControl'>"
" <arg type='s' name='device_id' direction='in'/>"
" <arg type='ay' name='appcontrol' direction='in'/>"
EventHandler().send_app_control_event.connect(handler);
}
-void DBusService::RegisterGetRemoteCapsHandler(const std::string& method,
- std::function<void(GVariant**)> handler) {
- if (method == "GetRemoteCapabilities")
- EventHandler().get_remote_caps_event.connect(handler);
-}
-
bool DBusService::HandleDiscoverUnownedDevices(GVariant* params,
GDBusMethodInvocation* invocation) {
EventHandler().on_event();
}
g_variant_iter_free(iter);
- EventHandler().send_app_control_event(device_id, data, len);
+ boost::optional<bool> r =
+ EventHandler().send_app_control_event(device_id, data, len);
+ bool res = r ? *r : false;
+ g_dbus_method_invocation_return_value(invocation, g_variant_new("(b)", res));
return true;
}
-void DBusService::HandleGetRemoteCapabilities(GVariant* params,
- GDBusMethodInvocation* invocation) {
- GVariant* temp;
- EventHandler().get_remote_caps_event(&temp);
-
- g_dbus_method_invocation_return_value(invocation, g_variant_new("(v)", temp));
-}
-
void DBusService::HandleMethodCall(GDBusConnection* /* connection */,
const gchar* /* sender */, const gchar* /* object_path */,
const gchar* /* interface_name */, const gchar* method_name,
r = HandleDiscoverUnownedDevices(parameters, invocation);
} else if (g_strcmp0("ExchangeCapabilities", method_name) == 0) {
r = HandleExchangeCapabilities(parameters, invocation);
- } else if (g_strcmp0("GetRemoteCapabilities", method_name) == 0) {
- HandleGetRemoteCapabilities(parameters, invocation);
- return;
} else if (g_strcmp0("SendRemoteAppControl", method_name) == 0) {
LOG(INFO) << " method call: " << method_name;
HandleSendRemoteAppControl(parameters, invocation);
#include <iostream>
+#include "client/include/capmgr.h"
+
namespace bpo = boost::program_options;
namespace {
const char kDBusObjectPath[] = "/org/tizen/capmgr";
const char kDBusInterfaceName[] = "org.tizen.capmgr";
+struct cbdata {
+ capmgr_device_h* device;
+ std::string device_id;
+};
+
class Client {
public:
- Client() {
- GError* error = nullptr;
- conn_ = g_bus_get_sync(G_BUS_TYPE_SYSTEM, nullptr, &error);
- if (!conn_ || error) {
- std::cout << "g_bus_get_sync() failed: " << error->message << std::endl;
- exit(1);
- }
+ Client();
+ ~Client();
+
+ void Discover(GVariant* params);
+ void CapExchange(GVariant* params);
+ void SendAppControl(const std::string& device_id, const std::string& appid);
+ void ListDevices();
- proxy_ = g_dbus_proxy_new_sync(conn_, G_DBUS_PROXY_FLAGS_NONE, nullptr,
- kDBusServiceName, kDBusObjectPath, kDBusInterfaceName, nullptr, &error);
- if (!proxy_ || error) {
- std::cout << "g_dbus_proxy_new_sync() failed: " << error->message
- << std::endl;
- exit(1);
+ private:
+ GVariant* ProxyCallSync(const char* method, GVariant* params);
+
+ GDBusConnection* conn_;
+ GDBusProxy* proxy_;
+};
+
+int DeviceForeachCb(const capmgr_device_h device, void* user_data) {
+ char* device_id = nullptr;
+ char* model_name = nullptr;
+ char* device_name = nullptr;
+ char* platform_ver = nullptr;
+ char* profile = nullptr;
+ char* sw_ver = nullptr;
+
+ int ret = capmgr_device_get_device_id(device, &device_id);
+ if (ret != CAPMGR_ERROR_NONE)
+ std::cout << "Failed to get device id" << std::endl;
+
+ ret = capmgr_device_get_model_name(device, &model_name);
+ if (ret != CAPMGR_ERROR_NONE)
+ std::cout << "Failed to get model name" << std::endl;
+
+ ret = capmgr_device_get_device_name(device, &device_name);
+ if (ret != CAPMGR_ERROR_NONE)
+ std::cout << "Failed to get device name" << std::endl;
+
+ ret = capmgr_device_get_platform_ver(device, &platform_ver);
+ if (ret != CAPMGR_ERROR_NONE)
+ std::cout << "Failed to get platform version" << std::endl;
+
+ ret = capmgr_device_get_profile(device, &profile);
+ if (ret != CAPMGR_ERROR_NONE)
+ std::cout << "Failed to get profile" << std::endl;
+
+ ret = capmgr_device_get_sw_ver(device, &sw_ver);
+ if (ret != CAPMGR_ERROR_NONE)
+ std::cout << "Failed to get sw version" << std::endl;
+
+ if (user_data) {
+ struct cbdata* cbdata = reinterpret_cast<struct cbdata*>(user_data);
+ if (!strcmp(device_id, cbdata->device_id.c_str())) {
+ ret = capmgr_device_clone(device, cbdata->device);
+ if (ret != CAPMGR_ERROR_NONE)
+ std::cout << "capmgr_device_clone() failed: " << ret << std::endl;
}
+ } else {
+ std::cout << "==============================================" << std::endl;
+ std::cout << "DeviceID: " << device_id << std::endl
+ << "Model name: " << model_name << std::endl
+ << "Device name: " << device_name << std::endl
+ << "Platform version: " << platform_ver << std::endl
+ << "Profile: " << profile << std::endl
+ << "SW version: " << sw_ver << std::endl;
}
- ~Client() {
- g_object_unref(proxy_);
- g_dbus_connection_flush_sync(conn_, nullptr, nullptr);
- g_object_unref(conn_);
+ free(device_id);
+ free(model_name);
+ free(device_name);
+ free(platform_ver);
+ free(profile);
+ free(sw_ver);
+
+ return 0;
+}
+
+Client::Client() {
+ GError* error = nullptr;
+ conn_ = g_bus_get_sync(G_BUS_TYPE_SYSTEM, nullptr, &error);
+ if (!conn_ || error) {
+ std::cout << "g_bus_get_sync() failed: " << error->message << std::endl;
+ exit(1);
}
- void PrintUsage() {
- std::cout << "Usage: ??" << std::endl;
+ proxy_ = g_dbus_proxy_new_sync(conn_, G_DBUS_PROXY_FLAGS_NONE, nullptr,
+ kDBusServiceName, kDBusObjectPath, kDBusInterfaceName, nullptr, &error);
+ if (!proxy_ || error) {
+ std::cout << "g_dbus_proxy_new_sync() failed: " << error->message
+ << std::endl;
+ exit(1);
}
+}
+
+Client::~Client() {
+ g_object_unref(proxy_);
+ g_dbus_connection_flush_sync(conn_, nullptr, nullptr);
+ g_object_unref(conn_);
+}
- void Discover(GVariant* params) {
- GVariant* ret = ProxyCallSync("DiscoverUnownedDevices", params);
- if (!ret)
- return;
+void Client::Discover(GVariant* params) {
+ GVariant* ret = ProxyCallSync("DiscoverUnownedDevices", params);
+ if (!ret)
+ return;
- g_variant_unref(ret);
+ g_variant_unref(ret);
+}
+
+void Client::CapExchange(GVariant* params) {
+ GVariant* ret = ProxyCallSync("ExchangeCapabilities", params);
+ if (!ret)
+ return;
+
+ g_variant_unref(ret);
+}
+
+void Client::SendAppControl(const std::string& device_id,
+ const std::string& appid) {
+ if (device_id.empty()) {
+ std::cout << "Target device is missing!" << std::endl;
+ return;
}
- void CapExchange(GVariant* params) {
- GVariant* ret = ProxyCallSync("ExchangeCapabilities", params);
- if (!ret)
- return;
+ capmgr_device_h device = nullptr;
+ struct cbdata cbdata = {&device, device_id};
+ int ret = capmgr_device_foreach_devices(DeviceForeachCb, &cbdata);
+ if (ret != CAPMGR_ERROR_NONE) {
+ std::cout << "capmgr_device_foreach_devices() failed: " << ret
+ << std::endl;
+ return;
+ }
- g_variant_unref(ret);
+ if (*cbdata.device == nullptr) {
+ std::cout << "There is no such device!" << std::endl;
+ return;
}
- void SendAppControl(GVariant* params) {
- GVariant* ret = ProxyCallSync("SendRemoteAppControl", params);
- if (!ret)
- return;
+ capmgr_app_control_h ac;
+ ret = capmgr_app_control_create(&ac);
+ if (ret != CAPMGR_ERROR_NONE) {
+ std::cout << "capmgr_app_control_create() failed: " << ret << std::endl;
+ capmgr_device_destroy(device);
+ return;
+ }
- g_variant_unref(ret);
+ ret = capmgr_app_control_set_device(ac, device);
+ if (ret != CAPMGR_ERROR_NONE) {
+ std::cout << "capmgr_app_control_set_device() failed: " << ret
+ << std::endl;
+ capmgr_device_destroy(device);
+ capmgr_app_control_destroy(ac);
+ return;
}
- private:
- GVariant* ProxyCallSync(const char* method, GVariant* params) {
- GError* error = nullptr;
- GVariant* ret = g_dbus_proxy_call_sync(proxy_, method,
- params, G_DBUS_CALL_FLAGS_NONE, -1, nullptr, &error);
- if (error) {
- std::cout << "g_dbus_proxy_call_sync of " << method << " failed: "
- << error->message << std::endl;
- }
- return ret;
+ ret = capmgr_app_control_set_appid(ac, appid.c_str());
+ if (ret != CAPMGR_ERROR_NONE) {
+ std::cout << "capmgr_app_control_set_appid() failed: " << ret
+ << std::endl;
+ capmgr_device_destroy(device);
+ capmgr_app_control_destroy(ac);
+ return;
}
- GDBusConnection* conn_;
- GDBusProxy* proxy_;
-};
+ ret = capmgr_app_control_send(ac);
+ if (ret != CAPMGR_ERROR_NONE)
+ std::cout << "capmgr_app_control_set_appid() failed: " << ret
+ << std::endl;
+
+ capmgr_device_destroy(device);
+ capmgr_app_control_destroy(ac);
+}
+
+void Client::ListDevices() {
+ int ret = capmgr_device_foreach_devices(DeviceForeachCb, nullptr);
+ if (ret != CAPMGR_ERROR_NONE)
+ std::cout << "capmgr_device_foreach_devices() failed: " << ret
+ << std::endl;
+}
+
+GVariant* Client::ProxyCallSync(const char* method, GVariant* params) {
+ GError* error = nullptr;
+ GVariant* ret = g_dbus_proxy_call_sync(proxy_, method,
+ params, G_DBUS_CALL_FLAGS_NONE, -1, nullptr, &error);
+ if (error) {
+ std::cout << "g_dbus_proxy_call_sync of " << method << " failed: "
+ << error->message << std::endl;
+ }
+ return ret;
+}
} // namespace
try {
options.add_options()
("help,h", "help")
- ("discovery,d", "discover devices&capabilities")
+ ("discovery,f", "discover devices&capabilities")
("capexchange,c", "capability exchange")
- ("send-appcontrol,s", "send remote app-control");
+ ("device,d", bpo::value<std::string>(), "device id")
+ ("send-appcontrol,s", bpo::value<std::string>(),
+ "send remote app-control")
+ ("list-devices,l", "list remote devices");
bpo::store(bpo::parse_command_line(argc, argv, options), opt_map);
if (opt_map.count("help"))
- client.PrintUsage();
+ std::cout << options << std::endl;
else if (opt_map.count("discovery"))
client.Discover(nullptr);
else if (opt_map.count("capexchange"))
client.CapExchange(nullptr);
else if (opt_map.count("send-appcontrol"))
- client.SendAppControl(nullptr);
+ client.SendAppControl(opt_map["device"].as<std::string>(),
+ opt_map["send-appcontrol"].as<std::string>());
+ else if (opt_map.count("list-devices"))
+ client.ListDevices();
} catch (...) {
std::cout << "Exception occured" << std::endl;
}