Back to index

im-sdk  12.3.91
trigger.c
Go to the documentation of this file.
00001 /*
00002   trigger.c
00003 */
00004 
00005 #include "iiimcfint.h"
00006 
00007 IIIMF_status
00008 iiimcf_receive_trigger_notify(
00009     IIIMCF_context_rec *pc,
00010     int flag
00011 )
00012 {
00013     IIIMCF_event event;
00014     IIIMF_status st;
00015 
00016     if (flag && !IIIMCF_IS_ENABLED(pc, IIIMCF_CONTEXT_CONVERSION_MODE)) {
00017        IIIMCF_SET_STATE(pc, IIIMCF_CONTEXT_CONVERSION_MODE);
00018        IIIMCF_SET_STATE_CHANGE(pc, IIIMCF_STATE_CONVERSION_MODE_CHANGED);
00019 
00020        st = iiimcf_create_trigger_notify_event(1, &event);
00021        if (st != IIIMF_STATUS_SUCCESS) return st;
00022        return iiimcf_store_event(pc, (IIIMCF_event_rec*) event);
00023     } else if (!flag && IIIMCF_IS_ENABLED(pc, IIIMCF_CONTEXT_CONVERSION_MODE)) {
00024        IIIMCF_RESET_STATE(pc, IIIMCF_CONTEXT_CONVERSION_MODE);
00025        IIIMCF_SET_STATE_CHANGE(pc, IIIMCF_STATE_CONVERSION_MODE_CHANGED);
00026 
00027        st = iiimcf_create_trigger_notify_event(0, &event);
00028        if (st != IIIMF_STATUS_SUCCESS) return st;
00029        return iiimcf_store_event(pc, (IIIMCF_event_rec*) event);
00030     }
00031 
00032     return IIIMF_STATUS_SUCCESS;
00033 }
00034 
00035 IIIMF_status
00036 iiimcf_receive_hotkey_notify(
00037     IIIMCF_context_rec *pc
00038 )
00039 {
00040     IIIMCF_event event;
00041     IIIMF_status st;
00042 
00043     st = iiimcf_create_hotkey_notify_event(&event);
00044     if (st != IIIMF_STATUS_SUCCESS) return st;
00045     return iiimcf_store_event(pc, (IIIMCF_event_rec*) event);
00046 }
00047 
00048 IIIMF_status
00049 iiimcf_forward_trigger_notify(
00050     IIIMCF_context_rec *pc,
00051     int flag
00052 )
00053 {
00054     IIIMF_status st;
00055     IIIMCF_handle_rec *ph = pc->ph;
00056     IIIMP_data_s *pds = ph->data_s;
00057     IIIMP_message *pmes;
00058 
00059     pmes = iiimp_trigger_notify_new(pds, ph->im_id, pc->ic_id, flag ? 0 : 1);
00060     if (!pmes) {
00061        return IIIMF_STATUS_MALLOC;
00062     }
00063 
00064     st = iiimcf_receive_trigger_notify(pc, flag);
00065     if (st != IIIMF_STATUS_SUCCESS) return st;
00066 
00067     st = iiimcf_request_message(ph, pmes, pc, IM_TRIGGER_NOTIFY_REPLY, NULL);
00068 
00069     return st;
00070 }
00071 
00072 IIIMF_status
00073 iiimcf_forward_hotkey_notify(
00074     IIIMCF_context_rec *pc,
00075     int hotkey_id,
00076     int ikev
00077 )
00078 {
00079     IIIMF_status st;
00080     IIIMCF_handle_rec *ph = pc->ph;
00081     IIIMP_data_s *pds = ph->data_s;
00082     IIIMP_message *pmes;
00083 
00084     pmes = iiimp_hotkey_notify_new(pds, ph->im_id, pc->ic_id, hotkey_id, ikev);
00085     if (!pmes) {
00086        return IIIMF_STATUS_MALLOC;
00087     }
00088 
00089     st = iiimcf_receive_hotkey_notify(pc);
00090     if (st != IIIMF_STATUS_SUCCESS) return st;
00091 
00092     st = iiimcf_request_message(ph, pmes, pc, IM_HOTKEY_NOTIFY_REPLY, NULL);
00093 
00094     return st;
00095 }
00096 
00097 IIIMF_status
00098 iiimcf_process_trigger_keyevent(
00099     IIIMCF_context_rec *pc,
00100     IIIMCF_keyevent *pkev
00101 )
00102 {
00103     int i, n;
00104     IIIMCF_keyevent *pkevl;
00105     IIIMF_status st = IIIMF_STATUS_SUCCESS;
00106 
00107     if (IIIMCF_IS_ENABLED(pc, IIIMCF_CONTEXT_CONVERSION_MODE)) {
00108        n = pc->ph->num_off_keys;
00109        pkevl = pc->ph->poff_keys;
00110        for (i = 0; i < n; i++, pkevl++) {
00111            if (IIIMCF_IS_KEYEVENT_EQUAL(*pkev, *pkevl)) {
00112               st = iiimcf_forward_trigger_notify(pc, 0);
00113               return st;
00114            }
00115        }
00116     } else {
00117        n = pc->ph->num_on_keys;
00118        pkevl = pc->ph->pon_keys;
00119        for (i = 0; i < n; i++, pkevl++) {
00120            if (IIIMCF_IS_KEYEVENT_EQUAL(*pkev, *pkevl)) {
00121               st = iiimcf_forward_trigger_notify(pc, 1);
00122               return st;
00123            }
00124        }
00125     }
00126     return IIIMF_STATUS_NOT_TRIGGER_KEY;
00127 }
00128 
00129 IIIMF_status
00130 iiimcf_process_hotkey_keyevent(
00131     IIIMCF_context_rec *pc,
00132     IIIMCF_keyevent *pkev
00133 )
00134 {
00135     int found, i, j, k, m, n, hotkey_id, sflag, aflag, ikev;
00136     IIIMCF_keyevent *pkevl;
00137     IIIMF_status st = IIIMF_STATUS_SUCCESS;
00138 
00139     /* some older version of IIIMSF sends protocol version 3,
00140      * but not supported hotkey.
00141      */
00142     if (!pc->ph->phk_profile || pc->ph->curr_profile_id == -1)
00143       return iiimcf_process_trigger_keyevent(pc, pkev);
00144 
00145     k = 0;
00146     found = 0;
00147     while (k < pc->ph->num_of_hkprofiles) {
00148       if (pc->ph->phk_profile[k].profile_id == pc->ph->curr_profile_id) {
00149        found = 1;
00150        break;
00151       }
00152       k++;
00153     }
00154     if (found == 0)
00155       /* no valid hotkey profile is found, so use trigger key event */
00156       return iiimcf_process_trigger_keyevent(pc, pkev);
00157 
00158     m = pc->ph->phk_profile[k].num_hotkeys;
00159     for (i = 0; i < m; i++) {
00160        pkevl = pc->ph->phk_profile[k].phot_keys[i].keys;
00161        n = pc->ph->phk_profile[k].phot_keys[i].nkeys;
00162        for (j = 0; j < n; j++, pkevl++) {
00163            if (IIIMCF_IS_KEYEVENT_EQUAL(*pkev, *pkevl)) {
00164               hotkey_id = pc->ph->phk_profile[k].phot_keys[i].hotkey_id;
00165               sflag = pc->ph->phk_profile[k].phot_keys[i].state_flag;
00166               aflag = pc->ph->phk_profile[k].phot_keys[i].action_flag;
00167               ikev = j;
00168   
00169               if (IIIMCF_IS_ENABLED(pc, IIIMCF_CONTEXT_CONVERSION_MODE)) { /* Event Forwarding ON */
00170                   if (!sflag && !aflag) { 
00171                      st = iiimcf_forward_trigger_notify(pc, 0);
00172                      return st;
00173                   } else if (!sflag && aflag) {
00174                      IIIMCF_SET_STATE(pc, IIIMCF_CONTEXT_CONVERSION_MODE);
00175                      IIIMCF_SET_STATE_CHANGE(pc, IIIMCF_STATE_CONVERSION_MODE_CHANGED);
00176                      st = iiimcf_forward_hotkey_notify(pc, hotkey_id, ikev);
00177                      return st;
00178                   } else {
00179                      return IIIMF_STATUS_NOT_TRIGGER_KEY;
00180                   }
00181               } else { /* Event Forwarding OFF */
00182                   if (!sflag) { /* if HOTKEY is valid */
00183                      if (aflag) { /* Action flag is Forward ON */
00184                          IIIMCF_SET_STATE(pc, IIIMCF_CONTEXT_CONVERSION_MODE);
00185                          IIIMCF_SET_STATE_CHANGE(pc, IIIMCF_STATE_CONVERSION_MODE_CHANGED);
00186                          st = iiimcf_forward_hotkey_notify(pc, hotkey_id, ikev);
00187                          return st;
00188                      }
00189                   }
00190               } 
00191            }
00192        }
00193     }
00194     /* If it is not a HOTKEY */
00195     st = iiimcf_process_trigger_keyevent(pc, pkev);
00196     return st;
00197 }
00198 
00199 /********************************************************************************
00200                                  APIs
00201 ********************************************************************************/
00202 
00203 IIIMF_status
00204 iiimcf_create_trigger_notify_event(
00205     int flag,
00206     IIIMCF_event *pevent
00207 )
00208 {
00209     IIIMCF_event_rec *pe;
00210 
00211     pe = iiimcf_make_event(IIIMCF_EVENT_TYPE_TRIGGER_NOTIFY);
00212     if (!pe) return IIIMF_STATUS_MALLOC;
00213 
00214     if (flag)
00215        pe->v.number = 1;
00216     else
00217        pe->v.number = 0;
00218 
00219     *pevent = pe;
00220 
00221     return IIIMF_STATUS_SUCCESS;
00222 }
00223 
00224 IIIMF_status
00225 iiimcf_create_hotkey_notify_event(
00226     IIIMCF_event *pevent
00227 )
00228 {
00229     IIIMCF_event_rec *pe;
00230 
00231     pe = iiimcf_make_event(IIIMCF_EVENT_TYPE_HOTKEY_NOTIFY);
00232     if (!pe) return IIIMF_STATUS_MALLOC;
00233 
00234     *pevent = pe;
00235 
00236     return IIIMF_STATUS_SUCCESS;
00237 }
00238 
00239 IIIMF_status
00240 iiimcf_get_trigger_notify_flag(
00241     IIIMCF_event event,
00242     int *pflag
00243 )
00244 {
00245     IIIMCF_event_rec *pe = (IIIMCF_event_rec*) event;
00246 
00247     if (pe->type != IIIMCF_EVENT_TYPE_TRIGGER_NOTIFY)
00248        return IIIMF_STATUS_FAIL;
00249 
00250     *pflag = pe->v.number;
00251     return IIIMF_STATUS_SUCCESS;
00252 }
00253 
00254 IIIMF_status
00255 iiimcf_get_current_conversion_mode(
00256     IIIMCF_context context,
00257     int *pflag
00258 )
00259 {
00260     IIIMCF_context_rec *pc = (IIIMCF_context_rec*) context;
00261 
00262     if (IIIMCF_IS_ENABLED(pc, IIIMCF_CONTEXT_CONVERSION_MODE)) {
00263        *pflag = 1;
00264     } else {
00265        *pflag = 0;
00266     }
00267 
00268     return IIIMF_STATUS_SUCCESS;
00269 }
00270 
00271 /*
00272  * get the hotkey list of current hotkey profile.
00273  */
00274 IIIMF_status
00275 iiimcf_get_hotkeys(
00276    IIIMCF_context context,
00277    int *pnum_hotkey,
00278    const IIIMCF_hotkey **photkey
00279 )
00280 {
00281   IIIMCF_handle_rec *hc = (IIIMCF_context_rec *)context->ph;
00282 
00283   if (pnum_hotkey && hc->num_of_hkprofiles)
00284     *pnum_hotkey = hc->phk_profile[hc->curr_profile_id].num_hotkeys;
00285   if (photkey && hc->num_of_hkprofiles)
00286     *photkey = hc->phk_profile[hc->curr_profile_id].phot_keys;
00287 
00288   return IIIMF_STATUS_SUCCESS;
00289 }
00290 
00291 /* Local Variables: */
00292 /* c-file-style: "iiim-project" */
00293 /* End: */