From 01b59a4da5950f7c725b56a1fa23d7d1c7de311a Mon Sep 17 00:00:00 2001 From: Perry Werneck Date: Tue, 1 Oct 2019 15:24:22 -0300 Subject: [PATCH] Fixing "set property" linux method. --- client/src/core/linux/request.cc | 42 +++++++++++++++++++++++++++++++++++------- client/src/include/lib3270/ipc/request.h | 7 ++++--- client/src/session/remote/attribute.cc | 68 +++++++++----------------------------------------------------------- client/src/session/remote/linux/request.cc | 3 +++ client/src/testprogram/testprogram.cc | 4 ++-- 5 files changed, 53 insertions(+), 71 deletions(-) diff --git a/client/src/core/linux/request.cc b/client/src/core/linux/request.cc index 9587d01..b4b6ed3 100644 --- a/client/src/core/linux/request.cc +++ b/client/src/core/linux/request.cc @@ -37,6 +37,7 @@ */ #include + #include using std::string; @@ -46,8 +47,10 @@ IPC::Request::Request(DBusConnection * conn) { this->conn = conn; - this->response.msg = nullptr; - this->request.msg = nullptr; + + memset(&response,0,sizeof(response)); + memset(&request,0,sizeof(request)); + } IPC::Request::~Request() { @@ -87,11 +90,36 @@ IPC::Request & IPC::Request::push(int type, const void *value) { - if (!dbus_message_iter_append_basic(&request.iter,type,value)) { - throw std::runtime_error("Can't append value"); - } + if(request.variant) { + + // Is variant + DBusMessageIter iter; + char signature[] = { (char) type, 0 }; + + if(!dbus_message_iter_open_container(&request.iter, DBUS_TYPE_VARIANT, signature, &iter)) { + throw std::runtime_error("Can't open variant"); + } + + if(!dbus_message_iter_append_basic(&iter,type,value)) { + dbus_message_iter_close_container(&request.iter, &iter); + throw std::runtime_error("Can't append variant"); + } + + if (!dbus_message_iter_close_container(&request.iter, &iter)) { + throw std::runtime_error("Can't close variant"); + } + + return *this; + + } else { - return *this; + // Basic type. + if(dbus_message_iter_append_basic(&request.iter,type,value)) + return *this; + + } + + throw std::runtime_error("Can't append value"); } @@ -302,7 +330,7 @@ } - debug("Argument type is ", ((char) dbus_message_iter_get_arg_type(&iter)) ); + debug("Argument type is %d", ((int) dbus_message_iter_get_arg_type(&iter)) ); throw std::runtime_error("Expected an integer data type"); } diff --git a/client/src/include/lib3270/ipc/request.h b/client/src/include/lib3270/ipc/request.h index b8f2d10..bca63b3 100644 --- a/client/src/include/lib3270/ipc/request.h +++ b/client/src/include/lib3270/ipc/request.h @@ -113,9 +113,10 @@ /// @brief Message who will be sent to server. struct { - DBusMessage * msg; - DBusMessageIter iter; - } request; + DBusMessage * msg; ///< @brief The request message. + DBusMessageIter iter; ///< @brief Arguments iter. + bool variant; ///< @brief Put arguments as variants? + } request; DBusConnection * conn; diff --git a/client/src/session/remote/attribute.cc b/client/src/session/remote/attribute.cc index 72d83cd..3e4a0f3 100644 --- a/client/src/session/remote/attribute.cc +++ b/client/src/session/remote/attribute.cc @@ -115,16 +115,10 @@ set.asInt32 = [](const Attribute & attr, const void *worker, const int32_t value) { const struct Worker * w = (const struct Worker *) worker; - int32_t rc; IPC::Request(*w->session,true,w->methods->name) .push(value) - .call() - .pop(rc); - - if(rc) { - throw std::system_error((int) rc, std::system_category()); - } + .call(); }; @@ -135,12 +129,7 @@ IPC::Request(*w->session,true,w->methods->name) .push(value) - .call() - .pop(rc); - - if(rc) { - throw std::system_error((int) rc, std::system_category()); - } + .call(); }; @@ -185,32 +174,20 @@ set.asInt32 = [](const Attribute & attr, const void *worker, const int32_t value) { const struct Worker * w = (const struct Worker *) worker; - int32_t rc; IPC::Request(*w->session,true,w->methods->name) .push(value) - .call() - .pop(rc); - - if(rc) { - throw std::system_error((int) rc, std::system_category()); - } + .call(); }; set.asBoolean = [](const Attribute & attr, const void *worker, const bool value) { const struct Worker * w = (const struct Worker *) worker; - int32_t rc; IPC::Request(*w->session,true,w->methods->name) .push(value) - .call() - .pop(rc); - - if(rc) { - throw std::system_error((int) rc, std::system_category()); - } + .call(); }; } @@ -259,12 +236,7 @@ IPC::Request(*w->session,true,w->methods->name) .push(value) - .call() - .pop(rc); - - if(rc) { - throw std::system_error((int) rc, std::system_category()); - } + .call(); }; @@ -275,12 +247,7 @@ IPC::Request(*w->session,true,w->methods->name) .push(value) - .call() - .pop(rc); - - if(rc) { - throw std::system_error((int) rc, std::system_category()); - } + .call(); }; @@ -328,44 +295,27 @@ IPC::Request(*w->session,true,w->methods->name) .push(value) - .call() - .pop(rc); - - if(rc) { - throw std::system_error((int) rc, std::system_category()); - } + .call(); }; set.asInt32 = [](const Attribute & attr, const void *worker, const int32_t value) { const struct Worker * w = (const struct Worker *) worker; - int32_t rc; IPC::Request(*w->session,true,w->methods->name) .push(std::to_string(value).c_str()) - .call() - .pop(rc); - - if(rc) { - throw std::system_error((int) rc, std::system_category()); - } + .call(); }; set.asUint32 = [](const Attribute & attr, const void *worker, const uint32_t value) { const struct Worker * w = (const struct Worker *) worker; - int32_t rc; IPC::Request(*w->session,true,w->methods->name) .push(std::to_string(value).c_str()) - .call() - .pop(rc); - - if(rc) { - throw std::system_error((int) rc, std::system_category()); - } + .call(); }; diff --git a/client/src/session/remote/linux/request.cc b/client/src/session/remote/linux/request.cc index e7c2505..96a1df7 100644 --- a/client/src/session/remote/linux/request.cc +++ b/client/src/session/remote/linux/request.cc @@ -92,6 +92,9 @@ push(DBUS_TYPE_STRING,&interface_name); push(DBUS_TYPE_STRING,&property); + // Set property argument should be variant! + this->request.variant = isSet; + } } diff --git a/client/src/testprogram/testprogram.cc b/client/src/testprogram/testprogram.cc index 377bb86..4dacefd 100644 --- a/client/src/testprogram/testprogram.cc +++ b/client/src/testprogram/testprogram.cc @@ -201,9 +201,9 @@ cout << "pre: " << host["url"] << endl; - // host["url"] = "http://www.google.com.br"; + host["url"] = "http://www.google.com.br"; - // cout << "post: " << host["url"] << endl; + cout << "post: " << host["url"] << endl; } -- libgit2 0.21.2