178
198
gssdp_resource_group_set_available
179
199
(resource_group, g_value_get_boolean (value));
201
case PROP_MESSAGE_DELAY:
202
gssdp_resource_group_set_message_delay
203
(resource_group, g_value_get_uint (value));
182
206
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
188
212
gssdp_resource_group_dispose (GObject *object)
190
214
GSSDPResourceGroup *resource_group;
215
GSSDPResourceGroupPrivate *priv;
192
217
resource_group = GSSDP_RESOURCE_GROUP (object);
194
while (resource_group->priv->resources) {
195
resource_free (resource_group->priv->resources->data);
196
resource_group->priv->resources =
197
g_list_delete_link (resource_group->priv->resources,
198
resource_group->priv->resources);
201
if (resource_group->priv->timeout_id > 0) {
202
g_source_remove (resource_group->priv->timeout_id);
203
resource_group->priv->timeout_id = 0;
206
if (resource_group->priv->client) {
218
priv = resource_group->priv;
220
while (priv->resources) {
221
resource_free (priv->resources->data);
223
g_list_delete_link (priv->resources,
227
if (priv->message_queue) {
228
/* send messages without usual delay */
229
while (!g_queue_is_empty (priv->message_queue)) {
231
process_queue (resource_group);
233
g_free (g_queue_pop_head
234
(priv->message_queue));
237
g_queue_free (priv->message_queue);
238
priv->message_queue = NULL;
241
if (priv->message_src_id > 0) {
242
g_source_remove (priv->message_src_id);
243
priv->message_src_id = 0;
246
if (priv->timeout_src) {
247
g_source_destroy (priv->timeout_src);
248
priv->timeout_src = NULL;
207
252
if (g_signal_handler_is_connected
208
(resource_group->priv->client,
209
resource_group->priv->message_received_id)) {
254
priv->message_received_id)) {
210
255
g_signal_handler_disconnect
211
(resource_group->priv->client,
212
resource_group->priv->message_received_id);
257
priv->message_received_id);
215
g_object_unref (resource_group->priv->client);
216
resource_group->priv->client = NULL;
260
g_object_unref (priv->client);
283
328
G_PARAM_READWRITE |
284
329
G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK |
285
330
G_PARAM_STATIC_BLURB));
333
* GSSDPResourceGroup:message-delay
335
* The minimum number of milliseconds between SSDP messages.
336
* The default is 20 based on DLNA specification.
338
g_object_class_install_property
344
"The minimum number of milliseconds between SSDP "
348
DEFAULT_MESSAGE_DELAY,
350
G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK |
351
G_PARAM_STATIC_BLURB));
339
405
* gssdp_resource_group_set_max_age
340
406
* @resource_group: A #GSSDPResourceGroup
341
* @mx: The number of seconds advertisements are valid
407
* @max_age: The number of seconds advertisements are valid
343
409
* Sets the number of seconds advertisements are valid to @max_age.
440
* gssdp_resource_group_set_message_delay
441
* @resource_group: A #GSSDPResourceGroup
442
* @message_delay: The message delay in ms.
444
* Sets the minimum time between each SSDP message.
447
gssdp_resource_group_set_message_delay (GSSDPResourceGroup *resource_group,
450
g_return_if_fail (GSSDP_IS_RESOURCE_GROUP (resource_group));
452
if (resource_group->priv->message_delay == message_delay)
455
resource_group->priv->message_delay = message_delay;
457
g_object_notify (G_OBJECT (resource_group), "message-delay");
461
* gssdp_resource_group_get_message_delay
462
* @resource_group: A #GSSDPResourceGroup
464
* Return value: the minimum time between each SSDP message in ms.
467
gssdp_resource_group_get_message_delay (GSSDPResourceGroup *resource_group)
469
g_return_val_if_fail (GSSDP_IS_RESOURCE_GROUP (resource_group), 0);
471
return resource_group->priv->message_delay;
374
475
* gssdp_resource_group_set_available
375
476
* @resource_group: A #GSSDPResourceGroup
376
477
* @available: TRUE if @resource_group should be available (advertised)
401
503
timeout = timeout / 2 - 1;
403
505
/* Add re-announcement timer */
404
resource_group->priv->timeout_id =
405
g_timeout_add_seconds (timeout,
406
resource_group_timeout,
506
resource_group->priv->timeout_src =
507
g_timeout_source_new_seconds (timeout);
508
g_source_set_callback (resource_group->priv->timeout_src,
509
resource_group_timeout,
510
resource_group, NULL);
512
context = gssdp_client_get_main_context
513
(resource_group->priv->client);
514
g_source_attach (resource_group->priv->timeout_src, context);
516
g_source_unref (resource_group->priv->timeout_src);
409
518
/* Announce all resources */
410
519
for (l = resource_group->priv->resources; l; l = l->next)
415
524
resource_byebye (l->data);
417
526
/* Remove re-announcement timer */
418
g_source_remove (resource_group->priv->timeout_id);
419
resource_group->priv->timeout_id = 0;
527
g_source_destroy (resource_group->priv->timeout_src);
528
resource_group->priv->timeout_src = NULL;
422
531
g_object_notify (G_OBJECT (resource_group), "available");
469
578
resource->target = g_strdup (target);
470
579
resource->usn = g_strdup (usn);
581
resource->initial_alive_sent = FALSE;
472
583
for (l = locations; l; l = l->next) {
473
584
resource->locations = g_list_append (resource->locations,
474
585
g_strdup (l->data));
647
759
response->dest_ip = g_strdup (from_ip);
648
760
response->dest_port = from_port;
649
response->target = g_strdup (target);
650
761
response->resource = resource;
764
response->target = g_strdup (resource->target);
766
response->target = g_strdup (target);
652
768
/* Add timeout */
653
response->timeout_id =
654
g_timeout_add (timeout,
655
discovery_response_timeout,
769
response->timeout_src = g_timeout_source_new (timeout);
770
g_source_set_callback (response->timeout_src,
771
discovery_response_timeout,
774
context = gssdp_client_get_main_context (client);
775
g_source_attach (response->timeout_src, context);
777
g_source_unref (response->timeout_src);
658
779
/* Add to resource */
659
780
resource->responses =
744
865
response->resource->responses =
745
866
g_list_remove (response->resource->responses, response);
747
g_source_remove (response->timeout_id);
868
g_source_destroy (response->timeout_src);
749
870
g_free (response->dest_ip);
750
871
g_free (response->target);
877
* Send the next queued message, if any
880
process_queue (gpointer data)
882
GSSDPResourceGroup *resource_group;
884
resource_group = GSSDP_RESOURCE_GROUP (data);
886
if (g_queue_is_empty (resource_group->priv->message_queue)) {
887
/* this is the timeout after last message in queue */
888
resource_group->priv->message_src_id = 0;
895
client = resource_group->priv->client;
896
message = g_queue_pop_head
897
(resource_group->priv->message_queue);
899
_gssdp_client_send_message (client,
910
* Add a message to sending queue
912
* Do not free @message.
915
queue_message (GSSDPResourceGroup *resource_group,
918
g_queue_push_tail (resource_group->priv->message_queue,
921
if (resource_group->priv->message_src_id == 0) {
922
/* nothing in the queue: process message immediately
923
and add a timeout for (possible) next message */
925
process_queue (resource_group);
926
resource_group->priv->message_src_id =
927
g_timeout_add (resource_group->priv->message_delay,
756
934
* Send ssdp:alive message for @resource
763
941
char *al, *message;
943
if (!resource->initial_alive_sent) {
944
/* Unannounce before first announce. This is done to
945
minimize the possibility of control points thinking
946
that this is just a reannouncement. */
947
resource_byebye (resource);
949
resource->initial_alive_sent = TRUE;
765
952
/* Send message */
766
953
client = resource->resource_group->priv->client;
793
976
resource_byebye (Resource *resource)
799
client = resource->resource_group->priv->client;
801
981
message = g_strdup_printf (SSDP_BYEBYE_MESSAGE,
802
982
resource->target,
805
_gssdp_client_send_message (client,
985
queue_message (resource->resource_group, message);