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