4
Fork 0
This commit is contained in:
Artem Prilutskiy 2019-02-28 21:52:11 +03:00
parent dd0a950616
commit ab7b86dd44
4 changed files with 32 additions and 37 deletions

View file

@ -1,4 +1,4 @@
// Copyright 2015-2016 by Artem Prilutskiy
// Copyright 2015-2019 by Artem Prilutskiy
#include "PatchCord.h"
@ -19,12 +19,13 @@
#define VALUE_CORD_INCOMING_SOURCE_ID 4
#define BANNER_RENEWAL_INTERVAL 60
#define BANNER_BUFFER_LENGTH 40
PatchCord::PatchCord(uint32_t network, uint32_t link)
{
renewal = 0;
banner = NULL;
number = link;
banner = (char*)calloc(BANNER_BUFFER_LENGTH, 1);
asprintf(&name, SERVICE_NAME ".N%d", network);
connection = dbus_bus_get(DBUS_BUS_SYSTEM, NULL);
}
@ -62,8 +63,7 @@ void PatchCord::getContextBanner()
{
time_t now = time(NULL);
if ((banner == NULL) ||
(renewal < now))
if (renewal < now)
{
DBusMessage* request = dbus_message_new_method_call(
name, OBJECT_PATH, INTERFACE_NAME, "getContextList");
@ -81,30 +81,25 @@ void PatchCord::getContextBanner()
{
char** array;
int count;
if ((dbus_message_get_args(response, NULL,
DBUS_TYPE_ARRAY, DBUS_TYPE_STRING, &array, &count,
DBUS_TYPE_INVALID)) &&
(count > 0))
{
if ((banner == NULL) ||
(strcmp(banner, array[0]) != 0))
{
free(banner);
banner = strdup(array[0]);
}
strncpy(banner,array[0], BANNER_BUFFER_LENGTH);
renewal = now + BANNER_RENEWAL_INTERVAL;
dbus_free_string_array(array);
}
dbus_message_unref(response);
}
renewal = now + BANNER_RENEWAL_INTERVAL;
}
}
void PatchCord::invokeCommand(const char* command)
{
if (banner != NULL)
if (*banner != '\0')
{
DBusMessage* request = dbus_message_new_method_call(
name, OBJECT_PATH, INTERFACE_NAME, "invokeCommand");
@ -120,7 +115,7 @@ void PatchCord::invokeCommand(const char* command)
void PatchCord::setSpecificValue(uint32_t key, uint32_t value)
{
if (banner != NULL)
if (*banner != '\0')
{
DBusMessage* request = dbus_message_new_method_call(
name, OBJECT_PATH, INTERFACE_NAME, "setSpecificValue");
@ -139,7 +134,7 @@ uint32_t PatchCord::getSpecificValue(uint32_t key)
{
uint32_t value = 0;
if (banner != NULL)
if (*banner != '\0')
{
DBusMessage* request = dbus_message_new_method_call(
name, OBJECT_PATH, INTERFACE_NAME, "getContextData");