Back to index

im-sdk  12.3.91
xaux_object_classes.c
Go to the documentation of this file.
00001 #include <stdio.h>
00002 
00003 #ifdef HAVE_CONFIG_H
00004 #include "config.h"
00005 #endif
00006 
00007 #include "xaux_object.h"
00008 
00009 #ifdef USE_AUX_IF_VERSION_2
00010 #include "imbean.h"
00011 #endif
00012 
00013 #define MAX_NUM_AUX_MODULES  16 
00014 #define MAX_LEN_CLASS_NAME   128
00015 
00016 #define ATOM_NUM_XAUX_MODULE 32
00017 
00018 CARD16  utfname_xaux_object[] = {
00019         'c','o','m','.','s','u','n','.',
00020         'i','i','i','m','.',
00021         'c','l','e','.',
00022         'a','u','x','.',
00023         'o','b','j','e','c','t',
00024 };
00025 
00026 CARD16  utfname_xaux_manager_gtk2[] = {
00027         'c','o','m','.','s','u','n','.',
00028         'i','i','i','m','.',
00029         'c','l','e','.',
00030         'a','u','x','.',
00031         'm','a','n','a','g','e','r','.',
00032         'g','t','k','2'
00033 };
00034 
00035 CARD16  utfname_xaux_module_palette[] = {
00036         'c','o','m','.','s','u','n','.',
00037         'i','i','i','m','.',
00038         'c','l','e','.',
00039         'a','u','x','.',
00040         'p','a','l','e','t','t','e',
00041 };
00042 
00043 CARD16  utfname_xaux_module_composite[] = {
00044         'c','o','m','.','s','u','n','.',
00045         'i','i','i','m','.',
00046         'c','l','e','.',
00047         'a','u','x','.',
00048         'c','o','m','p','o','s','i','t','e',
00049 };
00050 
00051 xaux_class_t xaux_classes[MAX_NUM_AUX_MODULES] = {
00052        {
00053               XAUX_MODULE_PALETTE_CLASS_NAME,  1,
00054               LE_AUX_MODULES_DIR "/gtk2/palette_aux_gtk2",
00055               (Window)0, (Window)0, (Window)0,
00056               (Atom)0, (Atom)0, (Atom)0,  (Atom)0,
00057               { (Atom)0 }, ATOM_NUM_XAUX_MODULE, 0, 
00058               { (Atom)0 }, ATOM_NUM_XAUX_MODULE, 0,
00059               utfname_xaux_module_palette,
00060        },
00061        {
00062               XAUX_MODULE_COMPOSITE_CLASS_NAME,  1,
00063               LE_AUX_MODULES_DIR "/gtk2/composite_aux_gtk2",
00064               (Window)0, (Window)0, (Window)0,
00065               (Atom)0, (Atom)0, (Atom)0,  (Atom)0,
00066               { (Atom)0 }, ATOM_NUM_XAUX_MODULE, 0, 
00067               { (Atom)0 }, ATOM_NUM_XAUX_MODULE, 0,
00068               utfname_xaux_module_composite,
00069        },
00070 #if 0
00071        {
00072               XAUX_MANAGER_GTK2_CLASS_NAME,  1,
00073               LE_AUX_MODULES_DIR "/gtk2/aux_manager_gtk2",
00074               (Window)0, (Window)0, (Window)0,
00075               (Atom)0, (Atom)0, (Atom)0,  (Atom)0,
00076               { (Atom)0 }, ATOM_NUM_XAUX_MODULE, 0, 
00077               { (Atom)0 }, ATOM_NUM_XAUX_MODULE, 0,
00078               utfname_xaux_manager_gtk2,
00079        },
00080 #endif
00081        {
00082               NULL,  -1,
00083               NULL,
00084               (Window)0, (Window)0, (Window)0,
00085               (Atom)0, (Atom)0, (Atom)0,  (Atom)0,
00086               { (Atom)0 }, 0, 0, 
00087               { (Atom)0 }, 0, 0,
00088               (CARD16 *)NULL,
00089        },
00090 };
00091 
00092 extern aux_method_t xaux_so_methods;
00093 
00094 aux_dir_t aux_dir[MAX_NUM_AUX_MODULES] = {
00095        {
00096               { sizeof(utfname_xaux_object),
00097                 (CARD16 *)utfname_xaux_object,
00098               },
00099               &xaux_so_methods,
00100        },
00101        {
00102               { sizeof(utfname_xaux_module_palette),
00103                 (CARD16 *)utfname_xaux_module_palette,
00104               },
00105               &xaux_so_methods,
00106        },
00107        {
00108               { sizeof(utfname_xaux_module_composite),
00109                 (CARD16 *)utfname_xaux_module_composite,
00110               },
00111               &xaux_so_methods,
00112        },
00113 #if 0
00114        {
00115               { sizeof(utfname_xaux_manager_gtk2),
00116                 (CARD16 *)utfname_xaux_manager_gtk2,
00117               },
00118               &xaux_so_methods,
00119        },
00120 #endif
00121        { {0, NULL}, NULL},
00122 };
00123 
00124 int aux_classes_print(xaux_class_t *aux_classes)
00125 {
00126 #ifdef DEBUG
00127        xaux_class_t *p;
00128 
00129        if (aux_classes == NULL) return (AUX_OK);
00130 
00131        printf("\nxaux_classes: \n");
00132        for (p=aux_classes; p->classname; p++) {
00133               printf("class_name: %s, exec: %s\n", p->classname, p->extexec);
00134        }
00135 
00136        return (AUX_OK);
00137 #endif
00138 }
00139 
00140 #ifdef USE_AUX_IF_VERSION_2
00141 
00142 #define XAUX_MODULES_FILE "aux_modules.xml"
00143 
00144 CARD16 utfname_aux_modules_custom[MAX_NUM_AUX_MODULES][MAX_LEN_CLASS_NAME];
00145 char classname_aux_modules_custom[MAX_NUM_AUX_MODULES][MAX_LEN_CLASS_NAME];
00146 char exec_aux_modules_custom[MAX_NUM_AUX_MODULES][MAX_LEN_CLASS_NAME];
00147 
00148 int aux_dir_print(aux_dir_t *aux_dir)
00149 {
00150 #ifdef DEBUG
00151        aux_dir_t *p;
00152 
00153        if (aux_dir == NULL) return (AUX_OK);
00154 
00155        printf("\naux_dir: \n");
00156        for (p=aux_dir; p->name.ptr; p++) {
00157               char *class_name = NULL;
00158               class_name = (char *)xaux_so_get_classname_from_utfname(p->name.ptr, p->name.len);
00159               if (class_name) {
00160                      printf("class_name: %s, len: %d\n", class_name, p->name.len);
00161                      free ((char *)class_name);
00162               }
00163        }
00164 
00165        return (AUX_OK);
00166 #endif
00167 }
00168 
00169 char *aux_dir_get_full_file_path(char *file_path)
00170 {
00171        int len;
00172        char *full_file_path = NULL;
00173 
00174        if (!file_path || !*file_path)
00175               return (NULL);
00176 
00177        if (file_path[0] == '/') {
00178               len = strlen (file_path);
00179 
00180               full_file_path = (char *)calloc(len + 1, sizeof(char));
00181               if (full_file_path == NULL) return (NULL);
00182 
00183               snprintf(full_file_path, len + 1, "%s", file_path);
00184        } else {
00185               len = strlen(LE_AUX_MODULES_DIR) + 1 + strlen (file_path);
00186 
00187               full_file_path = (char *)calloc(len + 1, sizeof(char));
00188               if (full_file_path == NULL) return (NULL);
00189 
00190               snprintf(full_file_path, len + 1, "%s/%s", LE_AUX_MODULES_DIR, file_path);
00191        }
00192 
00193        return (full_file_path);
00194 }
00195 
00196 int aux_dir_get_custom_aux_modules(char *aux_dir_config_file)
00197 {
00198 #define AUX_MODULE_CLASS_NAME  "class_name"
00199 #define AUX_MODULE_OBJECT_FILE "object_file"
00200 
00201        aux_dir_t *dir;
00202        int num_aux_dirs;
00203        int num_aux_dirs_custom;
00204 
00205        xaux_class_t *class;
00206        int num_aux_classes;
00207        int num_aux_classes_custom;
00208 
00209        IbmlData *ibml_data;
00210        IbmlCategory    *ibml_category;
00211        IbmlElement     *ibml_element;
00212        IbmlProperty    *ibml_property;
00213        int i, j, k, n;
00214 
00215        char *id, *scope;
00216        char *name, *value;
00217 
00218        num_aux_dirs = 0;
00219        for (dir=aux_dir; dir->name.ptr; dir++) num_aux_dirs++;
00220 
00221        num_aux_classes = 0;
00222        for (class=xaux_classes; class->classname; class++) num_aux_classes++;
00223 
00224        DEBUG_printf("num_aux_dirs: %d, num_aux_classes: %d\n", num_aux_dirs, num_aux_classes);
00225        ibml_data = (IbmlData *)imbean_config_new_from_file(aux_dir_config_file);
00226        if (ibml_data == NULL) return(AUX_FAIL);
00227 
00228        num_aux_classes_custom = 0;
00229        num_aux_dirs_custom = 0;
00230        for (k=0; k<ibml_data->num_categories; k++) {
00231               ibml_category = ibml_data->categories[k];
00232 
00233               if (ibml_category->scope == NULL) continue;
00234               if (! *ibml_category->scope) continue;
00235               if (strcasecmp(ibml_category->scope, "gtk2") && 
00236                   strcasecmp(ibml_category->scope, "qt") &&
00237                   strcasecmp(ibml_category->scope, "binary"))
00238                      continue;
00239 
00240               for (i=0; i<ibml_category->num_elements; i++) {
00241                      CARD16 *utfname_ptr;
00242                      char *aux_module_class_name = NULL;
00243                      char *aux_module_object_file = NULL;
00244                      char *aux_module_file_path = NULL;
00245 
00246                      ibml_element = ibml_category->elements[i];
00247                      if (!ibml_element) continue;
00248 
00249                      id = (char *)ibml_element->id;
00250                      scope = (char *)ibml_element->scope;
00251                      DEBUG_printf("id:%s, scope:%s\n", id?id:"NULL", scope?scope:"NULL");
00252                      if (!id || !*id) continue;
00253 
00254                      for(j=0; j<ibml_element->num_properties; j++) {
00255                             ibml_property = ibml_element->properties[j];
00256                             if (!ibml_property) continue;
00257 
00258                             name = (char *)ibml_property->name;
00259                             if (!name || !*name)
00260                                    continue;
00261 
00262                             value = (char *)ibml_property->value;
00263                             if (!value || !*value)
00264                                    continue;
00265 
00266                             if (!strcasecmp(name, AUX_MODULE_CLASS_NAME)) {
00267                                    aux_module_class_name = value;
00268                             } else if (!strcasecmp(name, AUX_MODULE_OBJECT_FILE)) {
00269                                    aux_module_object_file = value;
00270                             }
00271                      }
00272 
00273                      if (!aux_module_class_name || !*aux_module_class_name)
00274                             continue;
00275                      if (!aux_module_object_file || !*aux_module_object_file)
00276                             continue;
00277 
00278                      DEBUG_printf("category: %s, classname: %s, object: %s\n",
00279                             ibml_category->scope, aux_module_class_name, aux_module_object_file);
00280 
00281                      if (num_aux_dirs + num_aux_dirs_custom >= MAX_NUM_AUX_MODULES-1)
00282                             break;
00283 
00284                      utfname_ptr = utfname_aux_modules_custom[num_aux_dirs_custom];
00285                      for (n=0; n<strlen(aux_module_class_name); n++) {
00286                             if (n >= MAX_LEN_CLASS_NAME-1) break;
00287                             utfname_ptr[n] = aux_module_class_name[n];
00288                      }
00289                      utfname_ptr[n] = 0;
00290 
00291                      dir = &(aux_dir[num_aux_dirs + num_aux_dirs_custom]);
00292                      dir->name.ptr = utfname_ptr;
00293                      dir->name.len = n * sizeof(CARD16);
00294                      dir->method   = &xaux_so_methods;
00295 
00296                      num_aux_dirs_custom ++;
00297 
00298                      if (strcasecmp(ibml_category->scope, "binary"))
00299                             continue;
00300 
00301                      aux_module_file_path =  aux_dir_get_full_file_path(aux_module_object_file);
00302                      if (aux_module_file_path == NULL)
00303                             continue;
00304 
00305                      strncpy(exec_aux_modules_custom[num_aux_classes_custom],
00306                             aux_module_file_path,
00307                             MAX_LEN_CLASS_NAME-1);
00308                      free((char *)aux_module_file_path);
00309 
00310                      class = &(xaux_classes[num_aux_classes + num_aux_classes_custom]);
00311                      strncpy(classname_aux_modules_custom[num_aux_classes_custom],
00312                             aux_module_class_name,
00313                             MAX_LEN_CLASS_NAME-1);
00314                      class->classname = classname_aux_modules_custom[num_aux_classes_custom];
00315                      class->index = 0;
00316                      class->extexec = exec_aux_modules_custom[num_aux_classes_custom];
00317                      class->sowin = 0;
00318                      class->clientwin = 0;
00319                      class->utfname = utfname_ptr;
00320                      
00321                      num_aux_classes_custom ++;
00322               }
00323        }
00324 
00325        dir = &(aux_dir[num_aux_dirs + num_aux_dirs_custom]);
00326        dir->name.ptr = NULL;
00327        dir->name.len = 0;
00328        dir->method   = NULL;
00329 
00330        class = &(xaux_classes[num_aux_classes + num_aux_classes_custom]);
00331        class->classname = NULL;
00332 
00333        ibml_data_free(ibml_data);
00334        return (AUX_OK);
00335 }
00336 
00337 aux_dir_t *aux_dir_init()
00338 {
00339        char *aux_dir_config_file = NULL;
00340 
00341        aux_dir_config_file =  aux_dir_get_full_file_path(XAUX_MODULES_FILE);
00342 
00343        if (aux_dir_config_file) {
00344               DEBUG_printf("aux_dir_config_file: %s\n", aux_dir_config_file);
00345               aux_dir_get_custom_aux_modules(aux_dir_config_file);
00346               free ((char *)aux_dir_config_file);
00347        }
00348 
00349 #ifdef DEBUG
00350        aux_dir_print(aux_dir);
00351        aux_classes_print(xaux_classes);
00352 #endif
00353 
00354        return (aux_dir);
00355 }
00356 
00357 #endif