Back to index

im-sdk  12.3.91
template.c
Go to the documentation of this file.
00001 /*
00002 Copyright 1990-2001 Sun Microsystems, Inc. All Rights Reserved.
00003 
00004 Permission is hereby granted, free of charge, to any person obtaining a
00005 copy of this software and associated documentation files (the
00006 "Software"), to deal in the Software without restriction, including
00007 without limitation the rights to use, copy, modify, merge, publish,
00008 distribute, sublicense, and/or sell copies of the Software, and to
00009 permit persons to whom the Software is furnished to do so, subject to
00010 the following conditions: The above copyright notice and this
00011 permission notice shall be included in all copies or substantial
00012 portions of the Software.
00013 
00014 
00015 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
00016 OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00017 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
00018 IN NO EVENT SHALL THE OPEN GROUP OR SUN MICROSYSTEMS, INC. BE LIABLE
00019 FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
00020 CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH
00021 THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE EVEN IF
00022 ADVISED IN ADVANCE OF THE POSSIBILITY OF SUCH DAMAGES.
00023 
00024 
00025 Except as contained in this notice, the names of The Open Group and/or
00026 Sun Microsystems, Inc. shall not be used in advertising or otherwise to
00027 promote the sale, use or other dealings in this Software without prior
00028 written authorization from The Open Group and/or Sun Microsystems,
00029 Inc., as applicable.
00030 
00031 
00032 X Window System is a trademark of The Open Group
00033 
00034 OSF/1, OSF/Motif and Motif are registered trademarks, and OSF, the OSF
00035 logo, LBX, X Window System, and Xinerama are trademarks of the Open
00036 Group. All other trademarks and registered trademarks mentioned herein
00037 are the property of their respective owners. No right, title or
00038 interest in or to any trademark, service mark, logo or trade name of
00039 Sun Microsystems, Inc. or its licensors is granted.
00040 
00041 */
00042 
00043 #include <stdio.h>
00044 #include <stdlib.h>
00045 #include <string.h>
00046 #include <sys/types.h>
00047 
00048 /*
00049  * header files for SunIM library
00050  */
00051 #include "SunIM.h"
00052 #include "SunIMMMan.h"
00053 #include "SunIMProt.h"
00054 #include "SunIMMthd.h"
00055 #include "SunIMPriv.h"
00056 #include "SunIMCore.h"
00057 #include "SunIMPub.h"
00058 
00059 /*
00060  * define If method prototype
00061  */
00062 Bool if_template_OpenIF(iml_if_t *);
00063 Bool if_template_CloseIF(iml_if_t *);
00064 Bool if_template_GetIFValues(iml_if_t *, IMArgList, int);
00065 Bool if_template_SetIFValues(iml_if_t *, IMArgList, int);
00066 Bool if_template_OpenDesktop(iml_desktop_t *, IMArgList, int);
00067 Bool if_template_CloseDesktop(iml_desktop_t *);
00068 Bool if_template_CreateSC(iml_session_t*, IMArgList, int);
00069 Bool if_template_DestroySC(iml_session_t *);
00070 Bool if_template_GetSCValues(iml_session_t *, IMArgList, int);
00071 Bool if_template_SetSCValues(iml_session_t *, IMArgList, int);
00072 IMText *if_template_ResetSC(iml_session_t *);
00073 void if_template_SetSCFocus(iml_session_t *);
00074 void if_template_UnsetSCFocus(iml_session_t *);
00075 void if_template_SendEvent(iml_session_t *, IMInputEvent * ev);
00076 
00077 /*
00078  * define if_methods_t
00079  */
00080 static if_methods_t if_methods = {
00081     if_template_OpenIF,
00082     if_template_CloseIF,
00083     if_template_GetIFValues,
00084     if_template_SetIFValues,
00085     if_template_OpenDesktop,
00086     if_template_CloseDesktop,
00087     if_template_CreateSC,
00088     if_template_DestroySC,
00089     if_template_GetSCValues,
00090     if_template_SetSCValues,
00091     if_template_ResetSC,
00092     if_template_SetSCFocus,
00093     if_template_UnsetSCFocus,
00094     if_template_SendEvent
00095 };
00096 
00097 /*
00098  * define Human Readable Name as UTFCHAR for LE
00099  */
00100 UTFCHAR lename_string[] = {
00101     0x30c6,
00102     0x30f3,
00103     0x30d7,
00104     0x30ec,
00105     0x30fc,
00106     0x30c8,
00107     0x30a8,
00108     0x30f3,
00109     0x30b8,
00110     0x30f3,
00111 0};
00112 
00113 /*
00114  * define Human Readable Name as UTFCHAR for language
00115  */
00116 UTFCHAR jahrn_string[] = {
00117     0x65e5,
00118     0x672c,
00119     0x8a9e,
00120 0};
00121 
00122 static IMLEName lename = {
00123     "template",                    /* LE id */
00124     lename_string           /* LE HRN */
00125 };
00126 
00127 static IMLocale locales[] = {
00128     {
00129         "ja",               /* locale id */
00130         jahrn_string        /* locale HRN */
00131     },
00132     NULL
00133 };
00134 
00135 #ifdef WIN32
00136 #define EXPORT extern __declspec(dllexport)
00137 
00138 EXPORT
00139 
00140 #endif
00141 
00142 void
00143 if_GetIfInfo(
00144     IMArgList args,
00145     int num_args
00146 )
00147 {
00148     int i;
00149 #ifdef DEBUG
00150     printf("if_GetIfInfo()\n");
00151     printf("  This method is invoked when htt_server retrieves\n");
00152     printf("  if_method_t method table.\n\n");
00153 #endif
00154     for (i = 0; i < num_args; i++, args++) {
00155         switch (args->id) {
00156             case IF_VERSION:
00157                 args->value = (IMArgVal) "1.2";
00158                 break;
00159             case IF_METHOD_TABLE:
00160                 args->value = (IMArgVal) & if_methods;
00161                 break;
00162             case IF_LE_NAME:
00163                 args->value = (IMArgVal) & lename;
00164                 break;
00165             case IF_SUPPORTED_LOCALES:
00166                 args->value = (IMArgVal) & locales;
00167                 break;
00168             case IF_SUPPORTED_OBJECTS:
00169                 break;
00170             case IF_NEED_THREAD_LOCK:
00171                 args->value = (IMArgVal) False;
00172                 break;
00173             default:
00174                 break;
00175             }
00176     }
00177 }
00178 
00179 Bool
00180 if_template_OpenIF(
00181     iml_if_t * If
00182 )
00183 {
00184     printf("if_template_OpenIF()\n");
00185     printf("  This method is invoked when the Language Engine\n");
00186     printf("  is started to use by htt_server\n\n");
00187     return True;
00188 }
00189 
00190 Bool
00191 if_template_CloseIF(
00192     iml_if_t * If
00193 )
00194 {
00195     printf("if_template_CloseIF()\n");
00196     printf("  This method is invoked when htt_server stops to\n");
00197     printf("  to use the Language Engine, which means there is\n");
00198     printf("  no client of the Language Engine is used.\n\n");
00199     return True;
00200 }
00201 
00202 
00203 
00204 Bool
00205 if_template_GetIFValues(
00206     iml_if_t * If,
00207     IMArgList args,
00208     int num_args
00209 )
00210 {
00211     int i;
00212     
00213     printf("if_template_GetIFValues()\n");
00214     printf("  This method is invoked when the Language Engine\n");
00215     printf("  wants to set IF attributes of IM Client.\n\n");
00216     return True;
00217 }
00218 
00219 Bool
00220 if_template_SetIFValues(
00221     iml_if_t * If,
00222     IMArgList args,
00223     int num_args
00224 )
00225 {
00226     printf("if_template_SetIFValues()\n");
00227     printf("  This method is invoked when the IM client\n");
00228     printf("  wants to set IF attributes.\n\n");
00229     
00230     return True;
00231 }
00232 
00233 Bool
00234 if_template_OpenDesktop(
00235     iml_desktop_t * desktop,
00236     IMArgList args,
00237     int num_args
00238 )
00239 {
00240     int i;
00241 
00242     printf("if_template_OpenDesktop()\n");
00243     printf("  This method is invoked when the user start to use\n");
00244     printf("  the desktop, which means the first connection.\n");
00245     
00246     printf("\n");
00247     printf("  user [%s@%s] is entered\n",
00248         desktop->user_name,
00249         desktop->host_name);
00250     printf("\n");
00251 
00252     printf("  The additional info of IM client are\n");
00253 
00254     for (i = 0; i < num_args; i++, args++) {
00255         switch (args->id) {
00256             case UI_USER_NAME:
00257                 if (args->value) {
00258                     printf("       UI_USER_NAME=%s\n", args->value);
00259                 }
00260                 break;
00261             case UI_HOST_NAME:
00262                 if (args->value) {
00263                     printf("       UI_HOST_NAME=%s\n", args->value);
00264                 }
00265                 break;
00266             case UI_DISPLAY_ID:
00267                 if (args->value) {
00268                     printf("       UI_DISPLAY_ID=%s\n", args->value);
00269                 }
00270                 break;
00271             case UI_PROTOCOL_TYPE:
00272                 if (args->value) {
00273                     printf("       UI_PROTOCOL_TYPE=%s\n", args->value);
00274                 }
00275                 break;
00276             case UI_CLIENT_TYPE:
00277                 if (args->value) {
00278                     printf("       UI_CLIENT_TYPE=%s\n", args->value);
00279                 }
00280                 break;
00281             case UI_XSERVER_VENDOR:
00282                 if (args->value) {
00283                     printf("       UI_XSERVER_VENDOR=%s\n", args->value);
00284                 }
00285                 break;
00286             case UI_OS_NAME:
00287                 if (args->value) {
00288                     printf("       UI_OS_NAME=%s\n", args->value);
00289                 }
00290                 break;
00291             case UI_OS_ARCH:
00292                 if (args->value) {
00293                     printf("       UI_OS_ARCH=%s\n", args->value);
00294                 }
00295                 break;
00296             case UI_OS_VERSION:
00297                 if (args->value) {
00298                     printf("       UI_OS_VERSION=%s\n", args->value);
00299                 }
00300                 break;
00301             }
00302     }
00303     
00304     return True;
00305 }
00306 
00307 Bool
00308 if_template_CloseDesktop(
00309     iml_desktop_t * desktop
00310 )
00311 {
00312     printf("if_template_CloseDesktop()\n");
00313     printf("  This method is invoked when the user exits from\n");
00314     printf("  the desktop, which means there is no IM client\n");
00315     printf("  for the user.\n");
00316     
00317     printf("\n");
00318     printf("  user [%s@%s] exited\n",
00319         desktop->user_name,
00320         desktop->host_name);
00321     printf("\n");
00322     return True;
00323 }
00324 
00325 Bool
00326 if_template_CreateSC(
00327     iml_session_t *s,
00328     IMArgList args,
00329     int num_args
00330 )
00331 {
00332     int i;
00333     iml_desktop_t *desktop = s->desktop;
00334 
00335     printf("if_template_CreateSC()\n");
00336     printf("  This method is invoked when a session is created\n");
00337     
00338     printf("\n");
00339     printf("  Creating a session for user [%s@%s]\n",
00340         desktop->user_name,
00341         desktop->host_name);
00342     printf("\n");
00343 
00344     printf("  The additional info of IM client are\n");
00345 
00346     for (i = 0; i < num_args; i++, args++) {
00347         switch (args->id) {
00348             case UI_USER_NAME:
00349                 if (args->value) {
00350                     printf("       UI_USER_NAME=%s\n", args->value);
00351                 }
00352                 break;
00353             case UI_HOST_NAME:
00354                 if (args->value) {
00355                     printf("       UI_HOST_NAME=%s\n", args->value);
00356                 }
00357                 break;
00358             case UI_DISPLAY_ID:
00359                 if (args->value) {
00360                     printf("       UI_DISPLAY_ID=%s\n", args->value);
00361                 }
00362                 break;
00363             case UI_PROTOCOL_TYPE:
00364                 if (args->value) {
00365                     printf("       UI_PROTOCOL_TYPE=%s\n", args->value);
00366                 }
00367                 break;
00368             case UI_CLIENT_TYPE:
00369                 if (args->value) {
00370                     printf("       UI_CLIENT_TYPE=%s\n", args->value);
00371                 }
00372                 break;
00373             case UI_XSERVER_VENDOR:
00374                 if (args->value) {
00375                     printf("       UI_XSERVER_VENDOR=%s\n", args->value);
00376                 }
00377                 break;
00378             case UI_OS_NAME:
00379                 if (args->value) {
00380                     printf("       UI_OS_NAME=%s\n", args->value);
00381                 }
00382                 break;
00383             case UI_OS_ARCH:
00384                 if (args->value) {
00385                     printf("       UI_OS_ARCH=%s\n", args->value);
00386                 }
00387                 break;
00388             case UI_OS_VERSION:
00389                 if (args->value) {
00390                     printf("       UI_OS_VERSION=%s\n", args->value);
00391                 }
00392                 break;
00393             }
00394     }
00395     
00396     return True;
00397 }
00398 
00399 Bool
00400 if_template_DestroySC(
00401     iml_session_t * s
00402 )
00403 {
00404     printf("if_template_DestroySC(s=0x%x)\n", s);
00405     printf("  This method is invoked when the session is\n");
00406     printf("  being destroyed.\n");
00407     
00408     printf("\n");
00409     printf("  Destroying the session %x of user [%s@%s]\n",
00410         s,
00411         s->desktop->user_name,
00412         s->desktop->host_name);
00413     printf("\n");
00414     
00415     return True;
00416 }
00417 
00418 Bool
00419 if_template_GetSCValues(
00420     iml_session_t * s,
00421     IMArgList args,
00422     int num_args
00423 )
00424 {
00425     int i;
00426     IMArg *p = args;
00427 
00428     printf("if_template_GetSCValues(s=0x%x)\n", s);
00429     printf("  This method is invoked when the Language Engine\n");
00430     printf("  wants to set SC attributes of IM Client.\n\n");
00431     
00432     for (i = 0; i < num_args; i++, p++) {
00433         switch (p->id) {
00434             default:
00435                 break;
00436             }
00437     }
00438     return True;
00439 }
00440 
00441 Bool
00442 if_template_SetSCValues(
00443     iml_session_t * s,
00444     IMArgList args,
00445     int num_args
00446 )
00447 {
00448     int i;
00449     IMArg *p = args;
00450     
00451     printf("if_template_SetSCValues(s=0x%x)\n", s);
00452     printf("  This method is invoked when the IM client\n");
00453     printf("  wants to set SC attributes.\n\n");
00454     
00455     for (i = 0; i < num_args; i++, p++) {
00456         switch (p->id) {
00457             case SC_TRIGGER_ON_NOTIFY:
00458                 printf("    SC_TRIGGER_ON_NOTIFY: received\n");
00459                 break;
00460             case SC_TRIGGER_OFF_NOTIFY:
00461                 printf("    SC_TRIGGER_OFF_NOTIFY: received\n");
00462                 break;
00463             case SC_REALIZE:
00464               if(s->desktop->session_count == 1){
00465                      printf("      SC_REALIZE: just after OpenDesktop\n");
00466               } else {
00467                      printf("      SC_REALIZE: received\n");
00468               }
00469                 break;
00470             default:
00471                 break;
00472             }
00473     }
00474     printf("\n");
00475     return True;
00476 }
00477 
00478 IMText *
00479 if_template_ResetSC(
00480     iml_session_t * s
00481 )
00482 {
00483     printf("if_template_ResetSC(s=0x%x)\n", s);
00484     printf("  This method is invoked when the IM client\n");
00485     printf("  wants to reset the IC.\n\n");
00486     
00487     return (IMText *) NULL;
00488 }
00489 
00490 void
00491 if_template_SetSCFocus(
00492     iml_session_t * s
00493 )
00494 {
00495     printf("if_template_SetSCFocus(s=0x%x)\n", s);
00496     printf("  This method is invoked when the IM client\n");
00497     printf("  gets the input focus.\n\n");
00498 }
00499 
00500 void
00501 if_template_UnsetSCFocus(
00502     iml_session_t * s
00503 )
00504 {
00505     printf("if_template_UnsetSCFocus(s=0x%x)\n", s);
00506     printf("  This method is invoked when the IM client\n");
00507     printf("  loses the input focus.\n\n");
00508 }
00509 
00510 void
00511 if_template_SendEvent(
00512     iml_session_t * s,
00513     IMInputEvent * ev
00514 )
00515 {
00516     printf("if_template_SendEvent(s=0x%x,ev=%x)\n", s, ev);
00517     printf("  This method is invoked when any event occurs\n");
00518     printf("  on the IM client.\n\n");
00519     
00520     if (ev->type == IM_EventKeyList) {
00521         IMKeyListEvent *keylistevent = (IMKeyListEvent *) ev;
00522         IMKeyEventStruct *key = (IMKeyEventStruct *) keylistevent->keylist;
00523         printf("     received keyevent keycode=0x%x,keychar=0x%x,state=%x\n",
00524             key->keyCode,
00525             key->keyChar,
00526             key->modifier);
00527     }
00528 }