3
Fork 0
This commit is contained in:
Artem Prilutskiy 2016-12-30 13:34:07 +03:00
parent 143fb78682
commit c937c9b2d6
4 changed files with 62 additions and 28 deletions

View file

@ -48,22 +48,13 @@ uint32_t PatchCordProxy::getTalkerID()
void PatchCordProxy::setTalkerAlias(const char* value)
{
size_t length = strlen(value);
const uint32_t* data = (const uint32_t*)value;
size_t index = VALUE_CORD_TALKER_ALIAS;
size_t count =
(length / sizeof(uint32_t)) +
((length % sizeof(uint32_t)) > 0);
char* buffer;
asprintf(&buffer, "set alias %s", value);
getContextBanner();
while (count > 0)
{
setSpecificValue(index, *data);
count --;
index ++;
data ++;
}
invokeCommand(buffer);
free(buffer);
}
void PatchCordProxy::getContextBanner()
@ -101,6 +92,31 @@ void PatchCordProxy::getContextBanner()
dbus_message_unref(message);
}
void PatchCordProxy::invokeCommand(const char* command)
{
DBusMessage* message = dbus_message_new_method_call(
name, OBJECT_PATH, INTERFACE_NAME, "invokeCommand");
dbus_message_append_args(message,
DBUS_TYPE_STRING, &banner,
DBUS_TYPE_STRING, &command,
DBUS_TYPE_INVALID);
DBusPendingCall* pending;
if (dbus_connection_send_with_reply(connection, message, &pending, -1))
{
dbus_connection_flush(connection);
dbus_message_unref(message);
dbus_pending_call_block(pending);
message = dbus_pending_call_steal_reply(pending);
dbus_pending_call_unref(pending);
}
dbus_message_unref(message);
// Each call of dbus_message_unref removes banner from the heap
banner = NULL;
}
void PatchCordProxy::setSpecificValue(uint32_t key, uint32_t value)
{
DBusMessage* message = dbus_message_new_method_call(

View file

@ -26,6 +26,7 @@ class PatchCordProxy
char* banner;
void getContextBanner();
void invokeCommand(const char* command);
void setSpecificValue(uint32_t key, uint32_t value);
uint32_t getSpecificValue(uint32_t key);

View file

@ -48,22 +48,13 @@ uint32_t PatchCordProxy::getTalkerID()
void PatchCordProxy::setTalkerAlias(const char* value)
{
size_t length = strlen(value);
const uint32_t* data = (const uint32_t*)value;
size_t index = VALUE_CORD_TALKER_ALIAS;
size_t count =
(length / sizeof(uint32_t)) +
((length % sizeof(uint32_t)) > 0);
char* buffer;
asprintf(&buffer, "set alias %s", value);
getContextBanner();
while (count > 0)
{
setSpecificValue(index, *data);
count --;
index ++;
data ++;
}
invokeCommand(buffer);
free(buffer);
}
void PatchCordProxy::getContextBanner()
@ -101,6 +92,31 @@ void PatchCordProxy::getContextBanner()
dbus_message_unref(message);
}
void PatchCordProxy::invokeCommand(const char* command)
{
DBusMessage* message = dbus_message_new_method_call(
name, OBJECT_PATH, INTERFACE_NAME, "invokeCommand");
dbus_message_append_args(message,
DBUS_TYPE_STRING, &banner,
DBUS_TYPE_STRING, &command,
DBUS_TYPE_INVALID);
DBusPendingCall* pending;
if (dbus_connection_send_with_reply(connection, message, &pending, -1))
{
dbus_connection_flush(connection);
dbus_message_unref(message);
dbus_pending_call_block(pending);
message = dbus_pending_call_steal_reply(pending);
dbus_pending_call_unref(pending);
}
dbus_message_unref(message);
// Each call of dbus_message_unref removes banner from the heap
banner = NULL;
}
void PatchCordProxy::setSpecificValue(uint32_t key, uint32_t value)
{
DBusMessage* message = dbus_message_new_method_call(

View file

@ -26,6 +26,7 @@ class PatchCordProxy
char* banner;
void getContextBanner();
void invokeCommand(const char* command);
void setSpecificValue(uint32_t key, uint32_t value);
uint32_t getSpecificValue(uint32_t key);