RPi Locator and Display Services
|
#include <stdlib.h>
#include <string.h>
#include <gtk/gtk.h>
#include <libgssdp/gssdp.h>
#include <gio/gio.h>
#include <glib-unix.h>
#include <gio/gnetworking.h>
#include <ifaddrs.h>
Go to the source code of this file.
Data Structures | |
struct | _ipBroadcastArray |
struct | _messageData |
struct | _signalData |
struct | _registryData |
struct | _gssdpRegistryData |
struct | _controlData |
struct | MessageQueueSource |
Macros | |
#define | PACKAGE_VERSION "0.9.0" |
#define | PACKAGE_NAME "gtkDS" |
#define | PACKAGE_DESCRIPTION "Display Messages from other Raspberry Pi's on the network." |
#define | G_OPTION_FLAG_NONE 0 |
#define | SZ_TIMESTAMP_BUFF 32 |
#define | SZ_PARAMS_BUFF 64 |
#define | SZ_RMTADDR_BUFF 256 |
#define | SZ_MESSAGE_BUFF 512 |
#define | SZ_RESPONSE_BUFF 256 |
#define | UDP_COMM_PORT 48029 |
#define | UDP_BROADCAST_PORT 48028 |
#define | UDP_REGULAR_PORT 48027 |
#define | MS_TEN_MINUTES 600000 |
#define | SKN_SMALL_DISPLAY_MODE_ON 1 |
#define | SKN_SMALL_DISPLAY_MODE_OFF 0 |
#define | MAX_MESSAGES_VIEWABLE 64 |
#define | SZ_CHAR_LABEL 48 |
#define | SZ_INFO_BUFF 256 |
#define | SZ_CHAR_BUFF 128 |
#define | SZ_LINE_BUFF 512 |
#define | SZ_COMM_BUFF 256 |
#define | SKN_UDP_ANY_PORT 0 |
#define | ARY_MAX_INTF 8 |
#define | PLATFORM_ERROR -1 |
Typedefs | |
typedef struct _ipBroadcastArray | IPBroadcastArray |
typedef struct _ipBroadcastArray * | PIPBroadcastArray |
typedef struct _messageData | MsgData |
typedef struct _messageData * | PMsgData |
typedef struct _signalData | USignalData |
typedef struct _signalData * | PUSignalData |
typedef struct _registryData | RegData |
typedef struct _registryData * | PRegData |
typedef struct _registryData ** | PPRegData |
typedef struct _gssdpRegistryData | GSSDPRegData |
typedef struct _gssdpRegistryData * | PGSSDPRegData |
typedef struct _controlData | ControlData |
typedef struct _controlData * | PControlData |
typedef gboolean(* | MessageQueueSourceFunc) (gpointer message, gpointer user_data) |
Enumerations | |
enum | _messages { MSGS_COLUMN_TIMESTAMP, COLUMN_NODE, COLUMN_MESSAGES, MSG_NUM_COLUMNS } |
enum | _registry { UDP_COLUMN_TIMESTAMP, COLUMN_FROM, COLUMN_NAME, COLUMN_IP, COLUMN_PORT, REG_NUM_COLUMNS } |
enum | _gssdp_registry { GSSDP_COLUMN_TIMESTAMP, COLUMN_URN, COLUMN_LOCATION, COLUMN_STATUS, GSSDP_NUM_COLUMNS } |
Functions | |
gchar * | skn_get_timestamp () |
gchar * | skn_gio_condition_to_string (GIOCondition condition) |
gchar * | skn_strip (gchar *alpha) |
PIPBroadcastArray | skn_get_default_interface_name_and_ipv4_address (char *intf, char *ipv4) |
gint | skn_get_broadcast_ip_array (PIPBroadcastArray paB) |
gint | skn_get_default_interface_name (char *pchDefaultInterfaceName) |
gboolean | skn_udp_network_broadcast_all_interfaces (GSocket *gSock, PIPBroadcastArray pab) |
static gboolean | cb_unix_signal_handler (PUSignalData psig) |
static gboolean | cb_registry_refresh (PControlData pctrl) |
static gboolean | cb_registry_request_handler (PRegData msg, PControlData pctrl) |
static gboolean | cb_message_request_handler (PMsgData msg, PControlData pctrl) |
static gboolean | cb_udp_comm_request_handler (GSocket *socket, GIOCondition condition, PControlData pctrl) |
static gboolean | cb_udp_broadcast_response_handler (GSocket *gSock, GIOCondition condition, PControlData pctrl) |
PPRegData | udp_registry_response_parser (PRegData msg, gchar *response) |
GtkWidget * | ui_page_layout (GtkWidget *parent, PControlData pctrl) |
GtkWidget * | ui_message_page_new (GtkWidget *parent, guint gSmall) |
GtkWidget * | ui_registry_page_new (GtkWidget *parent, guint gSmall) |
GtkWidget * | ui_gssdp_registry_page_new (GtkWidget *parent, guint gSmall) |
gboolean | ui_add_message_entry (GtkWidget *treeview, PMsgData msg, gboolean limiter) |
gboolean | ui_add_registry_entry (GtkWidget *treeview, PRegData msg, gboolean limiter) |
gboolean | ui_add_gssdp_registry_entry (GtkWidget *treeview, PGSSDPRegData msg, gboolean limiter) |
guint | ui_update_status_bar (PControlData pctrl) |
gboolean | gssdp_publish (PControlData pctrl, guint udp_port) |
gboolean | gssdp_browse (PControlData pctrl) |
static void | cb_gssdp_resource_available (GSSDPResourceBrowser *resource_browser, const char *usn, GList *locations, PControlData pctrl) |
static void | cb_gssdp_resource_unavailable (GSSDPResourceBrowser *resource_browser, const char *usn, PControlData pctrl) |
static gboolean | message_queue_source_prepare (GSource *source, gint *timeout_) |
static gboolean | message_queue_source_dispatch (GSource *source, GSourceFunc callback, gpointer user_data) |
static void | message_queue_source_finalize (GSource *source) |
static gboolean | message_queue_source_closure_callback (gpointer message, gpointer user_data) |
GSource * | message_queue_source_new (GAsyncQueue *queue, GDestroyNotify destroy_message, GCancellable *cancellable) |
PIPBroadcastArray | skn_get_default_interface_name_and_ipv4_address (gchar *intf, gchar *ipv4) |
static gboolean | cb_gssdp_registry_request_handler (PGSSDPRegData msg, PControlData pctrl) |
static void | cb_gtk_shutdown (GtkWidget *object, gpointer data) |
int | main (int argc, char **argv) |
Variables | |
enum _messages | EMessages |
enum _registry | EUDPRegistry |
enum _gssdp_registry | EGSSDPRegistry |
static GSourceFuncs | message_queue_source_funcs |
#define ARY_MAX_INTF 8 |
Definition at line 72 of file gtkDS.c.
Referenced by skn_get_broadcast_ip_array().
#define MAX_MESSAGES_VIEWABLE 64 |
Definition at line 63 of file gtkDS.c.
Referenced by cb_gssdp_registry_request_handler(), cb_message_request_handler(), and cb_registry_request_handler().
#define PACKAGE_DESCRIPTION "Display Messages from other Raspberry Pi's on the network." |
#define PACKAGE_VERSION "0.9.0" |
gtkDS.c IOT/RaspberryPi message display service gcc pkg-config --cflags --libs gtk+-3.0 gssdp-1.0
-O3 -Wall -o gtkDS gtkDS.c
Program Flow:
#define PLATFORM_ERROR -1 |
Definition at line 73 of file gtkDS.c.
Referenced by skn_get_broadcast_ip_array(), and skn_get_default_interface_name_and_ipv4_address().
#define SKN_SMALL_DISPLAY_MODE_OFF 0 |
Definition at line 61 of file gtkDS.c.
Referenced by main(), ui_gssdp_registry_page_new(), ui_message_page_new(), ui_page_layout(), ui_registry_page_new(), and ui_update_status_bar().
#define SZ_CHAR_BUFF 128 |
Definition at line 67 of file gtkDS.c.
Referenced by skn_get_broadcast_ip_array(), and skn_get_default_interface_name_and_ipv4_address().
#define SZ_INFO_BUFF 256 |
Definition at line 66 of file gtkDS.c.
Referenced by skn_get_default_interface_name().
#define SZ_MESSAGE_BUFF 512 |
Definition at line 52 of file gtkDS.c.
Referenced by gssdp_publish(), and ui_update_status_bar().
#define SZ_RESPONSE_BUFF 256 |
Definition at line 53 of file gtkDS.c.
Referenced by cb_udp_broadcast_response_handler(), and cb_udp_comm_request_handler().
#define SZ_RMTADDR_BUFF 256 |
Definition at line 51 of file gtkDS.c.
Referenced by udp_registry_response_parser().
#define UDP_BROADCAST_PORT 48028 |
Definition at line 56 of file gtkDS.c.
Referenced by main(), and skn_udp_network_broadcast_all_interfaces().
typedef struct _controlData ControlData |
typedef struct _gssdpRegistryData GSSDPRegData |
typedef struct _ipBroadcastArray IPBroadcastArray |
typedef gboolean(* MessageQueueSourceFunc) (gpointer message, gpointer user_data) |
MessageQueueSourceFunc: : (transfer full) (nullable): message pulled off the queue : user data provided to g_source_set_callback()
Callback function type for MessageQueueSource.
typedef struct _messageData MsgData |
typedef struct _controlData * PControlData |
typedef struct _gssdpRegistryData * PGSSDPRegData |
typedef struct _ipBroadcastArray * PIPBroadcastArray |
typedef struct _messageData * PMsgData |
typedef struct _registryData ** PPRegData |
typedef struct _registryData * PRegData |
typedef struct _signalData * PUSignalData |
typedef struct _registryData RegData |
typedef struct _signalData USignalData |
enum _gssdp_registry |
Enumerator | |
---|---|
GSSDP_COLUMN_TIMESTAMP | |
COLUMN_URN | |
COLUMN_LOCATION | |
COLUMN_STATUS | |
GSSDP_NUM_COLUMNS |
Definition at line 162 of file gtkDS.c.
enum _messages |
Enumerator | |
---|---|
MSGS_COLUMN_TIMESTAMP | |
COLUMN_NODE | |
COLUMN_MESSAGES | |
MSG_NUM_COLUMNS |
Definition at line 146 of file gtkDS.c.
enum _registry |
Enumerator | |
---|---|
UDP_COLUMN_TIMESTAMP | |
COLUMN_FROM | |
COLUMN_NAME | |
COLUMN_IP | |
COLUMN_PORT | |
REG_NUM_COLUMNS |
Definition at line 153 of file gtkDS.c.
|
static |
Definition at line 786 of file gtkDS.c.
References _controlData::gGSSDPRegCount, MAX_MESSAGES_VIEWABLE, _controlData::pg3Target, ui_add_gssdp_registry_entry(), and ui_update_status_bar().
Referenced by main().
|
static |
Definition at line 1303 of file gtkDS.c.
References _gssdpRegistryData::ch_location, _gssdpRegistryData::ch_status, _gssdpRegistryData::ch_timestamp, _gssdpRegistryData::ch_urn, _controlData::queueGSSDPRegistry, and skn_get_timestamp().
Referenced by gssdp_browse().
|
static |
Definition at line 1337 of file gtkDS.c.
References _gssdpRegistryData::ch_location, _gssdpRegistryData::ch_status, _gssdpRegistryData::ch_timestamp, _gssdpRegistryData::ch_urn, _controlData::queueGSSDPRegistry, and skn_get_timestamp().
Referenced by gssdp_browse().
|
static |
Definition at line 1296 of file gtkDS.c.
References _signalData::loop, and _signalData::signalName.
Referenced by main().
|
static |
Definition at line 754 of file gtkDS.c.
References _controlData::gMsgCount, MAX_MESSAGES_VIEWABLE, _controlData::pg1Target, ui_add_message_entry(), and ui_update_status_bar().
Referenced by main().
|
static |
Definition at line 541 of file gtkDS.c.
References _controlData::gbSock, _controlData::paB, _controlData::resource_browser, skn_udp_network_broadcast_all_interfaces(), and TRUE.
Referenced by main().
|
static |
Definition at line 770 of file gtkDS.c.
References _controlData::gRegCount, MAX_MESSAGES_VIEWABLE, _controlData::pg2Target, ui_add_registry_entry(), and ui_update_status_bar().
Referenced by main().
|
static |
Definition at line 550 of file gtkDS.c.
References _registryData::ch_from, _registryData::ch_message, _controlData::ch_this_ip, _registryData::ch_timestamp, _controlData::gUDPPort, _controlData::loop, _controlData::pch_service_name, _controlData::queueRegistry, _controlData::resolver, skn_get_timestamp(), skn_gio_condition_to_string(), SZ_RESPONSE_BUFF, and udp_registry_response_parser().
Referenced by main().
|
static |
Definition at line 659 of file gtkDS.c.
References _messageData::ch_message, _messageData::ch_remoteAddress, _messageData::ch_timestamp, _controlData::loop, _controlData::queueMessage, _controlData::resolver, skn_get_timestamp(), skn_gio_condition_to_string(), and SZ_RESPONSE_BUFF.
Referenced by main().
|
static |
Definition at line 535 of file gtkDS.c.
References _signalData::loop, and _signalData::signalName.
Referenced by main().
gboolean gssdp_browse | ( | PControlData | pctrl | ) |
Setup a monitor for the registry page
Definition at line 1401 of file gtkDS.c.
References cb_gssdp_resource_available(), cb_gssdp_resource_unavailable(), _controlData::gssdp_rgroup_client, _controlData::pch_search, _controlData::resource_browser, and TRUE.
Referenced by main().
gboolean gssdp_publish | ( | PControlData | pctrl, |
guint | udp_port | ||
) |
Definition at line 1364 of file gtkDS.c.
References _controlData::ch_this_ip, FALSE, _controlData::gssdp_rgroup_client, _controlData::resource_group, SZ_MESSAGE_BUFF, and TRUE.
Referenced by main().
int main | ( | int | argc, |
char ** | argv | ||
) |
Definition at line 1412 of file gtkDS.c.
References cb_gssdp_registry_request_handler(), cb_gtk_shutdown(), cb_message_request_handler(), cb_registry_refresh(), cb_registry_request_handler(), cb_udp_broadcast_response_handler(), cb_udp_comm_request_handler(), cb_unix_signal_handler(), _controlData::ch_intfName, _controlData::ch_this_ip, FALSE, G_OPTION_FLAG_NONE, _controlData::gBroadSourceId, _controlData::gbSock, _controlData::gCommSourceId, _controlData::gGSSDPRegCount, _controlData::gGSSDPRegSourceId, _controlData::gMsgCount, _controlData::gMsgSourceId, _controlData::gRegCount, _controlData::gRegSourceId, _controlData::gSmall, gssdp_browse(), gssdp_publish(), _controlData::gssdp_rgroup_client, _controlData::gUDPPort, _signalData::loop, _controlData::loop, message_queue_source_new(), MS_TEN_MINUTES, _controlData::paB, _controlData::pch_search, _controlData::pch_service_name, _controlData::queueGSSDPRegistry, _controlData::queueMessage, _controlData::queueRegistry, _controlData::resolver, _controlData::resource_browser, _controlData::resource_group, _signalData::signalName, skn_get_default_interface_name_and_ipv4_address(), SKN_SMALL_DISPLAY_MODE_OFF, skn_udp_network_broadcast_all_interfaces(), TRUE, UDP_BROADCAST_PORT, UDP_COMM_PORT, and ui_page_layout().
|
static |
|
static |
Definition at line 241 of file gtkDS.c.
References MessageQueueSource::destroy_message, MessageQueueSource::queue, and TRUE.
|
static |
Definition at line 272 of file gtkDS.c.
References MessageQueueSource::queue.
GSource* message_queue_source_new | ( | GAsyncQueue * | queue, |
GDestroyNotify | destroy_message, | ||
GCancellable * | cancellable | ||
) |
message_queue_source_new: : the queue to check : (nullable): function to free a message, or NULL : (nullable): a #GCancellable, or NULL
Create a new MessageQueueSource, a type of #GSource which dispatches for each message queued to it.
If a callback function of type MessageQueueSourceFunc is connected to the returned #GSource using g_source_set_callback(), it will be invoked for each message, with the message passed as its first argument. It is responsible for freeing the message. If no callback is set, messages are automatically freed as they are queued.
Returns: (transfer full): a new MessageQueueSource
Definition at line 326 of file gtkDS.c.
References MessageQueueSource::destroy_message, message_queue_source_funcs, and MessageQueueSource::queue.
Referenced by main().
|
static |
Definition at line 236 of file gtkDS.c.
References MessageQueueSource::queue.
gint skn_get_broadcast_ip_array | ( | PIPBroadcastArray | paB | ) |
Collect IP and Broadcast Addresses for this machine
Definition at line 377 of file gtkDS.c.
References ARY_MAX_INTF, _ipBroadcastArray::broadAddrStr, _ipBroadcastArray::cbName, _ipBroadcastArray::chDefaultIntfName, _ipBroadcastArray::count, _ipBroadcastArray::defaultIndex, _ipBroadcastArray::ifNameStr, _ipBroadcastArray::ipAddrStr, _ipBroadcastArray::maskAddrStr, PLATFORM_ERROR, skn_get_default_interface_name(), and SZ_CHAR_BUFF.
Referenced by skn_get_default_interface_name_and_ipv4_address().
gint skn_get_default_interface_name | ( | char * | pchDefaultInterfaceName | ) |
Retrieves default internet interface name into param
[jscott OSX]$ route -n get 0.0.0.0 route to: default destination: default mask: default gateway: 10.21.1.254 interface: en3 flags: <UP,GATEWAY,DONE,STATIC,PRCLONING> recvpipe sendpipe ssthresh rtt,msec rttvar hopcount mtu expire 0 0 0 0 0 0 1500 0
Definition at line 438 of file gtkDS.c.
References skn_strip(), and SZ_INFO_BUFF.
Referenced by skn_get_broadcast_ip_array().
PIPBroadcastArray skn_get_default_interface_name_and_ipv4_address | ( | char * | intf, |
char * | ipv4 | ||
) |
PIPBroadcastArray skn_get_default_interface_name_and_ipv4_address | ( | gchar * | intf, |
gchar * | ipv4 | ||
) |
Definition at line 357 of file gtkDS.c.
References _ipBroadcastArray::chDefaultIntfName, _ipBroadcastArray::defaultIndex, _ipBroadcastArray::ipAddrStr, PLATFORM_ERROR, skn_get_broadcast_ip_array(), and SZ_CHAR_BUFF.
gchar* skn_get_timestamp | ( | ) |
Definition at line 515 of file gtkDS.c.
Referenced by cb_gssdp_resource_available(), cb_gssdp_resource_unavailable(), cb_udp_broadcast_response_handler(), and cb_udp_comm_request_handler().
gchar* skn_gio_condition_to_string | ( | GIOCondition | condition | ) |
Definition at line 801 of file gtkDS.c.
Referenced by cb_udp_broadcast_response_handler(), and cb_udp_comm_request_handler().
gchar* skn_strip | ( | gchar * | alpha | ) |
Remove Trailing and Leading Blanks
Definition at line 834 of file gtkDS.c.
Referenced by skn_get_default_interface_name().
gboolean skn_udp_network_broadcast_all_interfaces | ( | GSocket * | gSock, |
PIPBroadcastArray | paB | ||
) |
Send a registry request on the broadcast ip of all interfaces
gSock | IN GLib active/bound socket with broadcast enabled |
ch_request | IN Greetings message, anytext |
ch_intfName | OUT Default Ethernet Interface Name |
ch_ipAddress | OUT Default Ethernet IP Address |
Definition at line 489 of file gtkDS.c.
References _ipBroadcastArray::broadAddrStr, _ipBroadcastArray::count, _ipBroadcastArray::defaultIndex, _ipBroadcastArray::ifNameStr, _ipBroadcastArray::ipAddrStr, TRUE, and UDP_BROADCAST_PORT.
Referenced by cb_registry_refresh(), and main().
Parse this response message
Format: name=rpi_locator_service,ip=10.100.1.19,port=48028| name=lcd_display_service,ip=10.100.1.19,port=48029|
the vertical bar char '|' is the line separator, % and ; are also supported
Definition at line 870 of file gtkDS.c.
References _registryData::ch_ip, _registryData::ch_name, _registryData::ch_port, FALSE, SZ_RMTADDR_BUFF, and TRUE.
Referenced by cb_udp_broadcast_response_handler().
gboolean ui_add_gssdp_registry_entry | ( | GtkWidget * | treeview, |
PGSSDPRegData | msg, | ||
gboolean | limiter | ||
) |
Definition at line 1220 of file gtkDS.c.
References _gssdpRegistryData::ch_location, _gssdpRegistryData::ch_status, _gssdpRegistryData::ch_timestamp, _gssdpRegistryData::ch_urn, COLUMN_LOCATION, COLUMN_STATUS, COLUMN_URN, GSSDP_COLUMN_TIMESTAMP, and TRUE.
Referenced by cb_gssdp_registry_request_handler().
gboolean ui_add_message_entry | ( | GtkWidget * | treeview, |
PMsgData | msg, | ||
gboolean | limiter | ||
) |
Definition at line 1172 of file gtkDS.c.
References _messageData::ch_message, _messageData::ch_remoteAddress, _messageData::ch_timestamp, COLUMN_MESSAGES, COLUMN_NODE, MSGS_COLUMN_TIMESTAMP, and TRUE.
Referenced by cb_message_request_handler().
gboolean ui_add_registry_entry | ( | GtkWidget * | treeview, |
PRegData | msg, | ||
gboolean | limiter | ||
) |
Definition at line 1195 of file gtkDS.c.
References _registryData::ch_from, _registryData::ch_ip, _registryData::ch_name, _registryData::ch_port, _registryData::ch_timestamp, COLUMN_FROM, COLUMN_IP, COLUMN_NAME, COLUMN_PORT, TRUE, and UDP_COLUMN_TIMESTAMP.
Referenced by cb_registry_request_handler().
GtkWidget * ui_gssdp_registry_page_new | ( | GtkWidget * | parent, |
guint | gSmall | ||
) |
Definition at line 1104 of file gtkDS.c.
References COLUMN_LOCATION, COLUMN_STATUS, COLUMN_URN, FALSE, GSSDP_COLUMN_TIMESTAMP, GSSDP_NUM_COLUMNS, SKN_SMALL_DISPLAY_MODE_OFF, and TRUE.
Referenced by ui_page_layout().
GtkWidget * ui_message_page_new | ( | GtkWidget * | parent, |
guint | gSmall | ||
) |
Definition at line 970 of file gtkDS.c.
References COLUMN_MESSAGES, COLUMN_NODE, FALSE, MSG_NUM_COLUMNS, MSGS_COLUMN_TIMESTAMP, SKN_SMALL_DISPLAY_MODE_OFF, and TRUE.
Referenced by ui_page_layout().
GtkWidget * ui_page_layout | ( | GtkWidget * | parent, |
PControlData | pctrl | ||
) |
Definition at line 1244 of file gtkDS.c.
References _controlData::gSmall, _controlData::gStatusContextId, _controlData::pg1Target, _controlData::pg2Target, _controlData::pg3Target, SKN_SMALL_DISPLAY_MODE_OFF, _controlData::statusBar, TRUE, ui_gssdp_registry_page_new(), ui_message_page_new(), and ui_registry_page_new().
Referenced by main().
GtkWidget * ui_registry_page_new | ( | GtkWidget * | parent, |
guint | gSmall | ||
) |
Definition at line 1029 of file gtkDS.c.
References COLUMN_FROM, COLUMN_IP, COLUMN_NAME, COLUMN_PORT, FALSE, REG_NUM_COLUMNS, SKN_SMALL_DISPLAY_MODE_OFF, TRUE, and UDP_COLUMN_TIMESTAMP.
Referenced by ui_page_layout().
guint ui_update_status_bar | ( | PControlData | pctrl | ) |
Definition at line 522 of file gtkDS.c.
References _controlData::gGSSDPRegCount, _controlData::gMsgCount, _controlData::gRegCount, _controlData::gSmall, _controlData::gStatusContextId, SKN_SMALL_DISPLAY_MODE_OFF, _controlData::statusBar, and SZ_MESSAGE_BUFF.
Referenced by cb_gssdp_registry_request_handler(), cb_message_request_handler(), and cb_registry_request_handler().
enum _gssdp_registry EGSSDPRegistry |
enum _messages EMessages |
enum _registry EUDPRegistry |
|
static |
Definition at line 299 of file gtkDS.c.
Referenced by message_queue_source_new().