Back to index

im-sdk  12.3.91
IMBasicObject.hh
Go to the documentation of this file.
00001 #ifndef IMBasicObject_HH_
00002 #define IMBasicObject_HH_
00003 #include <list>
00004 #include <map>
00005 #include <functional>
00006 #include <IMProtocolStruct.h>
00007 #include <IMLock.hh>
00008 #include "basictype.hh"
00009 #include "SunIM.h"
00010 
00011 class IMLang
00012 {
00013     string identifier;
00014     u16string hrn;
00015   public:
00016     const char* get_id() const
00017     { return identifier.c_str(); }
00018     const u16string& get_hrn() const
00019     { return hrn; }
00020 
00021     bool operator <(const IMLang &b)
00022     {
00023        return (identifier.compare(b.identifier) < 0);
00024     }
00025     bool operator ==(const IMLang &b)
00026     {
00027        return (identifier.compare(b.identifier) == 0);
00028     }
00029 
00030     IMLang(
00031        const char *id,
00032        const u16string& x_hrn
00033     )
00034        : identifier(id), hrn(x_hrn)
00035     {}
00036 };
00037 
00038 inline bool
00039 operator==(const IMLang& lang, const std::string& l)
00040 {
00041     return (l.compare(lang.get_id()) == 0);
00042 }
00043 // some older g++ needs
00044 inline bool
00045 operator!=(const IMLang&lang, const std::string& l)
00046 {
00047     return (l.compare(lang.get_id()) != 0);
00048 }
00049 
00050 typedef list<IMLang> IMLangList;
00051 
00052 /* class to hold information of Input Method Engine */
00053 class IMImeInfo
00054 {
00055     bool enable;
00056     string ime_id;
00057     u16string imename;
00058     u16string version;
00059     u16string description;
00060     u16string author;
00061     u16string copyright;
00062     u16string reserved1;
00063     u16string reserved2;
00064 
00065   public:
00066     const bool get_enable() const
00067     { return enable; }
00068     const string& get_ime_id() const
00069     { return ime_id; }
00070     const u16string& get_imename() const
00071     { return imename; }
00072     const u16string& get_version() const
00073     { return version; }
00074     const u16string& get_description() const
00075     { return description; }
00076     const u16string& get_author() const
00077     { return author; }
00078     const u16string& get_copyright() const
00079     { return copyright; }
00080     const u16string& get_reserved1() const
00081     { return reserved1; }
00082     const u16string& get_reserved2() const
00083     { return reserved2; }
00084     void set_enable(bool flag)
00085     { enable = flag; }
00086 
00087     IMImeInfo(
00088        const bool x_enable,
00089         const string& x_ime_id,
00090         const u16string& x_imename,
00091         const u16string& x_version,
00092         const u16string& x_description,
00093         const u16string& x_author,
00094         const u16string& x_copyright,
00095         const u16string& x_reserved1,
00096         const u16string& x_reserved2
00097     ) : enable(x_enable), ime_id(x_ime_id), imename(x_imename), version(x_version), description(x_description), author(x_author), copyright(x_copyright), reserved1(x_reserved1), reserved2(x_reserved2)
00098     {}
00099 };
00100 
00101 typedef list<IMImeInfo> IMImeInfoList;
00102 
00103 /*
00104   SYMBOL-ID
00105   4   : CARD32 :  MSB  --------------------------> LSB
00106   +----------+---------+-+-----------+
00107   | reserved | TYPEBIT |1|  IDBITS   |
00108   +----------+---------+-+-----------+
00109   |<--8bits->|<--8bit->| |<-15bits-->|
00110   TYPEBITS : 0:RESERVED for ATTRIBID
00111   1: operation,
00112 
00113   2: variable(number),
00114   3: valriable(bool),
00115   4: variable(char),
00116   5: variable(mtext),
00117   6: variable(event),
00118 
00119   0x12:property(number),
00120   0x13:property(bool),
00121   0x14:property(char),
00122   0x15:property(mtext),
00123   0x16:property(event),
00124 
00125   0x81:EIMIL,
00126   0x82:IMDESCRIPTOR,
00127   0x83:BINARY_GUI,
00128   0x84:BINARY_LWE,
00129   0x85:JAVA_GUI,
00130   0x86:JAVA_LWE
00131 */
00132 class IMObject
00133 {
00134   public:
00135     enum OBJTYPE {
00136            UNKNOWN,
00137 
00138            OPERATION = 1,
00139 
00140            NUMBER_VARIABLE = 2,
00141            BOOL_VARIABLE = 3,
00142            CHAR_VARIABLE = 4,
00143            MTEXT_VARIABLE = 5,
00144            EVENT_VARIABLE = 6,
00145 
00146            NUMBER_PROPERTY = 0x12,
00147            BOOL_PROPERTY = 0x13,
00148            CHAR_PROPERTY = 0x14,
00149            MTEXT_PROPERTY = 0x15,
00150            EVENT_PROPERTY = 0x16,
00151 
00152            DOWNLOADABLE_OBJ_MASK = 0x80,
00153            EIMIL_CONFIG = 0x81,
00154            IMDESCRIPTOR = 0x82,
00155            BINARY_GUI = 0x83,
00156            BINARY_LWE = 0x84,
00157            JAVA_GUI = 0x85,
00158            JAVA_LWE = 0x86,
00159            SCRIPT_GUI = 0x87,
00160            SCRIPT_LWE = 0x88
00161     };
00162     enum OBJCATEGORY {
00163            UNKNOWN_OBJECT = -1,
00164            GUI_OBJECT = 0,
00165            LWE_OBJECT = 1,
00166            SYNTAX_RULE_OBJECT = 2,
00167            IM_MANAGER_RULE_OBJECT = 3,
00168            PRELOADING_LWE_OBJECT = 4
00169     };
00170   private:
00171     CARD32BIT id;
00172     enum OBJTYPE type;
00173     bool downloadable;
00174     
00175   protected:
00176     IMObject(enum OBJTYPE type, bool downloadble);
00177     virtual ~IMObject() {};
00178   public:
00179     CARD16BIT get_attribid() const
00180     {
00181        if (!downloadablep()) return 0;
00182        return ((id & ((1 << 15) - 1)) | (1 << 15));
00183     }
00184     CARD32BIT get_fullid() const
00185     { return id; }
00186     bool downloadablep() const
00187     { return downloadable; }
00188     enum OBJTYPE get_type() const
00189     { return type; }
00190     enum OBJCATEGORY get_category() const;
00191 };
00192 
00193 class IMDescriptorMatchPredicate;
00194 class IMDescriptor : public IMObject
00195 {
00196     u16string imname;
00197     u16string hrn;
00198     string domainname;
00199     IMLangList langs;
00200     IMImeInfoList imeinfos;
00201     const IMHotkeyProfileStruct *hotkey_profile;
00202 
00203   public:
00204     const u16string& get_imname() const
00205     { return imname; }
00206     const u16string& get_hrn() const
00207     { return hrn; }
00208     const IMLangList* get_languages() const
00209     { return &langs; }
00210     const IMImeInfoList* get_imeinfos() const
00211     { return &imeinfos; }
00212     const IMHotkeyProfileStruct* get_hotkey_profile() const
00213     { return hotkey_profile; }
00214 
00215     IMDescriptor(
00216        const u16string& imname,
00217        const u16string& hrn,
00218        const string& domainname,
00219        const IMLangList& langs,
00220        const IMImeInfoList& imeinfos,
00221        IMHotkeyProfileStruct *hkps
00222     );
00223   friend class IMDescriptorMatchPredicate;
00224 };
00225 typedef list<IMDescriptor> IMDescriptorList;
00226 
00227 // IMDescriptor predicate.
00228 class IMDescriptorMatchPredicate : public unary_function<IMDescriptor, bool>
00229 {
00230     const u16string* ppattern;
00231   public:
00232     IMDescriptorMatchPredicate(const u16string* pattern)
00233     { ppattern = pattern; }
00234     bool operator()(
00235        const IMDescriptor &d
00236     ) const;
00237 };
00238 
00239 
00240 class IMObjectWithDesc : public IMObject
00241 {
00242     CARD8BIT *pbinrep;
00243     string leid;
00244     int size;
00245     list<u16string> jarfile_classes;
00246     u16string hrn;
00247     u16string domain;
00248     u16string path;
00249     u16string scope;
00250     u16string signature;
00251     u16string basepath;
00252     u16string encoding;
00253 
00254     void set_size();
00255 
00256   public:
00257     int get_object_size() const
00258     { return size; }
00259     const u16string& get_domain() const
00260     { return domain; }
00261     const u16string& get_hrn() const
00262     { return hrn; }
00263     const u16string& get_signature() const
00264     { return signature; }
00265     const u16string& get_scope() const
00266     { return scope; }
00267     const u16string& get_path() const
00268     { return path; }
00269     const list<u16string>& get_classes() const
00270     { return jarfile_classes; }
00271     virtual const CARD8BIT* get_binary_representation();
00272 
00273   public:
00274     void log_obj();
00275     IMObjectWithDesc(const IMObjectDescriptorStruct &desc);
00276     virtual ~IMObjectWithDesc();
00277 };
00278 typedef list<IMObjectWithDesc*> IMObjectWithDescList;
00279 
00280 // singleton class
00281 class IMObjectMgr
00282 {
00283     int attribid_counter;
00284     static IMObjectMgr *pimobjmgr;
00285     IMSyncObject sync_object;
00286     typedef map<CARD16BIT, IMObject*> IMObjectMap;
00287     IMObjectMap objmap;
00288 
00289     CARD16BIT get_attribid(CARD32BIT fullid);
00290 
00291     IMObjectMgr();
00292   public:
00293     static IMObjectMgr* get_instance()
00294     { return pimobjmgr; }
00295     bool add(
00296        IMObject *pobj,
00297        CARD32BIT &id
00298     );
00299     IMObject* get_object_from_fullid(
00300        CARD32BIT id
00301     );
00302     IMObject* get_object_from_attribid(
00303        CARD16BIT id
00304     );
00305     static IMObjectMgr* construct();
00306 
00307   friend class IMObject;
00308 };
00309 
00310 #endif /* not IMHANDLER_HH_ */
00311 
00312 /* Local Variables: */
00313 /* c-file-style: "iiim-project" */
00314 /* End: */