Advertisement
Guest User

gupnp

a guest
Dec 26th, 2014
38
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.08 KB | None | 0 0
  1. static void
  2. add_item (GUPnPContext *context,
  3. GUPnPDIDLLiteWriter *didl_writer,
  4. GUPnPDIDLLiteObject *object,
  5. const char *id,
  6. const char *parent_id,
  7. const char *mime,
  8. const char *title,
  9. const char *path)
  10. {
  11. GUPnPDIDLLiteResource *res;
  12. res = gupnp_didl_lite_object_add_resource(object);
  13. gupnp_didl_lite_resource_set_uri(res, g_strdup_printf ("http://%s:%d%s",
  14. gupnp_context_get_host_ip (context),
  15. gupnp_context_get_port (context),
  16. path));
  17. gupnp_didl_lite_resource_set_protocol_info(res, gupnp_protocol_info_new_from_string(g_strdup_printf("http-get:*:%s:*", mime), NULL));
  18. gupnp_didl_lite_object_set_id(object, id);
  19. gupnp_didl_lite_object_set_parent_id(object, parent_id);
  20. gupnp_didl_lite_object_set_title(object, title);
  21. }
  22.  
  23. static char *
  24. browse_direct_children ()
  25. {
  26. GUPnPContext *context;
  27. const char *didl;
  28. char *result;
  29. GUPnPDIDLLiteWriter *didlw = gupnp_didl_lite_writer_new (NULL);
  30. GUPnPDIDLLiteObject *object = GUPNP_DIDL_LITE_OBJECT
  31. (gupnp_didl_lite_writer_add_item (didlw));
  32. context = gupnp_device_info_get_context (GUPNP_DEVICE_INFO (device));
  33. add_item (context,
  34. didlw,
  35. object,
  36. "4000",
  37. "0",
  38. "audio/mp3",
  39. "Song1",
  40. "/home/phantom/Music/2.mp3");
  41. didl = gupnp_didl_lite_writer_get_string (didlw);
  42. result = g_strdup(didl);
  43. qDebug() << result;
  44. return result;
  45. }
  46.  
  47. static void browse_cb (GUPnPService *service,
  48. GUPnPServiceAction *action,
  49. gpointer user_data)
  50. {
  51. qDebug()<< "Browse";
  52. char *object_id, *browse_flag;
  53. char *result;
  54. guint num_returned = 1;
  55. /* Handle incoming arguments */
  56. gupnp_service_action_get (action,
  57. "ObjectID",
  58. G_TYPE_STRING,
  59. &object_id,
  60. "BrowseFlag",
  61. G_TYPE_STRING,
  62. &browse_flag,
  63. NULL);
  64. result = browse_direct_children();
  65. /* Set action return arguments */
  66. gupnp_service_action_set (action,
  67. "Result",
  68. G_TYPE_STRING,
  69. result,
  70. "NumberReturned",
  71. G_TYPE_UINT,
  72. num_returned,
  73. "TotalMatches",
  74. G_TYPE_UINT,
  75. num_returned,
  76. "UpdateID",
  77. G_TYPE_UINT,
  78. 32,
  79. NULL);
  80. gupnp_service_action_return (action);
  81. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement