BEAST/BSE - Better Audio System and Sound Engine  0.8.2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
sfiglue.hh
Go to the documentation of this file.
00001  // Licensed GNU LGPL v2.1 or later: http://www.gnu.org/licenses/lgpl.html
00002 #ifndef __SFI_GLUE_H__
00003 #define __SFI_GLUE_H__
00004 
00005 #include <sfi/sfiprimitives.hh>
00006 #include <sfi/sfiring.hh>
00007 #include <sfi/sfiparams.hh>
00008 
00009 G_BEGIN_DECLS
00010 
00011 /* Glue proxy (object handle) description in terms of
00012  * supported interfaces and property names
00013  */
00014 typedef struct {
00015   guint   ref_count;
00016   gchar  *type_name;            /* interface type name */
00017   guint   n_ifaces;
00018   gchar **ifaces;/*NULL-term*/  /* supported interfaces */
00019   guint   n_props;
00020   gchar **props;/*NULL-term*/   /* property names */
00021 } SfiGlueIFace;
00022 
00023 gchar*          sfi_glue_base_iface     (void);
00024 const gchar**   sfi_glue_iface_children (const gchar    *iface_name);
00025 SfiGlueIFace*   sfi_glue_describe_iface (const gchar    *iface_name);
00026 SfiGlueIFace*   sfi_glue_iface_ref      (SfiGlueIFace   *iface);
00027 void            sfi_glue_iface_unref    (SfiGlueIFace   *iface);
00028 
00029 
00030 
00031 /* Procedure description in terms of it's parameters
00032  */
00033 typedef struct {
00034   guint        ref_count;
00035   gchar       *name;
00036   gchar       *help;
00037   gchar       *authors;
00038   gchar       *license;
00039   GParamSpec  *ret_param;
00040   guint        n_params;
00041   GParamSpec **params;
00042 } SfiGlueProc;
00043 
00044 SfiGlueProc*    sfi_glue_describe_proc          (const gchar    *proc_name);
00045 SfiGlueProc*    sfi_glue_proc_ref               (SfiGlueProc    *proc);
00046 void            sfi_glue_proc_unref             (SfiGlueProc    *proc);
00047 const gchar**   sfi_glue_list_proc_names        (void);
00048 const gchar**   sfi_glue_list_method_names      (const gchar    *iface_name);
00049 
00050 GValue*         sfi_glue_call_seq               (const gchar    *proc_name,
00051                                                  SfiSeq         *params);
00052 GValue*         sfi_glue_call_valist            (const gchar    *proc_name,
00053                                                  guint8          first_arg_type,
00054                                                  va_list         var_args);
00055 void            sfi_glue_vcall_void             (const gchar    *proc_name,
00056                                                  guint8          first_arg_type,
00057                                                  ...);
00058 SfiBool         sfi_glue_vcall_bool             (const gchar    *proc_name,
00059                                                  guint8          first_arg_type,
00060                                                  ...);
00061 SfiInt          sfi_glue_vcall_int              (const gchar    *proc_name,
00062                                                  guint8          first_arg_type,
00063                                                  ...);
00064 SfiNum          sfi_glue_vcall_num              (const gchar    *proc_name,
00065                                                  guint8          first_arg_type,
00066                                                  ...);
00067 SfiReal         sfi_glue_vcall_real             (const gchar    *proc_name,
00068                                                  guint8          first_arg_type,
00069                                                  ...);
00070 const gchar*    sfi_glue_vcall_string           (const gchar    *proc_name,
00071                                                  guint8          first_arg_type,
00072                                                  ...);
00073 const gchar*    sfi_glue_vcall_choice           (const gchar    *proc_name,
00074                                                  guint8          first_arg_type,
00075                                                  ...);
00076 SfiProxy        sfi_glue_vcall_proxy            (const gchar    *proc_name,
00077                                                  guint8          first_arg_type,
00078                                                  ...);
00079 SfiSeq*         sfi_glue_vcall_seq              (const gchar    *proc_name,
00080                                                  guint8          first_arg_type,
00081                                                  ...);
00082 SfiRec*         sfi_glue_vcall_rec              (const gchar    *proc_name,
00083                                                  guint8          first_arg_type,
00084                                                  ...);
00085 SfiFBlock*      sfi_glue_vcall_fblock           (const gchar    *proc_name,
00086                                                  guint8          first_arg_type,
00087                                                  ...);
00088 SfiBBlock*      sfi_glue_vcall_bblock           (const gchar    *proc_name,
00089                                                  guint8          first_arg_type,
00090                                                  ...);
00091 GValue*         sfi_glue_client_msg             (const gchar    *msg,
00092                                                  GValue         *value);
00093 
00094 
00095 /* Glue context table, abstracts middleware implementation */
00096 typedef struct _SfiGlueContext SfiGlueContext;
00097 typedef struct {
00098   /* core functions */
00099   SfiGlueIFace*         (*describe_iface)               (SfiGlueContext *context,
00100                                                          const gchar    *iface);
00101   SfiGlueProc*          (*describe_proc)                (SfiGlueContext *context,
00102                                                          const gchar    *proc_name);
00103   gchar**               (*list_proc_names)              (SfiGlueContext *context);
00104   gchar**               (*list_method_names)            (SfiGlueContext *context,
00105                                                          const gchar    *iface_name);
00106   gchar*                (*base_iface)                   (SfiGlueContext *context);
00107   gchar**               (*iface_children)               (SfiGlueContext *context,
00108                                                          const gchar    *iface_name);
00109   GValue*               (*exec_proc)                    (SfiGlueContext *context,
00110                                                          const gchar    *proc_name,
00111                                                          SfiSeq         *params);
00112   /* proxy functions */
00113   gchar*                (*proxy_iface)                  (SfiGlueContext *context,
00114                                                          SfiProxy        proxy);
00115   gboolean              (*proxy_is_a)                   (SfiGlueContext *context,
00116                                                          SfiProxy        proxy,
00117                                                          const gchar    *iface);
00118   gchar**               (*proxy_list_properties)        (SfiGlueContext *context,
00119                                                          SfiProxy        proxy,
00120                                                          const gchar    *first_ancestor,
00121                                                          const gchar    *last_ancestor);
00122   GParamSpec*           (*proxy_get_pspec)              (SfiGlueContext *context,
00123                                                          SfiProxy        proxy,
00124                                                          const gchar    *prop_name);
00125   SfiSCategory          (*proxy_get_pspec_scategory)    (SfiGlueContext *context,
00126                                                          SfiProxy        proxy,
00127                                                          const gchar    *prop_name);
00128   void                  (*proxy_set_property)           (SfiGlueContext *context,
00129                                                          SfiProxy        proxy,
00130                                                          const gchar    *prop,
00131                                                          const GValue   *value);
00132   GValue*               (*proxy_get_property)           (SfiGlueContext *context,
00133                                                          SfiProxy        proxy,
00134                                                          const gchar    *prop);
00135   gboolean              (*proxy_watch_release)          (SfiGlueContext *context,
00136                                                          SfiProxy        proxy);
00137   gboolean              (*proxy_request_notify)         (SfiGlueContext *context,
00138                                                          SfiProxy        proxy,
00139                                                          const gchar    *signal,
00140                                                          gboolean        enable_notify);
00141   void                  (*proxy_processed_notify)       (SfiGlueContext *context,
00142                                                          guint           notify_id);
00143   /* misc extensions */
00144   GValue*               (*client_msg)                   (SfiGlueContext *context,
00145                                                          const gchar    *msg,
00146                                                          GValue         *value);
00147   /* framework functions */
00148   SfiRing*              (*fetch_events)                 (SfiGlueContext *context);
00149   SfiRing*              (*list_poll_fds)                (SfiGlueContext *context);
00150   void                  (*destroy)                      (SfiGlueContext *context);
00151 } SfiGlueContextTable;
00152 
00153 
00154 /* --- Glue Context --- */
00155 struct _SfiGlueContext
00156 {
00157   /*< private >*/
00158   SfiGlueContextTable    table;
00159   gulong                 seq_hook_id;
00160   GHashTable            *gc_hash;
00161   SfiUStore             *proxies;
00162   SfiRing               *pending_events;
00163 };
00164 void            sfi_glue_context_push           (SfiGlueContext *context);
00165 SfiGlueContext* sfi_glue_context_current        (void);
00166 void            sfi_glue_context_pop            (void);
00167 SfiRing*        sfi_glue_context_list_poll_fds  (void);
00168 void            sfi_glue_context_process_fd     (void);
00169 gboolean        sfi_glue_context_pending        (void);
00170 void            sfi_glue_context_dispatch       (void);
00171 SfiSeq*         sfi_glue_context_fetch_event    (void);
00172 void            sfi_glue_context_destroy        (SfiGlueContext *context);
00173 
00174 
00175 /* --- Glue utilities --- */
00176 #ifdef __cplusplus
00177 typedef void (*SfiGlueGcFreeFunc) (void*);
00178 #else
00179 typedef void *SfiGlueGcFreeFunc;  // FIXME: remove C-legacy
00180 #endif
00181 
00182 void            sfi_glue_gc_add         (gpointer           data,
00183                                          SfiGlueGcFreeFunc  free_func);
00184 void            sfi_glue_gc_remove      (gpointer           data,
00185                                          SfiGlueGcFreeFunc  free_func);
00186 void            sfi_glue_gc_free_now    (gpointer           data,
00187                                          SfiGlueGcFreeFunc  free_func);
00188 void            sfi_glue_gc_run         (void);
00189 
00190 
00191 /* --- internal --- */
00192 gboolean        _sfi_glue_gc_test               (gpointer        data,
00193                                                  gpointer        free_func);
00194 SfiGlueIFace*   sfi_glue_iface_new              (const gchar    *iface_name);
00195 SfiGlueProc*    sfi_glue_proc_new               (const gchar    *proc_name);
00196 void            sfi_glue_proc_add_param         (SfiGlueProc    *proc,
00197                                                  GParamSpec     *param);
00198 void            sfi_glue_proc_add_ret_param     (SfiGlueProc    *proc,
00199                                                  GParamSpec     *param);
00200 gboolean       _sfi_glue_proxy_request_notify   (SfiProxy        proxy,
00201                                                  const gchar    *signal,
00202                                                  gboolean        enable_notify);
00203 
00204 
00205 /* --- implementations --- */
00206 void    _sfi_init_glue            (void);
00207 void sfi_glue_context_common_init (SfiGlueContext            *context,
00208                                    const SfiGlueContextTable *vtable);
00209 static inline SfiGlueContext*
00210 sfi_glue_fetch_context (const gchar *floc);
00211 static inline SfiGlueContext*
00212 sfi_glue_fetch_context (const gchar *floc)
00213 {
00214   SfiGlueContext *context = sfi_glue_context_current ();
00215   if (!context)
00216     g_error ("%s: SfiGlue function called without context (use sfi_glue_context_push())", floc);
00217   return context;
00218 }
00219 
00220 G_END_DECLS
00221 
00222 #endif /* __SFI_GLUE_H__ */
00223 
00224 /* vim:set ts=8 sts=2 sw=2: */
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines