Back to index

im-sdk  12.3.91
object.c
Go to the documentation of this file.
00001 /*
00002   object.c
00003 */
00004 
00005 #include <stdlib.h>
00006 #include <string.h>
00007 #include "iiimcfint.h"
00008 
00009 /********************************************************************************
00010                             internal services
00011 ********************************************************************************/
00012 
00013 static IIIMF_status
00014 get_imvalues(
00015     IIIMCF_handle_rec *ph,
00016     int num,
00017     IIIMP_card16 *pattribids,
00018     IIIMP_message **ppmes
00019 )
00020 {
00021     IIIMF_status st;
00022     IIIMP_card16_list *pc16;
00023     IIIMP_message *pmes;
00024 
00025     pc16 = iiimp_card16_list_new(ph->data_s, num, pattribids);
00026     if (!pc16) return IIIMF_STATUS_MALLOC;
00027     pmes = iiimp_getimvalues_new(ph->data_s, ph->im_id, pc16);
00028     if (!pmes) {
00029        iiimp_card16_list_delete(ph->data_s, pc16);
00030        return IIIMF_STATUS_MALLOC;
00031     }
00032     st = iiimcf_request_message(ph, pmes, NULL, IM_GETIMVALUES_REPLY, ppmes);
00033 
00034     return st;
00035 }
00036 
00037 static IIIMCF_downloaded_object_rec*
00038 register_downloaded_object(
00039     IIIMCF_handle_rec *ph,
00040     const IIIMCF_object_descriptor *pod,
00041     IIIMP_imattribute *pimattr
00042 )
00043 {
00044     IIIMP_string *pimstr;
00045     IIIMCF_downloaded_object_rec *po;
00046 
00047     for (po = ph->pdownloaded_objs; po; po = po->pnext) {
00048        if (po->pod == pod) return po;
00049     }
00050 
00051     po = (IIIMCF_downloaded_object_rec*) malloc(sizeof(*po));
00052     if (!po) return NULL;
00053     memset(po, 0, sizeof(*po));
00054     po->pod = pod;
00055 
00056     switch (pod->predefined_id) {
00057       case IIIMP_IMATTRIBUTE_CHARACTER_CONVERSION_DEFINITION_RULE:
00058        pimstr = pimattr->value.ccdef->contents;
00059        po->v.str = iiimcf_make_string(pimstr->ptr, pimstr->len);
00060        if (!po->v.str) {
00061           free(po);
00062           return NULL;
00063        }
00064        break;
00065 
00066       case IIIMP_IMATTRIBUTE_BINARY_GUI_OBJECT:
00067       case IIIMP_IMATTRIBUTE_BINARY_LIGHT_WEIGHT_ENGINE_OBJECT:
00068       case IIIMP_IMATTRIBUTE_SCRIPT_GUI_OBJECT:
00069       case IIIMP_IMATTRIBUTE_SCRIPT_LIGHT_WEIGHT_ENGINE_OBJECT:
00070        pimstr = pimattr->value.binaryfile_object->object;
00071        po->v.str = iiimcf_make_string(pimstr->ptr, pimstr->len);
00072        if (!po->v.str) {
00073           free(po);
00074           return NULL;
00075        }
00076        break;
00077 
00078       case IIIMP_IMATTRIBUTE_JAR_GUI_OBJECT:
00079       case IIIMP_IMATTRIBUTE_JAR_LIGHT_WEIGHT_ENGINE_OBJECT:
00080       default:
00081        /* Nothing to do with it!
00082          Treat it as an invalid object. */
00083        break;
00084     }
00085     po->pnext = ph->pdownloaded_objs;
00086     ph->pdownloaded_objs = po;
00087 
00088     return po;
00089 }
00090 
00091 void
00092 iiimcf_delete_all_downloaded_objects(
00093     IIIMCF_handle_rec *ph
00094 )
00095 {
00096     IIIMCF_downloaded_object_rec *po, *po2;
00097 
00098     for (po = ph->pdownloaded_objs; po; po = po2) {
00099        po2 = po->pnext;
00100        switch (po->pod->predefined_id) {
00101          case IIIMP_IMATTRIBUTE_BINARY_GUI_OBJECT:
00102          case IIIMP_IMATTRIBUTE_BINARY_LIGHT_WEIGHT_ENGINE_OBJECT:
00103          case IIIMP_IMATTRIBUTE_SCRIPT_GUI_OBJECT:
00104          case IIIMP_IMATTRIBUTE_SCRIPT_LIGHT_WEIGHT_ENGINE_OBJECT:
00105           if (po->v.str) free(po->v.str);
00106           break;
00107        }
00108        free(po);
00109     }
00110     
00111     return;
00112 }
00113 
00114 /********************************************************************************
00115                                  APIs
00116 ********************************************************************************/
00117 
00118 IIIMF_status
00119 iiimcf_get_downloaded_object_descriptor(
00120     IIIMCF_downloaded_object object,
00121     const IIIMCF_object_descriptor **ppdesc
00122 )
00123 {
00124     IIIMCF_downloaded_object_rec *po = (IIIMCF_downloaded_object_rec*) object;
00125 
00126     *ppdesc = po->pod;
00127 
00128     return IIIMF_STATUS_SUCCESS;
00129 }
00130 
00131 IIIMF_status
00132 iiimcf_get_downloaded_object_filename(
00133     IIIMCF_downloaded_object object,
00134     const IIIMP_card16 **pfilename
00135 )
00136 {
00137     IIIMCF_downloaded_object_rec *po = (IIIMCF_downloaded_object_rec*) object;
00138 
00139     switch (po->pod->predefined_id) {
00140       case IIIMP_IMATTRIBUTE_BINARY_GUI_OBJECT:
00141       case IIIMP_IMATTRIBUTE_BINARY_LIGHT_WEIGHT_ENGINE_OBJECT:
00142       case IIIMP_IMATTRIBUTE_SCRIPT_GUI_OBJECT:
00143       case IIIMP_IMATTRIBUTE_SCRIPT_LIGHT_WEIGHT_ENGINE_OBJECT:
00144        *pfilename = po->v.str;
00145        break;
00146 
00147       default:
00148        return IIIMF_STATUS_ARGUMENT;
00149     }
00150 
00151     return IIIMF_STATUS_SUCCESS;
00152 }
00153 
00154 #if 0
00155 IIIMF_status
00156 iiimcf_get_object_binary(
00157     IIIMCF_downloaded_object object,
00158     const IIIMP_card8 **ppbinary
00159 )
00160 {
00161     /* Currently, there is no supported
00162        objects that has binary data. */
00163     return IIIMF_STATUS_SUCCESS;
00164 }
00165 #endif
00166 
00167 IIIMF_status
00168 iiimcf_get_downloaded_objects(
00169     IIIMCF_handle handle,
00170     int num_objs,
00171     const IIIMCF_object_descriptor **ppdesc,
00172     IIIMCF_downloaded_object *pobjs
00173 )
00174 {
00175     IIIMCF_handle_rec *ph = (IIIMCF_handle_rec*) handle;
00176     IIIMF_status st;
00177     IIIMP_card16 *pattribids;
00178     IIIMP_imattribute *pimattr;
00179     IIIMCF_downloaded_object_rec *po;
00180     IIIMP_message *pmes;
00181     int i;
00182 
00183     pattribids = (IIIMP_card16*) malloc(sizeof(*pattribids) * num_objs);
00184     if (!pattribids) return IIIMF_STATUS_MALLOC;
00185 
00186     for (i = 0; i < num_objs; i++) {
00187        pattribids[i] = ppdesc[i]->dynamic_id;
00188     }
00189 
00190     st = get_imvalues(ph, num_objs, pattribids, &pmes);
00191     free(pattribids);
00192     if (st != IIIMF_STATUS_SUCCESS) return st;
00193 
00194     st = IIIMF_STATUS_SUCCESS;
00195     pimattr = pmes->v.getimvalues_reply.attr_list;
00196     for (i = 0; i < num_objs; i++) {
00197        if (!pimattr) {
00198            st = IIIMF_STATUS_FAIL;
00199            break;
00200        }
00201        if (pimattr->id_dyn !=  ppdesc[i]->dynamic_id) {
00202            st = IIIMF_STATUS_FAIL;
00203            break;
00204        }
00205        ASSERT(pimattr->id_pre == ppdesc[i]->predefined_id);
00206        po = register_downloaded_object(ph, ppdesc[i], pimattr);
00207        if (!po) {
00208            st = IIIMF_STATUS_MALLOC;
00209            break;
00210        }
00211        pobjs[i] = (IIIMCF_downloaded_object) po;
00212        pimattr = pimattr->next;
00213     }
00214 
00215     iiimp_message_delete(ph->data_s, pmes);
00216     return st;
00217 }
00218 
00219 /* Local Variables: */
00220 /* c-file-style: "iiim-project" */
00221 /* End: */