static gboolean init_server (GUPnPContext *context) { NetworkLight *network_light; GUPnPRootDevice *dev; GUPnPServiceInfo *switch_power; GUPnPServiceInfo *dimming; GError *error = NULL; /* Create root device */ dev = gupnp_root_device_new_full (context, gupnp_resource_factory_get_default (), doc, desc_location, DATA_DIR); switch_power = gupnp_device_info_get_service (GUPNP_DEVICE_INFO (dev), SWITCH_SERVICE); if (switch_power) { gupnp_service_signals_autoconnect (GUPNP_SERVICE (switch_power), NULL, &error); g_signal_connect (switch_power, "notify-failed", G_CALLBACK (on_notify_failed), NULL); } dimming = gupnp_device_info_get_service (GUPNP_DEVICE_INFO (dev), DIMMING_SERVICE); if (dimming) { gupnp_service_signals_autoconnect (GUPNP_SERVICE (dimming), NULL, &error); g_signal_connect (dimming, "notify-failed", G_CALLBACK (on_notify_failed), NULL); } network_light = network_light_new (dev, switch_power, dimming); g_hash_table_insert (nl_hash, g_object_ref (context), network_light); /* Run */ gupnp_root_device_set_available (dev, TRUE); g_print ("Attaching to IP/Host %s on port %d\n", gupnp_context_get_host_ip (context), gupnp_context_get_port (context)); return TRUE; }
static void mapped_external_port_cb (GUPnPSimpleIgd *igd, gchar *proto, gchar *external_ip, gchar *replaces_external_ip, guint external_port, gchar *local_ip, guint local_port, gchar *description, gpointer user_data) { guint requested_external_port = GPOINTER_TO_UINT (user_data); g_assert (invalid_ip == NULL); if (requested_external_port) g_assert (external_port == requested_external_port); else if (return_conflict) g_assert (external_port != INTERNAL_PORT); else g_assert (external_port == INTERNAL_PORT); g_assert (proto && !strcmp (proto, "UDP")); g_assert (local_port == INTERNAL_PORT); g_assert (local_ip && !strcmp (local_ip, "192.168.4.22")); g_assert (description != NULL); g_assert (external_ip); if (replaces_external_ip) { g_assert ((!strcmp (replaces_external_ip, IP_ADDRESS_FIRST) && !strcmp (external_ip, IP_ADDRESS_SECOND)) || (!strcmp (replaces_external_ip, PPP_ADDRESS_FIRST) && !strcmp (external_ip, PPP_ADDRESS_SECOND))); if (dispose_removes) g_object_unref (igd); else gupnp_simple_igd_remove_port (igd, "UDP", requested_external_port); } else { if (!strcmp (external_ip, IP_ADDRESS_FIRST)) gupnp_service_notify (GUPNP_SERVICE (ipservice), "ExternalIPAddress", G_TYPE_STRING, IP_ADDRESS_SECOND, NULL); else if (!strcmp (external_ip, PPP_ADDRESS_FIRST)) gupnp_service_notify (GUPNP_SERVICE (pppservice), "ExternalIPAddress", G_TYPE_STRING, PPP_ADDRESS_SECOND, NULL); else g_assert_not_reached (); } }
void notify_load_level_change (gint load_level) { GList *network_lights; GList *nl_node; network_lights = g_hash_table_get_values (nl_hash); for (nl_node = network_lights; nl_node != NULL; nl_node = nl_node->next) { NetworkLight *nl = (NetworkLight *) nl_node->data; gupnp_service_notify (GUPNP_SERVICE (nl->dimming), "LoadLevelStatus", G_TYPE_UINT, load_level, NULL); } }
void notify_status_change (gboolean status) { GList *network_lights; GList *nl_node; network_lights = g_hash_table_get_values (nl_hash); for (nl_node = network_lights; nl_node != NULL; nl_node = nl_node->next) { NetworkLight *nl = (NetworkLight *) nl_node->data; gupnp_service_notify (GUPNP_SERVICE (nl->switch_power), "Status", G_TYPE_BOOLEAN, status, NULL); } }
void upnpConnectionManagerServiceConnect(UpnpConnectionManagerService *self) { UpnpConnectionManagerServicePrivate *priv = UPNP_CONNECTION_MANAGER_SERVICE_GET_PRIVATE(self); priv->service = gupnp_device_info_get_service(GUPNP_DEVICE_INFO(priv->device), "urn:schemas-upnp-org:service:ConnectionManager:3"); if(!priv->service) { // g_printerr("Cannot get ConnectionManager service\n"); exit(EXIT_FAILURE); } /* ACTION CONNECT */ g_signal_connect(GUPNP_SERVICE(priv->service), "action-invoked::GetProtocolInfo", G_CALLBACK(getProtocolInfo), self); g_signal_connect(GUPNP_SERVICE(priv->service), "action-invoked::GetCurrentConnectionIDs", G_CALLBACK(getCurrentConnectionIDs), self); g_signal_connect(GUPNP_SERVICE(priv->service), "action-invoked::GetCurrentConnectionInfo", G_CALLBACK(getCurrentConnectionInfo), self); /* QUERY CONNECT */ g_signal_connect(GUPNP_SERVICE(priv->service), "query-variable::SourceProtocolInfo", G_CALLBACK(querySourceProtocolInfo), self); g_signal_connect(GUPNP_SERVICE(priv->service), "query-variable::SinkProtocolInfo", G_CALLBACK(querySinkProtocolInfo), self); g_signal_connect(GUPNP_SERVICE(priv->service), "query-variable::CurrentConnectionIDs", G_CALLBACK(queryCurrentConnectionIDs), self); // g_signal_connect(GUPNP_SERVICE(priv->service), "query-variable::FeatureList", G_CALLBACK(queryFeatureList), self); // g_signal_connect(GUPNP_SERVICE(priv->service), "query-variable::ClockUpdateID", G_CALLBACK(queryClockUpdateID), self); // g_signal_connect(GUPNP_SERVICE(priv->service), "query-variable::DeviceClockInfoUpdates", G_CALLBACK(queryDeviceClockInfoUpdates), self); g_signal_connect(GUPNP_SERVICE(priv->service), "query-variable::A_ARG_TYPE_ConnectionStatus", G_CALLBACK(queryConnectionStatus), self); g_signal_connect(GUPNP_SERVICE(priv->service), "query-variable::A_ARG_TYPE_ConnectionManager", G_CALLBACK(queryConnectionManager), self); g_signal_connect(GUPNP_SERVICE(priv->service), "query-variable::A_ARG_TYPE_Direction", G_CALLBACK(queryDirection), self); g_signal_connect(GUPNP_SERVICE(priv->service), "query-variable::A_ARG_TYPE_ProtocolInfo", G_CALLBACK(queryProtocolInfo), self); g_signal_connect(GUPNP_SERVICE(priv->service), "query-variable::A_ARG_TYPE_ConnectionID", G_CALLBACK(queryConnectionID), self); g_signal_connect(GUPNP_SERVICE(priv->service), "query-variable::A_ARG_TYPE_AVTransportID", G_CALLBACK(queryAVTransportID), self); g_signal_connect(GUPNP_SERVICE(priv->service), "query-variable::A_ARG_TYPE_RcsID", G_CALLBACK(queryRcsID), self); // g_signal_connect(GUPNP_SERVICE(priv->service), "query-variable::A_ARG_TYPE_ItemInfoFilter", G_CALLBACK(queryItemInfoFilter), self); // g_signal_connect(GUPNP_SERVICE(priv->service), "query-variable::A_ARG_TYPE_Result", G_CALLBACK(queryResult), self); // g_signal_connect(GUPNP_SERVICE(priv->service), "query-variable::A_ARG_TYPE_RenderingInfoList", G_CALLBACK(queryRenderingInfoList), self); }
int main (G_GNUC_UNUSED int argc, G_GNUC_UNUSED char **argv) { GOptionContext *optionContext; GMainLoop *main_loop; GError *error = NULL; GUPnPContext *context; GUPnPRootDevice *dev; GUPnPServiceInfo *service; #if !GLIB_CHECK_VERSION(2,35,0) g_type_init (); #endif optionContext = g_option_context_new (NULL); g_option_context_add_main_entries (optionContext, entries, NULL); if (!g_option_context_parse (optionContext, &argc, &argv, &error)) { g_print ("option parsing failed: %s\n", error->message); exit (1); } /* By default the light is off */ status = FALSE; if (!quiet) { g_print ("The light is now %s.\n", status ? "on" : "off"); } /* Create the UPnP context */ context = gupnp_context_new (NULL, NULL, 0, &error); if (error) { g_printerr ("Error creating the GUPnP context: %s\n", error->message); g_error_free (error); return EXIT_FAILURE; } /* Create root device */ dev = gupnp_root_device_new (context, "BinaryLight1.xml", "."); gupnp_root_device_set_available (dev, TRUE); /* Get the switch service from the root device */ service = gupnp_device_info_get_service (GUPNP_DEVICE_INFO (dev), "urn:schemas-upnp-org:service:SwitchPower:1"); if (!service) { g_printerr ("Cannot get SwitchPower1 service\n"); return EXIT_FAILURE; } /* Autoconnect the action and state variable handlers. This connects query_target_cb and query_status_cb to the Target and Status state variables query callbacks, and set_target_cb, get_target_cb and get_status_cb to SetTarget, GetTarget and GetStatus actions respectively. */ gupnp_service_signals_autoconnect (GUPNP_SERVICE (service), NULL, &error); if (error) { g_printerr ("Failed to autoconnect signals: %s\n", error->message); g_error_free (error); return EXIT_FAILURE; } /* Run the main loop */ main_loop = g_main_loop_new (NULL, FALSE); g_main_loop_run (main_loop); /* Cleanup */ g_main_loop_unref (main_loop); g_object_unref (service); g_object_unref (dev); g_object_unref (context); return EXIT_SUCCESS; }