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

midi

开发平台:

Unix_Linux

  1. /*****************************************************************************
  2.  * events.h: events definitions
  3.  * Interface used to send events.
  4.  *****************************************************************************
  5.  * Copyright (C) 2007 the VideoLAN team
  6.  * $Id: cba7fb9e2b182645aeaa3d1ecd79da0ac771c857 $
  7.  *
  8.  * Authors: Pierre d'Herbemont
  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. #ifndef VLC_EVENTS_H
  25. # define VLC_EVENTS_H
  26. #include <vlc_arrays.h>
  27. #include <vlc_meta.h>
  28. /**
  29.  * file
  30.  * This file is the interface definition for events
  31.  * (implementation in src/misc/events.c)
  32.  */
  33. /*****************************************************************************
  34.  * Documentation
  35.  *****************************************************************************/
  36. /*
  37.  **** Background
  38.  *
  39.  * This implements a way to send and receive event for an object (which can be
  40.  * a simple C struct or less).
  41.  *
  42.  * This is in direct concurrency with the Variable based Callback
  43.  * (see src/misc/variables.c).
  44.  *
  45.  * It has the following advantages over Variable based Callback:
  46.  * - No need to implement the whole VLC_COMMON_MEMBERS in the object,
  47.  * thus it reduce it size. This is especially true for input_item_t which
  48.  * doesn't have VLC_COMMON_MEMBERS. This is the first reason of existence of
  49.  * this implementation.
  50.  * - Libvlc can easily be based upon that.
  51.  * - Existing event are clearly declared (in include/vlc_events.h)
  52.  *
  53.  *
  54.  **** Example usage
  55.  *
  56.  * (vlc_cool_object_t doesn't need to have the VLC_COMMON_MEMBERS.)
  57.  *
  58.  * struct vlc_cool_object_t
  59.  * {
  60.  *        ...
  61.  *        vlc_event_manager_t p_event_manager;
  62.  *        ...
  63.  * }
  64.  *
  65.  * vlc_my_cool_object_new()
  66.  * {
  67.  *        ...
  68.  *        vlc_event_manager_init( &p_self->p_event_manager, p_self, p_a_libvlc_object );
  69.  *        vlc_event_manager_register_event_type(p_self->p_event_manager,
  70.  *                vlc_MyCoolObjectDidSomething, p_e)
  71.  *        ...
  72.  * }
  73.  *
  74.  * vlc_my_cool_object_release()
  75.  * {
  76.  *         ...
  77.  *         vlc_event_manager_fini( &p_self->p_event_manager );
  78.  *         ...
  79.  * }
  80.  *
  81.  * vlc_my_cool_object_do_something()
  82.  * {
  83.  *        ...
  84.  *        vlc_event_t event;
  85.  *        event.type = vlc_MyCoolObjectDidSomething;
  86.  *        event.u.my_cool_object_did_something.what_it_did = kSomething;
  87.  *        vlc_event_send( &p_self->p_event_manager, &event );
  88.  * }
  89.  * */
  90.   /*****************************************************************************
  91.  * Event Type
  92.  *****************************************************************************/
  93. /* Private structure defined in misc/events.c */
  94. struct vlc_event_listeners_group_t;
  95. /* Event manager type */
  96. typedef struct vlc_event_manager_t
  97. {
  98.     void * p_obj;
  99.     vlc_mutex_t object_lock;
  100.     vlc_mutex_t event_sending_lock;
  101.     vlc_object_t *p_parent_object;
  102.     DECL_ARRAY(struct vlc_event_listeners_group_t *) listeners_groups;
  103. } vlc_event_manager_t;
  104. /* List of event */
  105. /* Be sure to keep sync-ed with misc/events.c debug name table */
  106. typedef enum vlc_event_type_t {
  107.     /* Input (thread) events */
  108.     vlc_InputStateChanged,
  109.     vlc_InputSelectedStreamChanged,
  110.     /* Input item events */
  111.     vlc_InputItemMetaChanged,
  112.     vlc_InputItemSubItemAdded,
  113.     vlc_InputItemDurationChanged,
  114.     vlc_InputItemPreparsedChanged,
  115.     vlc_InputItemNameChanged,
  116.     vlc_InputItemInfoChanged,
  117.     vlc_InputItemErrorWhenReadingChanged,
  118.     /* Service Discovery event */
  119.     vlc_ServicesDiscoveryItemAdded,
  120.     vlc_ServicesDiscoveryItemRemoved,
  121.     vlc_ServicesDiscoveryStarted,
  122.     vlc_ServicesDiscoveryEnded
  123. } vlc_event_type_t;
  124. /* Event definition */
  125. typedef struct vlc_event_t
  126. {
  127.     vlc_event_type_t type;
  128.     void * p_obj; /* Sender object, automatically filled by vlc_event_send() */
  129.     union vlc_event_type_specific
  130.     {
  131.         /* Input (thread) events */
  132.         struct vlc_input_state_changed
  133.         {
  134.             int new_state;
  135.         } input_state_changed;
  136.         struct vlc_input_selected_stream_changed
  137.         {
  138.             void * unused;
  139.         } input_selected_stream_changed;
  140.         /* Input item events */
  141.         struct vlc_input_item_meta_changed
  142.         {
  143.             vlc_meta_type_t meta_type;
  144.         } input_item_meta_changed;
  145.         struct vlc_input_item_subitem_added
  146.         {
  147.             input_item_t * p_new_child;
  148.         } input_item_subitem_added;
  149.         struct vlc_input_item_duration_changed
  150.         {
  151.             mtime_t new_duration;
  152.         } input_item_duration_changed;
  153.         struct vlc_input_item_preparsed_changed
  154.         {
  155.             int new_status;
  156.         } input_item_preparsed_changed;
  157.         struct vlc_input_item_name_changed
  158.         {
  159.             const char * new_name;
  160.         } input_item_name_changed;
  161.         struct vlc_input_item_info_changed
  162.         {
  163.             void * unused;
  164.         } input_item_info_changed;
  165.         struct input_item_error_when_reading_changed
  166.         {
  167.             bool new_value;
  168.         } input_item_error_when_reading_changed;
  169.         /* Service discovery events */
  170.         struct vlc_services_discovery_item_added
  171.         {
  172.             input_item_t * p_new_item;
  173.             const char * psz_category;
  174.         } services_discovery_item_added;
  175.         struct vlc_services_discovery_item_removed
  176.         {
  177.             input_item_t * p_item;
  178.         } services_discovery_item_removed;
  179.         struct vlc_services_discovery_started
  180.         {
  181.             void * unused;
  182.         } services_discovery_started;
  183.         struct vlc_services_discovery_ended
  184.         {
  185.             void * unused;
  186.         } services_discovery_ended;
  187.     } u;
  188. } vlc_event_t;
  189. /* Event callback type */
  190. typedef void ( *vlc_event_callback_t )( const vlc_event_t *, void * );
  191.  /*****************************************************************************
  192.  * Event manager
  193.  *****************************************************************************/
  194. /*
  195.  * p_obj points to the object that owns the event manager, and from
  196.  * which events are sent
  197.  * p_obj is here to give us a libvlc instance
  198.  */
  199. #define vlc_event_manager_init_with_vlc_object(a,b) 
  200.             vlc_event_manager_init( a, b, b )
  201. #define vlc_event_manager_init(a,b,c) 
  202.             __vlc_event_manager_init(a, b, VLC_OBJECT(c))
  203. VLC_EXPORT(int, __vlc_event_manager_init, ( vlc_event_manager_t * p_em,
  204.                                           void * p_obj, vlc_object_t * ));
  205. /*
  206.  * Destroy
  207.  */
  208. VLC_EXPORT(void, vlc_event_manager_fini, ( vlc_event_manager_t * p_em ));
  209. /*
  210.  * Tells a specific event manager that it will handle event_type object
  211.  */
  212. VLC_EXPORT(int, vlc_event_manager_register_event_type,
  213.                 ( vlc_event_manager_t * p_em, vlc_event_type_t event_type ));
  214. /*
  215.  * Send an event to the listener attached to this p_em.
  216.  */
  217. VLC_EXPORT(void, vlc_event_send, ( vlc_event_manager_t * p_em,
  218.                                    vlc_event_t * p_event ));
  219. /*
  220.  * Add a callback for an event.
  221.  */
  222. #define vlc_event_attach(a, b, c, d) __vlc_event_attach(a, b, c, d, #c)
  223. VLC_EXPORT(int, __vlc_event_attach, ( vlc_event_manager_t * p_event_manager,
  224.                                       vlc_event_type_t event_type,
  225.                                       vlc_event_callback_t pf_callback,
  226.                                       void *p_user_data,
  227.                                       const char * psz_debug_name ));
  228. /*
  229.  * Remove a callback for an event.
  230.  */
  231. VLC_EXPORT(int, vlc_event_detach, ( vlc_event_manager_t *p_event_manager,
  232.                                     vlc_event_type_t event_type,
  233.                                     vlc_event_callback_t pf_callback,
  234.                                     void *p_user_data ));
  235. #endif /* VLC_EVENTS_H */