Back to index

im-sdk  12.3.91
IMBasicObject.cpp
Go to the documentation of this file.
00001 #include <config.h>
00002 #include <stdio.h>
00003 #include <stdlib.h>
00004 #include "IMBasicObject.hh"
00005 #include "IMUtil.hh"
00006 #include "IMLog.hh"
00007 #include "IMLock.hh"
00008 
00009 /*******************************************************************************
00010                                  IMObject
00011 *******************************************************************************/
00012 
00013 enum IMObject::OBJCATEGORY
00014 IMObject::get_category() const
00015 {
00016     enum OBJTYPE retval;
00017 
00018     retval = get_type();
00019     if (retval == EIMIL_CONFIG) {
00020        return SYNTAX_RULE_OBJECT;
00021     } else if (retval == JAVA_GUI ||
00022               retval == BINARY_GUI ||
00023               retval == SCRIPT_GUI) {
00024        return GUI_OBJECT;
00025     } else if (retval == BINARY_LWE ||
00026               retval == JAVA_LWE ||
00027               retval == SCRIPT_LWE) {
00028        return LWE_OBJECT;
00029     } else if (retval == UNKNOWN ||
00030               retval == IMDESCRIPTOR ||
00031               retval == OPERATION ||
00032               retval == NUMBER_VARIABLE ||
00033               retval == BOOL_VARIABLE ||
00034               retval == CHAR_VARIABLE ||
00035               retval == MTEXT_VARIABLE ||
00036               retval == EVENT_VARIABLE ||
00037               retval == NUMBER_PROPERTY ||
00038               retval == BOOL_PROPERTY ||
00039               retval == CHAR_PROPERTY ||
00040               retval == MTEXT_PROPERTY ||
00041               retval == EVENT_PROPERTY) {
00042        return UNKNOWN_OBJECT;
00043     } else {
00044        ERROR_INTERNAL("Invalid object type.");
00045     }
00046 }
00047 
00048 IMObject::IMObject(enum OBJTYPE x_type, bool x_downloadable)
00049     : type(x_type), downloadable(x_downloadable)
00050 {
00051     IMObjectMgr::get_instance()->add(this, id);
00052 }
00053 
00054 /*******************************************************************************
00055                                  IMLang
00056 *******************************************************************************/
00057 
00058 #if 0
00059 IMLangMatchPredicate::LocaleMap IMLangMatchPredicate::localemap;
00060 
00061 IMLangMatchPredicate::IMLangMatchPredicate(
00062     const string* pattern
00063 )
00064 {
00065     if (localemap.empty()) {
00066        // Japanese locale variant.
00067        localemap["ja_JP.EUC"] = "ja";
00068        localemap["ja_JP.EUC-JP"] = "ja";
00069        localemap["ja_JP.eucJP"] = "ja";
00070        localemap["ja_JP.PCK"] = "ja";
00071        localemap["ja_JP.UTF-8"] = "ja";
00072        localemap["japanese"] = "ja";
00073        // Korean locale variant.
00074        localemap["ko.UTF-8"] = "ko";
00075        localemap["ko_KR.UTF-8"] = "ko";
00076        localemap["ko_KR.EUC"] = "ko";
00077        localemap["ko_KR.EUC-KR"] = "ko";
00078        localemap["korean"] = "ko";
00079        // Chinese locale variant
00080        localemap["zh.UTF-8"] = "zh_CN";
00081        localemap["zh_CN.UTF-8"] = "zh_CN";
00082        localemap["zh_CN.EUC"] = "zh_CN";
00083        localemap["zh_CN.EUC-CN"] = "zn_CN";
00084        localemap["zh_CN.GB18030"] = "zh_CN";
00085        localemap["zh.GBK"] = "zh_CN";
00086        localemap["zh_CN.GBK"] = "zh_CN";
00087        localemap["zh_CN.GB-K"] = "zh_CN";
00088        localemap["zh"] = "zh_CN";
00089        // Taiwanese locale variant
00090        localemap["zh_TW.UTF-8"] = "zh_TW";
00091        localemap["zh_TW.BIG5"] = "zh_TW";
00092        localemap["zh_TW.BIG-5"] = "zh_TW";
00093        localemap["zh_TW.EUC"] = "zh_TW";
00094        localemap["zh_TW.EUC-TW"] = "zh_TW";
00095        // Hongkong locale variant
00096        localemap["zh_HK.UTF-8"] = "zh_HK";
00097        localemap["zh_HK.BIG5HK"] = "zh_HK";
00098        // Thai locale variant
00099        localemap["th_TH.UTF-8"] = "th_TH";
00100        localemap["th_TH.TIS620"] = "th_TH";
00101        localemap["th_TH.ISO8859-11"] = "th_TH";
00102        localemap["th"] = "th_TH";
00103     }
00104     ppattern = pattern;
00105 }
00106 
00107 bool
00108 IMLangMatchPredicate::operator()(
00109     const IMLang &l
00110 ) const
00111 {
00112     if (ppattern->compare(l.identifier) == 0) return true;
00113     LocaleMap::iterator it = localemap.find(l.identifier);
00114     if ((it != localemap.end()) && (ppattern->compare(it->second) == 0)) return true;
00115     return false;
00116 }
00117 #endif
00118 
00119 /*******************************************************************************
00120                                  IMDescriptor
00121 *******************************************************************************/
00122 
00123 IMDescriptor::IMDescriptor(
00124     const u16string& x_imname,
00125     const u16string& x_hrn,
00126     const string& x_domainname,
00127     const IMLangList& x_langs,
00128     const IMImeInfoList& x_imeinfos,
00129     IMHotkeyProfileStruct *hkps
00130 ) : IMObject(IMObject::IMDESCRIPTOR, false), imname(x_imname), hrn(x_hrn),
00131     domainname(x_domainname), langs(x_langs), imeinfos(x_imeinfos), hotkey_profile(hkps)
00132 {
00133 }
00134 
00135 bool
00136 IMDescriptorMatchPredicate::operator()(
00137     const IMDescriptor &d
00138 ) const
00139 {
00140     return (ppattern->compare(d.imname) == 0);
00141 }
00142 
00143 /*******************************************************************************
00144                               IMObjectWithDesc
00145 *******************************************************************************/
00146 
00147 void
00148 IMObjectWithDesc::log_obj()
00149 {
00150     const char none[] = "NONE";
00151     if (IMLog::get_instance()->check(IMLog::DEBUGLOG)) {
00152        LOG_DEBUG("object for %s\n"
00153                 "    object_type      = %d\n"
00154                 "    object id        = %d\n"
00155                 "    object size      = %d\n"
00156                 "    rev. domain name = %s\n"
00157                 "    path             = %s\n"
00158                 "    scope            = %s\n"
00159                 "    signature        = %s\n"
00160                 "    basepath         = %s\n"
00161                 "    encoding         = %s",
00162                 leid.c_str(),
00163                 (int) get_type(),
00164                 (int) get_attribid(),
00165                 size,
00166                 domain.get_charstr() ? domain.get_charstr() : none,
00167                 path.get_charstr() ? path.get_charstr() : none,
00168                 scope.get_charstr() ? scope.get_charstr() : none,
00169                 signature.get_charstr() ? signature.get_charstr() : none,
00170                 basepath.get_charstr() ? basepath.get_charstr() : none,
00171                 encoding.get_charstr() ? encoding.get_charstr() : none
00172        );
00173        list<u16string>::iterator it;
00174        for (it = jarfile_classes.begin();
00175             it != jarfile_classes.end();
00176             it++) {
00177            LOG_DEBUG("    jarfile class    = %s",
00178                     it->get_charstr() ? it->get_charstr() : "Invalid");
00179        }
00180     }
00181 }
00182 
00183 const CARD8BIT*
00184 IMObjectWithDesc::get_binary_representation()
00185 {
00186     enum OBJTYPE retval;
00187 
00188     if (pbinrep) return pbinrep;
00189     retval = get_type();
00190     if (retval == IMObject::JAVA_GUI || retval == IMObject::JAVA_LWE) {
00191        if (size > 0) {
00192           if (!path.get_charstr()) return NULL;
00193           pbinrep = IM_read_file(path.get_charstr(), size);
00194           return pbinrep;
00195        }
00196     }
00197     return NULL;
00198 }
00199 
00200 void
00201 IMObjectWithDesc::set_size()
00202 {
00203     enum OBJTYPE retval;
00204 
00205     retval = get_type();
00206     if (retval == IMObject::JAVA_GUI || retval == IMObject::JAVA_LWE) {
00207        int tsize;
00208        if (!path.get_charstr())
00209            return;
00210        tsize = IM_file_size(path.get_charstr());
00211        if (tsize > 0)
00212            size = tsize;
00213     }
00214 }
00215 
00216 static enum IMObject::OBJTYPE
00217 convert_od_type(IMObjectType ot)
00218 {
00219     switch (ot) {
00220       case IM_DOWNLOADINGOBJECT_JARGUI_TYPE:
00221        return IMObject::JAVA_GUI;
00222       case IM_DOWNLOADINGOBJECT_JARLWE_TYPE:
00223        return IMObject::JAVA_LWE;
00224       case IM_DOWNLOADINGOBJECT_EIMIL_TYPE:
00225        return IMObject::EIMIL_CONFIG;
00226       case IM_DOWNLOADINGOBJECT_BINGUI_TYPE:
00227        return IMObject::BINARY_GUI;
00228       case IM_DOWNLOADINGOBJECT_BINLWE_TYPE:
00229        return IMObject::BINARY_LWE;
00230       case IM_DOWNLOADINGOBJECT_SGUI_TYPE:
00231        return IMObject::SCRIPT_GUI;
00232       case IM_DOWNLOADINGOBJECT_SLWE_TYPE:
00233        return IMObject::SCRIPT_LWE;
00234       default:
00235        ERROR_INTERNAL("Invalid Object Type.");
00236     }
00237     return IMObject::UNKNOWN;
00238 }
00239 
00240 IMObjectWithDesc::IMObjectWithDesc(
00241     const IMObjectDescriptorStruct &desc
00242 ) : IMObject(convert_od_type(desc.type), true)
00243 {
00244     pbinrep = NULL;
00245     leid = desc.leid;
00246     size = desc.size;
00247 
00248     for (unsigned int i = 0; i < desc.count_names; i++) {
00249        jarfile_classes.push_back(u16string(desc.class_names[i]));
00250     }
00251     if (desc.name_length > 0) hrn = u16string(desc.name, desc.name_length);
00252     if (desc.domain) domain = u16string(desc.domain);
00253     if (desc.path) path = u16string(desc.path);
00254     if (desc.scope) scope = u16string(desc.scope);
00255     if (desc.signature) signature = u16string(desc.signature);
00256     if (desc.basepath) basepath = u16string(desc.basepath);
00257     if (desc.encoding) encoding = u16string(desc.encoding);
00258 
00259     set_size();
00260 }
00261 
00262 IMObjectWithDesc::~IMObjectWithDesc()
00263 {
00264     if (pbinrep) free(pbinrep);
00265 }
00266 
00267 /*******************************************************************************
00268                                  IMObjectMgr
00269 *******************************************************************************/
00270 
00271 const CARD32BIT attribid_id_max = ((1 << 15) - 1);
00272 
00273 IMObjectMgr* IMObjectMgr::pimobjmgr = NULL;
00274 
00275 CARD16BIT
00276 IMObjectMgr::get_attribid(
00277     CARD32BIT id
00278 )
00279 {
00280     return (id & ((1 << 16) - 1));
00281 }
00282 
00283 
00284 IMObjectMgr::IMObjectMgr()
00285 {
00286     attribid_counter = 0;
00287 }
00288 
00289 IMObjectMgr*
00290 IMObjectMgr::construct()
00291 {
00292     pimobjmgr = new IMObjectMgr();
00293     return pimobjmgr;
00294 }
00295 
00296 bool
00297 IMObjectMgr::add(
00298     IMObject *pobj,
00299     CARD32BIT &id
00300 )
00301 {
00302     IMLock lock(sync_object);
00303     CARD32BIT aid;
00304 #if 0
00305     if (pobj->downloadablep()) aid = attribid_counter++;
00306     else aid = id_counter++;
00307 #else
00308     aid = attribid_counter++;
00309 #endif
00310     if (aid > attribid_id_max) {
00311        LOG_CRITICAL("Maximum attribid is exceeded!!!.\n"
00312                    "We cannot continue operation any longer.");
00313        // TODO
00314        // we should throw exeption...
00315        exit(255);
00316     }
00317     if (pobj->downloadablep()) aid = aid | (1 << 15);
00318     id = (pobj->get_type() << 16) | aid;
00319     objmap[aid] = pobj;
00320     return true;
00321 }
00322 
00323 IMObject*
00324 IMObjectMgr::get_object_from_fullid(
00325     CARD32BIT id
00326 )
00327 {
00328     return get_object_from_attribid(get_attribid(id));
00329 }
00330 
00331 IMObject*
00332 IMObjectMgr::get_object_from_attribid(
00333     CARD16BIT id
00334 )
00335 {
00336     IMLock lock(sync_object);
00337     IMObjectMap::iterator it = objmap.find(id);
00338     if (it == objmap.end()) return NULL;
00339     return it->second;
00340 }
00341 
00342 /* Local Variables: */
00343 /* c-file-style: "iiim-project" */
00344 /* End: */