UniMRCP  1.7.0
mrcp_engine_plugin.h
Go to the documentation of this file.
1 /*
2  * Copyright 2008-2015 Arsen Chaloyan
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef MRCP_ENGINE_PLUGIN_H
18 #define MRCP_ENGINE_PLUGIN_H
19 
20 /**
21  * @file mrcp_engine_plugin.h
22  * @brief MRCP Engine Plugin
23  */
24 
25 #include "apr_version.h"
26 #include "apt_log.h"
27 #include "mrcp_engine_types.h"
28 
30 
31 /** Let the plugin symbols be always exported as C functions */
32 #ifdef __cplusplus
33 #define MRCP_PLUGIN_EXTERN_C extern "C"
34 #else
35 #define MRCP_PLUGIN_EXTERN_C extern
36 #endif
37 
38 /** Plugin export defines */
39 #ifdef WIN32
40 #define MRCP_PLUGIN_DECLARE(type) MRCP_PLUGIN_EXTERN_C __declspec(dllexport) type
41 #else
42 #define MRCP_PLUGIN_DECLARE(type) MRCP_PLUGIN_EXTERN_C type
43 #endif
44 
45 /** [REQUIRED] Symbol name of the main entry point in plugin DSO */
46 #define MRCP_PLUGIN_ENGINE_SYM_NAME "mrcp_plugin_create"
47 /** [REQUIRED] Symbol name of the vesrion number entry point in plugin DSO */
48 #define MRCP_PLUGIN_VERSION_SYM_NAME "mrcp_plugin_version"
49 /** [IMPLIED] Symbol name of the log accessor entry point in plugin DSO */
50 #define MRCP_PLUGIN_LOGGER_SYM_NAME "mrcp_plugin_logger_set"
51 /** [IMPLIED] Symbol name of the log source accessor entry point in plugin DSO */
52 #define MRCP_PLUGIN_LOG_SOURCE_SYM_NAME "mrcp_plugin_log_source_set"
53 
54 /** Prototype of engine creator (entry point of plugin DSO) */
55 typedef mrcp_engine_t* (*mrcp_plugin_creator_f)(apr_pool_t *pool);
56 
57 /** Prototype of log accessor (entry point of plugin DSO) */
59 
60 /** Prototype of log source accessor (entry point of plugin DSO) */
62 
63 /** Declare this macro in plugins to use log routine of the server */
64 #define MRCP_PLUGIN_LOGGER_IMPLEMENT \
65  MRCP_PLUGIN_DECLARE(apt_bool_t) mrcp_plugin_logger_set(apt_logger_t *logger) \
66  { apt_log_instance_set(logger); \
67  return TRUE; } \
68  MRCP_PLUGIN_DECLARE(void) mrcp_plugin_log_source_set(apt_log_source_t *orig_log_source) \
69  { apt_def_log_source_set(orig_log_source); }
70 
71 /** Declare this macro in plugins to use log routine of the server */
72 #define MRCP_PLUGIN_LOG_SOURCE_IMPLEMENT(LOG_SOURCE, LOG_SOURCE_TAG) \
73  apt_log_source_t *LOG_SOURCE = &def_log_source; \
74  MRCP_PLUGIN_DECLARE(apt_bool_t) mrcp_plugin_logger_set(apt_logger_t *logger) \
75  { apt_log_instance_set(logger); \
76  return TRUE; } \
77  MRCP_PLUGIN_DECLARE(void) mrcp_plugin_log_source_set(apt_log_source_t *orig_log_source) \
78  { apt_def_log_source_set(orig_log_source); \
79  apt_log_source_assign(LOG_SOURCE_TAG,&LOG_SOURCE); }
80 
81 /** Declare this macro in plugins to set plugin version */
82 #define MRCP_PLUGIN_VERSION_DECLARE \
83  MRCP_PLUGIN_DECLARE(mrcp_plugin_version_t) mrcp_plugin_version; \
84  mrcp_plugin_version_t mrcp_plugin_version = \
85  {PLUGIN_MAJOR_VERSION, PLUGIN_MINOR_VERSION, PLUGIN_PATCH_VERSION};
86 
87 
88 /** major version
89  * Major API changes that could cause compatibility problems for older
90  * plugins such as structure size changes. No binary compatibility is
91  * possible across a change in the major version.
92  */
93 #define PLUGIN_MAJOR_VERSION 1
94 
95 /** minor version
96  * Minor API changes that do not cause binary compatibility problems.
97  * Reset to 0 when upgrading PLUGIN_MAJOR_VERSION
98  */
99 #define PLUGIN_MINOR_VERSION 7
100 
101 /** patch level
102  * The Patch Level never includes API changes, simply bug fixes.
103  * Reset to 0 when upgrading PLUGIN_MINOR_VERSION
104  */
105 #define PLUGIN_PATCH_VERSION 0
106 
107 
108 /**
109  * Check at compile time if the plugin version is at least a certain
110  * level.
111  */
112 #define PLUGIN_VERSION_AT_LEAST(major,minor,patch) \
113 (((major) < PLUGIN_MAJOR_VERSION) \
114  || ((major) == PLUGIN_MAJOR_VERSION && (minor) < PLUGIN_MINOR_VERSION) \
115  || ((major) == PLUGIN_MAJOR_VERSION && (minor) == PLUGIN_MINOR_VERSION && (patch) <= PLUGIN_PATCH_VERSION))
116 
117 /** The formatted string of plugin's version */
118 #define PLUGIN_VERSION_STRING \
119  APR_STRINGIFY(PLUGIN_MAJOR_VERSION) "." \
120  APR_STRINGIFY(PLUGIN_MINOR_VERSION) "." \
121  APR_STRINGIFY(PLUGIN_PATCH_VERSION)
122 
123 /** Plugin version */
124 typedef apr_version_t mrcp_plugin_version_t;
125 
126 /** Get plugin version */
127 static APR_INLINE void mrcp_plugin_version_get(mrcp_plugin_version_t *version)
128 {
129  version->major = PLUGIN_MAJOR_VERSION;
130  version->minor = PLUGIN_MINOR_VERSION;
131  version->patch = PLUGIN_PATCH_VERSION;
132 }
133 
134 /** Check plugin version */
135 static APR_INLINE int mrcp_plugin_version_check(mrcp_plugin_version_t *version)
136 {
137  return PLUGIN_VERSION_AT_LEAST(version->major,version->minor,version->patch);
138 }
139 
141 
142 #endif /* MRCP_ENGINE_PLUGIN_H */
#define PLUGIN_PATCH_VERSION
Definition: mrcp_engine_plugin.h:105
apt_bool_t(* mrcp_plugin_log_source_accessor_f)(apt_log_source_t *log_source)
Definition: mrcp_engine_plugin.h:61
#define APT_END_EXTERN_C
Definition: apt.h:38
int apt_bool_t
Definition: apt.h:57
apr_version_t mrcp_plugin_version_t
Definition: mrcp_engine_plugin.h:124
#define PLUGIN_VERSION_AT_LEAST(major, minor, patch)
Definition: mrcp_engine_plugin.h:112
#define PLUGIN_MAJOR_VERSION
Definition: mrcp_engine_plugin.h:93
#define APT_BEGIN_EXTERN_C
Definition: apt.h:36
Basic Logger.
struct apt_log_source_t apt_log_source_t
Definition: apt_log.h:37
apt_bool_t(* mrcp_plugin_log_accessor_f)(apt_logger_t *logger)
Definition: mrcp_engine_plugin.h:58
#define PLUGIN_MINOR_VERSION
Definition: mrcp_engine_plugin.h:99
MRCP Engine Types.
struct apt_logger_t apt_logger_t
Definition: apt_log.h:125
Definition: mrcp_engine_types.h:119