gam-resource-manager: adjust to updated proxied call callback signature.
[profile/ivi/murphy.git] / src / core / method.h
1 /*
2  * Copyright (c) 2012, Intel Corporation
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are
6  * met:
7  *
8  *   * Redistributions of source code must retain the above copyright notice,
9  *     this list of conditions and the following disclaimer.
10  *   * Redistributions in binary form must reproduce the above copyright
11  *     notice, this list of conditions and the following disclaimer in the
12  *     documentation and/or other materials provided with the distribution.
13  *   * Neither the name of Intel Corporation nor the names of its contributors
14  *     may be used to endorse or promote products derived from this software
15  *     without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28  */
29
30 #ifndef __MURPHY_CORE_METHOD_H__
31 #define __MURPHY_CORE_METHOD_H__
32
33 typedef struct mrp_method_descr_s mrp_method_descr_t;
34
35 #include <murphy/core/plugin.h>
36 #include <murphy/core/scripting.h>
37
38
39 /*
40  * exported methods
41  */
42
43 #define __MRP_METHOD_FIELDS(...)                                             \
44     __VA_ARGS__ char *name;              /* method name */                   \
45     __VA_ARGS__ char *signature;         /* method signature */              \
46     /* pointers to exported function, native and boilerplate for scripts */  \
47     void         *native_ptr;                                                \
48     int         (*script_ptr)(mrp_plugin_t *plugin, const char *name,        \
49                               mrp_script_env_t *env);                        \
50     mrp_plugin_t *plugin                 /* exporting plugin (or NULL) */    \
51
52 struct mrp_method_descr_s {
53     __MRP_METHOD_FIELDS(const);
54 };
55
56
57 /*
58  * convenience macros for declaring exported methods
59  */
60
61 #define MRP_EXPORTABLE(_return_type, _func, _arglist)     \
62     static const char _func##_method_signature[] =        \
63         #_return_type" __ "#_arglist;                     \
64                                                           \
65     static _return_type _func _arglist
66
67 /** Declare a method along with a boilerplate to call from scripts. */
68 #define MRP_GENERIC_METHOD(_name, _func, _boilerplate) {  \
69             .name       = _name,                          \
70             .signature  = _func##_method_signature,       \
71             .native_ptr = _func,                          \
72             .script_ptr = _boilerplate,                   \
73             .plugin     = NULL,                           \
74         }
75
76 /** Declare a method that cannot be called from scripts. */
77 #define MRP_NATIVE_METHOD(_name, _func) {                \
78             .name       = _name,                         \
79             .signature  = _func##_method_signature,      \
80             .native_ptr = _func,                         \
81             .script_ptr = NULL,                          \
82             .plugin     = NULL,                          \
83         }
84
85 /** Declare a method that can only be called via a boilerplate for scripts. */
86 #define MRP_SCRIPT_METHOD(_name, _boilerplate) {         \
87             .name       = _name,                         \
88             .signature  = NULL,                          \
89             .native_ptr = NULL,                          \
90             .script_ptr = _boilerplate,                  \
91             .plugin     = NULL,                          \
92         }
93
94
95 /*
96  * convenience macros for declaring imported methods
97  */
98
99 #define MRP_IMPORTABLE(_return_type, _funcptr, _arglist) \
100     static const char _funcptr##_method_signature[] =    \
101         #_return_type" __ "#_arglist;                    \
102                                                          \
103     static _return_type (*_funcptr) _arglist
104
105 #define MRP_IMPORT_METHOD(_name, _funcptr) {             \
106         .name       = _name,                             \
107         .signature  = _funcptr##_method_signature,       \
108         .native_ptr = (void *)&_funcptr,                 \
109     }
110
111 /** Export a method for plugins and/or scripts. */
112 int mrp_export_method(mrp_method_descr_t *method);
113
114 /** Remove an exported method. */
115 int mrp_remove_method(mrp_method_descr_t *method);
116
117 /** Import an exported method. */
118 int mrp_import_method(const char *name, const char *signature,
119                       void **native_ptr,
120                       int (**script_ptr)(mrp_plugin_t *plugin, const char *name,
121                                          mrp_script_env_t *env),
122                       mrp_plugin_t **plugin);
123
124 /** Release an imported method. */
125 int mrp_release_method(const char *name, const char *signature,
126                       void **native_ptr,
127                       int (**script_ptr)(mrp_plugin_t *plugin, const char *name,
128                                          mrp_script_env_t *env));
129
130
131
132 #endif /* __MURPHY_CORE_METHOD_H__ */