#include <glib.h>
#include <glib-object.h>
#include <axsdk/axevent.h>
#include <glib-unix.h>
typedef struct SignalData_ {
GMainLoop *main_loop;
guint *subscription_id;
GThread *unsub_thread;
} SignalData;
static void
subscription_callback(guint subscription,
static guint
gint port, guint *token);
static void
unsubscribe_complete_cb(guint declaration,
gpointer user_data, GError *error);
static gboolean
signal_handler(gpointer data);
static void
subscription_callback(guint subscription,
{
gint port;
gboolean state;
(void)subscription;
"port", NULL, &port, NULL);
"state", NULL, &state, NULL);
if (state) {
g_message("Manual trigger port %d is high", port);
} else {
g_message("Manual trigger port %d is low", port);
}
g_message("And here's the token: %d", *token);
}
static guint
gint port, guint *token)
{
guint subscription;
NULL,
NULL);
NULL);
return subscription;
}
static void
unsubscribe_complete_cb(guint declaration, gpointer user_data, GError *error)
{
GMainLoop *loop = (GMainLoop *)user_data;
if (error) {
g_message("Unsubscribe failed: %s", error->message);
g_error_free(error);
} else {
g_message("Unsubscribe succeeded");
}
g_main_loop_quit(loop);
}
static gboolean
signal_handler(gpointer data) {
GError *error = NULL;
SignalData *signal_data = (SignalData *)data;
*signal_data->subscription_id,
(gpointer) signal_data->main_loop, &error)) {
g_message("Could not unsubscribe: %s", error->message);
g_error_free(error);
}
return FALSE;
}
int main(void)
{
GMainLoop *main_loop;
guint subscription;
gint port = 1;
guint token = 1234;
SignalData signal_data;
main_loop = g_main_loop_new(NULL, FALSE);
signal_data.main_loop = main_loop;
signal_data.event_handler = event_handler;
signal_data.subscription_id = &subscription;
g_unix_signal_add(SIGTERM, signal_handler, &signal_data);
g_unix_signal_add(SIGINT, signal_handler, &signal_data);
subscription = subscribe_to_manual_trigger_port(event_handler,
port, &token);
g_main_loop_run(main_loop);
g_main_loop_unref(main_loop);
return 0;
}
void ax_event_free(AXEvent *event)
Free an AXEvent.
struct _AXEvent AXEvent
The AXEvent is an opaque data type required to send and receive events.
Definition: ax_event.h:30
const AXEventKeyValueSet * ax_event_get_key_value_set(AXEvent *event)
Get the AXEventKeyValueSet associated with the AXEvent.
gboolean ax_event_handler_subscribe(AXEventHandler *event_handler, AXEventKeyValueSet *key_value_set, guint *subscription, AXSubscriptionCallback callback, gpointer user_data, GError **error)
Subscribes to an event or a set of events.
void(* AXUnsubscribeCompleteCallback)(guint declaration, gpointer user_data, GError *error)
This is the prototype of the callback function called when a subscription has been removed.
Definition: ax_event_handler.h:61
gboolean ax_event_handler_unsubscribe_and_notify(AXEventHandler *event_handler, guint subscription, AXUnsubscribeCompleteCallback callback, gpointer user_data, GError **error)
Asynchronously unsubscribes from an event or a set of events. When unsubscribe has completed,...
void ax_event_handler_free(AXEventHandler *event_handler)
Destroys an AXEventHandler an deallocates all associated declarations and subscriptions....
void(* AXSubscriptionCallback)(guint subscription, AXEvent *event, gpointer user_data)
This is the prototype of the callback function called whenever an event matching a subscription is re...
Definition: ax_event_handler.h:33
struct _AXEventHandler AXEventHandler
The AXEventHandler is an opaque data type used as an entry point into the event system.
Definition: ax_event_handler.h:19
AXEventHandler * ax_event_handler_new(void)
Creates a new AXEventHandler.
gboolean ax_event_key_value_set_get_integer(const AXEventKeyValueSet *key_value_set, const gchar *key, const gchar *name_space, gint *value, GError **error)
Retrieve the integer value associated with a key.
struct _AXEventKeyValueSet AXEventKeyValueSet
The AXEventKeyValueSet is an opaque data type required to create event declarations,...
Definition: ax_event_key_value_set.h:73
gboolean ax_event_key_value_set_add_key_values(AXEventKeyValueSet *key_value_set, GError **error,...)
Adds a set of key/value pairs to an AXEventKeyValueSet. The number of arguments is arbitrary and must...
AXEventKeyValueSet * ax_event_key_value_set_new(void)
Creates a new AXEventKeyValueSet.
gboolean ax_event_key_value_set_get_boolean(const AXEventKeyValueSet *key_value_set, const gchar *key, const gchar *name_space, gboolean *value, GError **error)
Retrieve the boolean value associated with a key.
void ax_event_key_value_set_free(AXEventKeyValueSet *key_value_set)
Frees an AXEventKeyValueSet.
@ AX_VALUE_TYPE_BOOL
Definition: ax_event_types.h:21
@ AX_VALUE_TYPE_INT
Definition: ax_event_types.h:20
@ AX_VALUE_TYPE_STRING
Definition: ax_event_types.h:23