dbus.h
上传用户:kjfoods
上传日期:2020-07-06
资源大小:29949k
文件大小:8k
源码类别:

midi

开发平台:

Unix_Linux

  1. /*****************************************************************************
  2.  * dbus.h : D-Bus control interface
  3.  *****************************************************************************
  4.  * Copyright (C) 2006 Rafaël Carré
  5.  * $Id: 929588b8a54e62ad75e85e0b12a04f4cffa2fb35 $
  6.  *
  7.  * Authors:    Rafaël Carré <funman at videolanorg>
  8.  *             Mirsal ENNAIME <mirsal dot ennaime at gmail dot com>
  9.  *
  10.  * This program is free software; you can redistribute it and/or modify
  11.  * it under the terms of the GNU General Public License as published by
  12.  * the Free Software Foundation; either version 2 of the License, or
  13.  * (at your option) any later version.
  14.  *
  15.  * This program is distributed in the hope that it will be useful,
  16.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  18.  * GNU General Public License for more details.
  19.  *
  20.  * You should have received a copy of the GNU General Public License
  21.  * along with this program; if not, write to the Free Software
  22.  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
  23.  *****************************************************************************/
  24. /* MPRIS VERSION */
  25. #define VLC_MPRIS_VERSION_MAJOR     1
  26. #define VLC_MPRIS_VERSION_MINOR     0
  27. /* DBUS IDENTIFIERS */
  28. /* name registered on the session bus */
  29. #define VLC_MPRIS_DBUS_SERVICE      "org.mpris.vlc"
  30. #define MPRIS_DBUS_INTERFACE        "org.freedesktop.MediaPlayer"
  31. #define MPRIS_DBUS_ROOT_PATH        "/"
  32. #define MPRIS_DBUS_PLAYER_PATH      "/Player"
  33. #define MPRIS_DBUS_TRACKLIST_PATH   "/TrackList"
  34. /* MACROS */
  35. #define DBUS_METHOD( method_function ) 
  36.     static DBusHandlerResult method_function 
  37.             ( DBusConnection *p_conn, DBusMessage *p_from, void *p_this )
  38. #define DBUS_SIGNAL( signal_function ) 
  39.     static DBusHandlerResult signal_function 
  40.             ( DBusConnection *p_conn, void *p_data )
  41. #define REPLY_INIT 
  42.     DBusMessage* p_msg = dbus_message_new_method_return( p_from ); 
  43.     if( !p_msg ) return DBUS_HANDLER_RESULT_NEED_MEMORY; 
  44. #define REPLY_SEND 
  45.     if( !dbus_connection_send( p_conn, p_msg, NULL ) ) 
  46.         return DBUS_HANDLER_RESULT_NEED_MEMORY; 
  47.     dbus_connection_flush( p_conn ); 
  48.     dbus_message_unref( p_msg ); 
  49.     return DBUS_HANDLER_RESULT_HANDLED
  50. #define SIGNAL_INIT( signal ) 
  51.     DBusMessage *p_msg = dbus_message_new_signal( MPRIS_DBUS_PLAYER_PATH, 
  52.         MPRIS_DBUS_INTERFACE, signal ); 
  53.     if( !p_msg ) return DBUS_HANDLER_RESULT_NEED_MEMORY; 
  54. #define SIGNAL_SEND 
  55.     if( !dbus_connection_send( p_conn, p_msg, NULL ) ) 
  56.         return DBUS_HANDLER_RESULT_NEED_MEMORY; 
  57.     dbus_message_unref( p_msg ); 
  58.     dbus_connection_flush( p_conn ); 
  59.     return DBUS_HANDLER_RESULT_HANDLED
  60. #define OUT_ARGUMENTS 
  61.     DBusMessageIter args; 
  62.     dbus_message_iter_init_append( p_msg, &args )
  63. #define DBUS_ADD( dbus_type, value ) 
  64.     if( !dbus_message_iter_append_basic( &args, dbus_type, value ) ) 
  65.         return DBUS_HANDLER_RESULT_NEED_MEMORY
  66. #define ADD_STRING( s ) DBUS_ADD( DBUS_TYPE_STRING, s )
  67. #define ADD_BOOL( b ) DBUS_ADD( DBUS_TYPE_BOOLEAN, b )
  68. #define ADD_INT32( i ) DBUS_ADD( DBUS_TYPE_INT32, i )
  69. #define ADD_BYTE( b ) DBUS_ADD( DBUS_TYPE_BYTE, b )
  70. /* XML data to answer org.freedesktop.DBus.Introspectable.Introspect requests */
  71. const char* psz_introspection_xml_data_root =
  72. "<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN"n"
  73. ""http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd">n"
  74. "<node>n"
  75. "  <node name="Player"/>n"
  76. "  <node name="TrackList"/>n"
  77. "  <interface name="org.freedesktop.DBus.Introspectable">n"
  78. "    <method name="Introspect">n"
  79. "      <arg name="data" direction="out" type="s"/>n"
  80. "    </method>n"
  81. "  </interface>n"
  82. "  <interface name="org.freedesktop.MediaPlayer">n"
  83. "    <method name="Identity">n"
  84. "      <arg type="s" direction="out" />n"
  85. "    </method>n"
  86. "    <method name="MprisVersion">n"
  87. "      <arg type="(qq)" direction="out" />n"
  88. "    </method>n"
  89. "    <method name="Quit">n"
  90. "    </method>n"
  91. "  </interface>n"
  92. "</node>n"
  93. ;
  94. const char* psz_introspection_xml_data_player =
  95. "<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN"n"
  96. ""http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd">n"
  97. "<node>"
  98. "  <interface name="org.freedesktop.DBus.Introspectable">n"
  99. "    <method name="Introspect">n"
  100. "      <arg name="data" direction="out" type="s"/>n"
  101. "    </method>n"
  102. "  </interface>n"
  103. "  <interface name="org.freedesktop.MediaPlayer">n"
  104. "    <method name="GetStatus">n"
  105. "      <arg type="(iiii)" direction="out" />n"
  106. "    </method>n"
  107. "    <method name="Prev">n"
  108. "    </method>n"
  109. "    <method name="Next">n"
  110. "    </method>n"
  111. "    <method name="Stop">n"
  112. "    </method>n"
  113. "    <method name="Play">n"
  114. "    </method>n"
  115. "    <method name="Pause">n"
  116. "    </method>n"
  117. "    <method name="Repeat">n"
  118. "      <arg type="b" direction="in" />n"
  119. "    </method>n"
  120. "    <method name="VolumeSet">n"
  121. "      <arg type="i" direction="in" />n"
  122. "    </method>n"
  123. "    <method name="VolumeGet">n"
  124. "      <arg type="i" direction="out" />n"
  125. "    </method>n"
  126. "    <method name="PositionSet">n"
  127. "      <arg type="i" direction="in" />n"
  128. "    </method>n"
  129. "    <method name="PositionGet">n"
  130. "      <arg type="i" direction="out" />n"
  131. "    </method>n"
  132. "    <method name="GetMetadata">n"
  133. "      <arg type="a{sv}" direction="out" />n"
  134. "    </method>n"
  135. "    <method name="GetCaps">n"
  136. "      <arg type="i" direction="out" />n"
  137. "    </method>n"
  138. "    <signal name="TrackChange">n"
  139. "      <arg type="a{sv}"/>n"
  140. "    </signal>n"
  141. "    <signal name="StatusChange">n"
  142. "      <arg type="(iiii)"/>n"
  143. "    </signal>n"
  144. "    <signal name="CapsChange">n"
  145. "      <arg type="i"/>n"
  146. "    </signal>n"
  147. "  </interface>n"
  148. "</node>n"
  149. ;
  150. const char* psz_introspection_xml_data_tracklist =
  151. "<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN"n"
  152. ""http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd">n"
  153. "<node>"
  154. "  <interface name="org.freedesktop.DBus.Introspectable">n"
  155. "    <method name="Introspect">n"
  156. "      <arg name="data" direction="out" type="s"/>n"
  157. "    </method>n"
  158. "  </interface>n"
  159. "  <interface name="org.freedesktop.MediaPlayer">n"
  160. "    <method name="AddTrack">n"
  161. "      <arg type="s" direction="in" />n"
  162. "      <arg type="b" direction="in" />n"
  163. "      <arg type="i" direction="out" />n"
  164. "    </method>n"
  165. "    <method name="DelTrack">n"
  166. "      <arg type="i" direction="in" />n"
  167. "    </method>n"
  168. "    <method name="GetMetadata">n"
  169. "      <arg type="i" direction="in" />n"
  170. "      <arg type="a{sv}" direction="out" />n"
  171. "    </method>n"
  172. "    <method name="GetCurrentTrack">n"
  173. "      <arg type="i" direction="out" />n"
  174. "    </method>n"
  175. "    <method name="GetLength">n"
  176. "      <arg type="i" direction="out" />n"
  177. "    </method>n"
  178. "    <method name="SetLoop">n"
  179. "      <arg type="b" direction="in" />n"
  180. "    </method>n"
  181. "    <method name="SetRandom">n"
  182. "      <arg type="b" direction="in" />n"
  183. "    </method>n"
  184. "    <signal name="TrackListChange">n"
  185. "      <arg type="i" />n"
  186. "    </signal>n"
  187. "  </interface>n"
  188. "</node>n"
  189. ;
  190. /* Handle  messages reception */
  191. DBUS_METHOD( handle_root );
  192. DBUS_METHOD( handle_player );
  193. DBUS_METHOD( handle_tracklist );
  194. static const DBusObjectPathVTable vlc_dbus_root_vtable = {
  195.         NULL, handle_root, /* handler function */
  196.         NULL, NULL, NULL, NULL
  197. };
  198. static const DBusObjectPathVTable vlc_dbus_player_vtable = {
  199.         NULL, handle_player, /* handler function */
  200.         NULL, NULL, NULL, NULL
  201. };
  202. static const DBusObjectPathVTable vlc_dbus_tracklist_vtable = {
  203.         NULL, handle_tracklist, /* handler function */
  204.         NULL, NULL, NULL, NULL
  205. };