static void prv_device_unavailable_cb(GUPnPControlPoint *cp, GUPnPDeviceProxy *proxy, gpointer user_data) { dld_upnp_t *upnp = user_data; const char *udn; const gchar *ip_address; DLEYNA_LOG_DEBUG("Enter"); udn = gupnp_device_info_get_udn((GUPnPDeviceInfo *)proxy); ip_address = gupnp_context_get_host_ip( gupnp_control_point_get_context(cp)); if (!udn || !ip_address) goto on_error; DLEYNA_LOG_DEBUG("UDN %s", udn); DLEYNA_LOG_DEBUG("IP Address %s", ip_address); (void) prv_remove_bm_service_sub_devices((GUPnPDeviceInfo *)proxy, upnp, ip_address); prv_remove_device(upnp, ip_address, udn); on_error: return; }
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 context_found(GUPnPContextManager* mngr, GUPnPContext* context, gpointer userData) { const gchar* ipaddr = 0; ipaddr = gupnp_context_get_host_ip(context); printf("Found physical router for address %s\n",ipaddr); GUPnPControlPoint* controlPoint = gupnp_control_point_new(context,"upnp:rootdevice"); g_signal_connect(controlPoint,"device-proxy-available",G_CALLBACK(device_proxy_found),context); gssdp_resource_browser_set_active(GSSDP_RESOURCE_BROWSER(controlPoint),TRUE); g_object_unref(context); }
static void on_context_unavailable (GUPnPContextManager *manager, GUPnPContext *context, gpointer user_data) { g_print ("Detaching from IP/Host %s and port %d\n", gupnp_context_get_host_ip (context), gupnp_context_get_port (context)); g_hash_table_remove (nl_hash, context); }
static void device_proxy_found(GUPnPControlPoint* cp, GUPnPServiceProxy* proxy, GUPnPContext* context) { GUPnPDeviceInfo* info = GUPNP_DEVICE_INFO(proxy); if(g_strcmp0(gupnp_device_info_get_device_type(info),"urn:schemas-upnp-org:device:InternetGatewayDevice:1") == 0) { const char* devname = gupnp_device_info_get_friendly_name(info); const char* serialno = gupnp_device_info_get_serial_number(info); devname = devname ? devname : "unknown"; serialno = serialno ? serialno : "unknown"; routerip = gupnp_context_get_host_ip(context); printf("Found device named %s with serial number %s on local interface %s\n",devname,serialno,gupnp_context_get_host_ip(context)); } }
static void prv_device_available_cb(GUPnPControlPoint *cp, GUPnPDeviceProxy *proxy, gpointer user_data) { dld_upnp_t *upnp = user_data; const char *udn; const gchar *ip_address; GUPnPServiceProxy *bms_proxy; DLEYNA_LOG_DEBUG("Enter"); udn = gupnp_device_info_get_udn((GUPnPDeviceInfo *)proxy); ip_address = gupnp_context_get_host_ip( gupnp_control_point_get_context(cp)); if (!udn || !ip_address) goto on_error; DLEYNA_LOG_DEBUG("UDN %s", udn); DLEYNA_LOG_DEBUG("IP Address %s", ip_address); bms_proxy = (GUPnPServiceProxy *) gupnp_device_info_get_service( (GUPnPDeviceInfo *)proxy, DLD_BASIC_MANAGEMENT_SERVICE_TYPE); if (bms_proxy != NULL) prv_add_device(upnp, proxy, bms_proxy, ip_address, udn); (void) prv_add_bm_service_sub_devices((GUPnPDeviceInfo *)proxy, upnp, ip_address); on_error: DLEYNA_LOG_DEBUG("Exit"); DLEYNA_LOG_DEBUG_NL(); return; }
void start_transfer (const char *file_path, const char *dest_uri, GUPnPServiceProxy *cds_proxy, GUPnPContext *context) { char *source_uri; char *file_name; if (!g_path_is_absolute (file_path)) { g_critical ("Given file path '%s' is not absolute.", file_path); transfer_completed (); return; } /* Time to host the file */ gupnp_context_host_path (context, file_path, file_path); source_uri = g_strdup_printf ("http://%s:%u%s", gupnp_context_get_host_ip (context), gupnp_context_get_port (context), file_path); file_name = g_path_get_basename (file_path); gupnp_service_proxy_begin_action (cds_proxy, "ImportResource", import_resource_cb, file_name, "SourceURI", G_TYPE_STRING, source_uri, "DestinationURI", G_TYPE_STRING, dest_uri, NULL); g_free (source_uri); }
static void prv_server_unavailable_cb(GUPnPControlPoint *cp, GUPnPDeviceProxy *proxy, gpointer user_data) { dls_upnp_t *upnp = user_data; const char *udn; dls_device_t *device; const gchar *ip_address; unsigned int i; dls_device_context_t *context; gboolean subscribed; gboolean construction_ctx = FALSE; gboolean under_construction = FALSE; prv_device_new_ct_t *priv_t; const dleyna_task_queue_key_t *queue_id; DLEYNA_LOG_DEBUG("Enter"); udn = gupnp_device_info_get_udn((GUPnPDeviceInfo *)proxy); ip_address = gupnp_context_get_host_ip( gupnp_control_point_get_context(cp)); if (!udn || !ip_address) goto on_error; DLEYNA_LOG_DEBUG("UDN %s", udn); DLEYNA_LOG_DEBUG("IP Address %s", ip_address); device = g_hash_table_lookup(upnp->server_udn_map, udn); if (!device) { priv_t = g_hash_table_lookup(upnp->server_uc_map, udn); if (priv_t) { device = priv_t->device; under_construction = TRUE; } } if (!device) { DLEYNA_LOG_WARNING("Device not found. Ignoring"); goto on_error; } for (i = 0; i < device->contexts->len; ++i) { context = g_ptr_array_index(device->contexts, i); if (!strcmp(context->ip_address, ip_address)) break; } if (i >= device->contexts->len) goto on_error; subscribed = context->subscribed; if (under_construction) construction_ctx = !strcmp(context->ip_address, priv_t->ip_address); (void) g_ptr_array_remove_index(device->contexts, i); if (device->contexts->len == 0) { if (!under_construction) { DLEYNA_LOG_DEBUG("Last Context lost. Delete device"); upnp->lost_server(device->path, upnp->user_data); g_hash_table_remove(upnp->server_udn_map, udn); } else { DLEYNA_LOG_WARNING( "Device under construction. Cancelling"); dleyna_task_processor_cancel_queue(priv_t->queue_id); } } else if (under_construction && construction_ctx) { DLEYNA_LOG_WARNING( "Device under construction. Switching context"); /* Cancel previous contruction task chain */ g_hash_table_remove(priv_t->upnp->server_uc_map, priv_t->udn); dleyna_task_queue_set_finally(priv_t->queue_id, prv_device_context_switch_end); dleyna_task_processor_cancel_queue(priv_t->queue_id); /* Create a new construction task chain */ context = dls_device_get_context(device, NULL); queue_id = prv_create_device_queue(&priv_t); prv_update_device_context(priv_t, upnp, udn, device, context->ip_address, queue_id); /* Start tasks from current construction step */ dls_device_construct(device, context, upnp->connection, upnp->interface_info, upnp->property_map, queue_id); } else if (subscribed && !device->timeout_id) { DLEYNA_LOG_DEBUG("Subscribe on new context"); device->timeout_id = g_timeout_add_seconds(1, prv_subscribe_to_contents_change, device); } on_error: DLEYNA_LOG_DEBUG("Exit"); DLEYNA_LOG_DEBUG_NL(); return; }
static void prv_server_available_cb(GUPnPControlPoint *cp, GUPnPDeviceProxy *proxy, gpointer user_data) { dls_upnp_t *upnp = user_data; const char *udn; dls_device_t *device; const gchar *ip_address; dls_device_context_t *context; const dleyna_task_queue_key_t *queue_id; unsigned int i; prv_device_new_ct_t *priv_t; udn = gupnp_device_info_get_udn((GUPnPDeviceInfo *)proxy); ip_address = gupnp_context_get_host_ip( gupnp_control_point_get_context(cp)); if (!udn || !ip_address) goto on_error; DLEYNA_LOG_DEBUG("UDN %s", udn); DLEYNA_LOG_DEBUG("IP Address %s", ip_address); device = g_hash_table_lookup(upnp->server_udn_map, udn); if (!device) { priv_t = g_hash_table_lookup(upnp->server_uc_map, udn); if (priv_t) device = priv_t->device; } if (!device) { DLEYNA_LOG_DEBUG("Device not found. Adding"); DLEYNA_LOG_DEBUG_NL(); queue_id = prv_create_device_queue(&priv_t); device = dls_device_new(upnp->connection, proxy, ip_address, upnp->interface_info, upnp->property_map, upnp->counter, queue_id); prv_update_device_context(priv_t, upnp, udn, device, ip_address, queue_id); upnp->counter++; } else { DLEYNA_LOG_DEBUG("Device Found"); for (i = 0; i < device->contexts->len; ++i) { context = g_ptr_array_index(device->contexts, i); if (!strcmp(context->ip_address, ip_address)) break; } if (i == device->contexts->len) { DLEYNA_LOG_DEBUG("Adding Context"); (void) dls_device_append_new_context(device, ip_address, proxy); } DLEYNA_LOG_DEBUG_NL(); } on_error: return; }
/* Pubic methods*/ static RygelMediaContainer* rygel_external_content_dir_real_create_root_container (RygelContentDirectory* base) { RygelExternalContentDir * self; ExternalPlugin* _tmp2_; GUPnPRootDevice* _tmp1_; GUPnPRootDevice* _tmp0_; ExternalPlugin* _tmp3_; ExternalPlugin* plugin; RygelMediaContainer* _tmp4_; self = (RygelExternalContentDir*) base; _tmp2_ = NULL; _tmp1_ = NULL; _tmp0_ = NULL; _tmp3_ = NULL; plugin = (_tmp3_ = (_tmp2_ = EXTERNAL_PLUGIN (gupnp_device_info_get_resource_factory ((GUPnPDeviceInfo*) (_tmp1_ = (g_object_get ((GUPnPService*) self, "root-device", &_tmp0_, NULL), _tmp0_)))), (_tmp2_ == NULL) ? NULL : g_object_ref (_tmp2_)), (_tmp1_ == NULL) ? NULL : (_tmp1_ = (g_object_unref (_tmp1_), NULL)), _tmp3_); _tmp4_ = NULL; return (_tmp4_ = (RygelMediaContainer*) rygel_external_container_new ("0", plugin->service_name, plugin->root_object, gupnp_context_get_host_ip (gupnp_service_info_get_context ((GUPnPServiceInfo*) self)), NULL), (plugin == NULL) ? NULL : (plugin = (g_object_unref (plugin), NULL)), _tmp4_); }
static gboolean context_equal (GUPnPContext *context1, GUPnPContext *context2) { return g_ascii_strcasecmp (gupnp_context_get_host_ip (context1), gupnp_context_get_host_ip (context2)) == 0; }
static void prv_server_unavailable_cb(GUPnPControlPoint *cp, GUPnPDeviceProxy *proxy, gpointer user_data) { msu_upnp_t *upnp = user_data; const char *udn; msu_device_t *device; const gchar *ip_address; unsigned int i; msu_device_context_t *context; gboolean subscribed; gboolean under_construction = FALSE; prv_device_new_ct_t *priv_t; MSU_LOG_DEBUG("Enter"); udn = gupnp_device_info_get_udn((GUPnPDeviceInfo *)proxy); if (!udn) goto on_error; ip_address = gupnp_context_get_host_ip( gupnp_control_point_get_context(cp)); MSU_LOG_DEBUG("UDN %s", udn); MSU_LOG_DEBUG("IP Address %s", ip_address); device = g_hash_table_lookup(upnp->server_udn_map, udn); if (!device) { priv_t = g_hash_table_lookup(upnp->server_uc_map, udn); if (priv_t) { device = priv_t->device; under_construction = TRUE; } } if (!device) { MSU_LOG_WARNING("Device not found. Ignoring"); goto on_error; } for (i = 0; i < device->contexts->len; ++i) { context = g_ptr_array_index(device->contexts, i); if (!strcmp(context->ip_address, ip_address)) break; } if (i >= device->contexts->len) goto on_error; subscribed = context->subscribed; (void) g_ptr_array_remove_index(device->contexts, i); if (device->contexts->len == 0) { if (!under_construction) { MSU_LOG_DEBUG("Last Context lost. Delete device"); upnp->lost_server(device->path, upnp->user_data); g_hash_table_remove(upnp->server_udn_map, udn); } else { MSU_LOG_WARNING( "Device under construction. Cancelling"); msu_task_processor_cancel_queue(priv_t->queue_id); } } else if (subscribed && !device->timeout_id) { MSU_LOG_DEBUG("Subscribe on new context"); device->timeout_id = g_timeout_add_seconds(1, prv_subscribe_to_contents_change, device); } on_error: MSU_LOG_DEBUG("Exit"); MSU_LOG_DEBUG_NL(); return; }
static void prv_server_available_cb(GUPnPControlPoint *cp, GUPnPDeviceProxy *proxy, gpointer user_data) { msu_upnp_t *upnp = user_data; const char *udn; msu_device_t *device; const gchar *ip_address; msu_device_context_t *context; const msu_task_queue_key_t *queue_id; unsigned int i; prv_device_new_ct_t *priv_t; udn = gupnp_device_info_get_udn((GUPnPDeviceInfo *)proxy); if (!udn) goto on_error; ip_address = gupnp_context_get_host_ip( gupnp_control_point_get_context(cp)); MSU_LOG_DEBUG("UDN %s", udn); MSU_LOG_DEBUG("IP Address %s", ip_address); device = g_hash_table_lookup(upnp->server_udn_map, udn); if (!device) { priv_t = g_hash_table_lookup(upnp->server_uc_map, udn); if (priv_t) device = priv_t->device; } if (!device) { MSU_LOG_DEBUG("Device not found. Adding"); MSU_LOG_DEBUG_NL(); priv_t = g_new0(prv_device_new_ct_t, 1); queue_id = msu_task_processor_add_queue( msu_media_service_get_task_processor(), msu_service_task_create_source(), MSU_SINK, MSU_TASK_QUEUE_FLAG_AUTO_REMOVE, msu_service_task_process_cb, msu_service_task_cancel_cb, msu_service_task_delete_cb); msu_task_queue_set_finally(queue_id, prv_device_chain_end); msu_task_queue_set_user_data(queue_id, priv_t); device = msu_device_new(upnp->connection, proxy, ip_address, &gSubtreeVtable, upnp, upnp->property_map, upnp->counter, queue_id); upnp->counter++; priv_t->upnp = upnp; priv_t->udn = g_strdup(udn); priv_t->queue_id = queue_id; priv_t->device = device; g_hash_table_insert(upnp->server_uc_map, g_strdup(udn), priv_t); } else { MSU_LOG_DEBUG("Device Found"); for (i = 0; i < device->contexts->len; ++i) { context = g_ptr_array_index(device->contexts, i); if (!strcmp(context->ip_address, ip_address)) break; } if (i == device->contexts->len) { MSU_LOG_DEBUG("Adding Context"); (void) msu_device_append_new_context(device, ip_address, proxy); } MSU_LOG_DEBUG_NL(); } on_error: return; }