00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include "trace.h"
00022 #include "parserImpl.h"
00023
00024 #define IILC_MODULE MODULE_TYPE_APP
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037 extern int yydebug;
00038
00039
00040
00041
00042 extern FILE * yyin;
00043
00044
00045
00046
00047 static pthread_key_t g_keyParserThis;
00048
00052 static pthread_once_t parse_init = PTHREAD_ONCE_INIT;
00053
00057 #define PARSER_INITIALISE (void) pthread_once(&parse_init, parserInitialise);
00058
00059
00060
00061
00062
00063
00064
00065
00066
00070 typedef struct _tag_parser_context
00071 {
00072 LPCONFIG_FILE pFile;
00073
00074 LPCONFIG_DISPLAY pDisplay;
00075
00076 LPCONFIG_DEVICE pDevice;
00077
00078 LPCONFIG_MODULE pModule;
00079
00080 LPCONFIG_OBJECT pObject;
00081
00082 LPCONFIG_SCREEN pScreen;
00083 }
00084 PARSER_CONTEXT, * LP_PARSER_CONTEXT;
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096 void parserInitialise(void)
00097 {
00098
00099 (void) pthread_key_create(&g_keyParserThis, NULL);
00100 }
00101
00102 LP_PARSER_CONTEXT parserGetContext()
00103 {
00104 LP_PARSER_CONTEXT pContext = NULL;
00105
00106 IILC_TRACE_ENTRY(IILC_MODULE, T_parserGetCurrentConfig);
00107
00108 PARSER_INITIALISE;
00109
00110
00111 pContext = (LP_PARSER_CONTEXT) pthread_getspecific(g_keyParserThis);
00112 if (pContext == NULL) {
00113 printf("Failed to obtain parser on current thread\n");
00114 exit(1);
00115 }
00116
00117 traceDebug(IILC_TRACE_CONTEXT, "pContext %p", pContext);
00118 IILC_TRACE_EXIT;
00119 return pContext;
00120 }
00121
00122
00123 int parserParse(LPCONFIG_FILE * ppFile, const char * pszFileName)
00124 {
00125 int rc = 0;
00126 LP_PARSER_CONTEXT pContext = NULL;
00127
00128 IILC_TRACE_ENTRY(IILC_MODULE, T_parserParse);
00129 traceDebug(IILC_TRACE_CONTEXT,
00130 "pszConfigFile %p, ppFile %p", pszFileName, ppFile);
00131
00132 PARSER_INITIALISE;
00133
00134
00135 pContext = (LP_PARSER_CONTEXT) calloc(1, sizeof(PARSER_CONTEXT));
00136
00137
00138 configFileCreate(&(pContext->pFile), pszFileName);
00139
00140
00141 pthread_setspecific(g_keyParserThis, (void *) pContext);
00142
00143
00144 yyin = fopen(pszFileName, "r");
00145 yydebug = 0;
00146
00147
00148 yyparse();
00149
00150
00151 fclose(yyin);
00152
00153
00154 *ppFile = pContext->pFile;
00155
00156
00157 free(pContext);
00158
00159
00160 pthread_setspecific(g_keyParserThis, NULL);
00161
00162 IILC_TRACE_EXIT_RC(rc);
00163 return rc;
00164 }
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176 void parserDeviceBegin(char * pszDevice)
00177 {
00178 configDeviceCreate(&(parserGetContext()->pDevice), pszDevice);
00179 }
00180
00181 void parserDeviceSetClass(char * pszClass)
00182 {
00183 configDeviceSetClass(parserGetContext()->pDevice, pszClass);
00184 }
00185
00186 void parserDeviceSetPort(char * pszPort)
00187 {
00188 configDeviceSetPort(parserGetContext()->pDevice, pszPort);
00189 }
00190
00191 int parserDeviceObjectCreate(int object_id, char * pszName, enum displayObjectType type,
00192 LPCONFIG_OBJECT * ppObject)
00193 {
00194 int rc = 0;
00195
00196 return rc;
00197 }
00198
00199 int parserDeviceObjectFind(LPCONFIG_DEVICE pDevice, enum displayObjectType type,
00200 int object_id, LPCONFIG_OBJECT * ppObject)
00201 {
00202 int rc = 0;
00203
00204 return rc;
00205 }
00206
00207
00208 void parserDeviceObjectUse(enum displayObjectType type, int id, char * pszName)
00209 {
00210 }
00211
00212 void parserDeviceEnd(void)
00213 {
00214 LP_PARSER_CONTEXT pContext = parserGetContext();
00215
00216 configDisplaySetDevice(pContext->pDisplay, pContext->pDevice);
00217
00218 pContext->pDevice = NULL;
00219 }
00220
00221
00222
00223
00224 void parserDisplayBegin(const char * pszDisplay)
00225 {
00226 configDisplayCreate(&(parserGetContext()->pDisplay), pszDisplay);
00227
00228 }
00229
00230 void parserDisplayEnd()
00231 {
00232 LP_PARSER_CONTEXT pContext = parserGetContext();
00233
00234 configFileAddDisplay(pContext->pFile, pContext->pDisplay);
00235
00236 pContext->pDisplay = NULL;
00237 }
00238
00239
00240
00241
00242
00243
00244
00245
00246
00247
00248
00249
00250
00251
00252
00253
00254 void parserModuleBegin(char * pszModule)
00255 {
00256 configModuleCreate(&(parserGetContext()->pModule), pszModule);
00257 }
00258
00259 void parserModuleSetLibrary(char * pszLibrary)
00260 {
00261 configModuleSetLibrary(parserGetContext()->pModule, pszLibrary);
00262 }
00263
00264 void parserModuleControlObject(enum displayObjectType object_type, int object_id)
00265 {
00266 configModuleControlObject(parserGetContext()->pModule, object_type, object_id);
00267 }
00268
00269 void parserModuleReportObject(enum displayObjectType object_type, int object_id,
00270 const char * report_as)
00271 {
00272 configModuleReportObject(parserGetContext()->pModule, object_type, object_id, report_as);
00273 }
00274
00275 void parserModuleVirtualObject(int module_id, int device_id, const char * pszObject)
00276 {
00277 configModuleVirtualObject(parserGetContext()->pModule, module_id, device_id, pszObject);
00278 }
00279
00280 void parserModuleEnd()
00281 {
00282 LP_PARSER_CONTEXT pContext = parserGetContext();
00283
00284 configDisplayAddModule(pContext->pDisplay, pContext->pModule);
00285
00286 pContext->pModule = NULL;
00287 }
00288
00289
00290
00291
00292
00293
00294
00295 void parserScreenBegin(char * pszScreen)
00296 {
00297 configScreenCreate(&(parserGetContext()->pScreen), pszScreen);
00298 }
00299
00300
00301 void parserScreenEnd(void)
00302 {
00303 LP_PARSER_CONTEXT pContext = parserGetContext();
00304
00305 configDisplayAddScreen(pContext->pDisplay, pContext->pScreen);
00306
00307 pContext->pScreen = NULL;
00308 }
00309
00310
00311 void parserScreenShowModule(char * pszModule, int size_x, int size_y, int pos_x, int pos_y)
00312 {
00313 configScreenShowModule(parserGetContext()->pScreen, pszModule, size_x, size_y, pos_x, pos_y);
00314 }
00315
00316