3
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");

View file

@ -1,4 +1,4 @@
// Copyright 2015 by Artem Prilutskiy
// Copyright 2015-2019 by Artem Prilutskiy
#include "BrandMeisterBridge.h"
#include <string.h>
@ -9,6 +9,10 @@
#define ECHOLINK_DEFAULT_USER_CALL "N0CALL Unknown call"
#define ECHOLINK_DEFAULT_USER_NUMBER 1
#define CALL_BUFFER_SIZE 16
#define TEXT_BUFFER_SIZE 48
#define TALKER_BUFFER_SIZE 80
#define DELETE(object) \
if (object) \
delete object;
@ -17,7 +21,7 @@ BrandMeisterBridge::BrandMeisterBridge()
{
proxy = NULL;
handle = NULL;
talker = NULL;
talker = (char*)malloc(TALKER_BUFFER_SIZE);
unknown = ECHOLINK_DEFAULT_USER_NUMBER;
}
@ -57,19 +61,19 @@ const char* BrandMeisterBridge::getTalker()
return ECHOLINK_DEFAULT_USER_CALL;
}
free(talker);
uint32_t number = proxy->getTalkerID();
char call[16];
char text[48];
char call[CALL_BUFFER_SIZE];
char text[TEXT_BUFFER_SIZE];
if ((number != 0) &&
(proxy->getCredentialsForID(number, call, text)))
{
asprintf(&talker, "%s %s", call, text);
snprintf(talker, TALKER_BUFFER_SIZE, "%s %s", call, text);
return talker;
}
asprintf(&talker, "DMR ID: %d", number);
snprintf(talker, TALKER_BUFFER_SIZE, "DMR ID: %d", number);
return talker;
}

View file

@ -4,6 +4,7 @@
#define BRANDMEISTERBRIDGE_H
#include <iconv.h>
#include <pthread.h>
#include "PatchCord.h"

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");