root/core/levent.c

/* [<][>][^][v][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. levent_index_for_name
  2. levent_index_for_id
  3. levent_count
  4. levent_id_for_name
  5. levent_name_for_id
  6. levent_post_to_ui_by_name
  7. levent_set_record
  8. levent_set_play

   1 #include "stdlib.h"
   2 #include "stddef.h"
   3 #include "string.h"
   4 #include "levent.h"
   5 
   6 /* function dealing with "logical events"*/
   7 unsigned levent_index_for_name(const char *name)
   8 {
   9   unsigned i;
  10   // TODO could check for id=-1 or id=0, both show up at end of table ?
  11   for (i=0; levent_table[i].name; i++) {
  12     // case insensitive might be better
  13     if (strcmp(levent_table[i].name,name) == 0) {
  14         return i;
  15     }
  16   }
  17   return LEVENT_INVALID_INDEX;
  18 }
  19 
  20 unsigned levent_index_for_id(unsigned id)
  21 {
  22   unsigned i;
  23   // TODO could check for id=-1 or id=0, both show up at end of table ?
  24   for (i=0; levent_table[i].name; i++) {
  25     // case insensitive might be better
  26     if (id == levent_table[i].id) {
  27         return i;
  28     }
  29   }
  30   return LEVENT_INVALID_INDEX;
  31 }
  32 
  33 unsigned levent_count(void)
  34 {
  35   static unsigned num_levents = 0;
  36   if(!num_levents) {
  37     levent_def *ev;
  38     // TODO could check for id=-1 or id=0, both show up at end of table ?
  39     for (ev = levent_table; ev->name; ev++) {
  40       num_levents++;
  41     }
  42   }
  43   return num_levents;
  44 }
  45 
  46 unsigned levent_id_for_name(const char *name)
  47 {
  48   unsigned i = levent_index_for_name(name);
  49   if (i!=LEVENT_INVALID_INDEX)
  50     return levent_table[i].id;
  51   else
  52     return 0; // or -1 ? both appear at the end of the event list
  53 }
  54 
  55 const char * levent_name_for_id(unsigned id)
  56 {
  57   unsigned i = levent_index_for_id(id);
  58   if (i!=LEVENT_INVALID_INDEX)
  59     return levent_table[i].name;
  60   else
  61     return NULL;
  62 }
  63 
  64 // note, slow linear search every time
  65 int levent_post_to_ui_by_name(const char *name)
  66 {
  67         unsigned id=levent_id_for_name(name);
  68         if(id) {
  69                 PostLogicalEventToUI(id,0);
  70                 return 1;
  71         }
  72         return 0;
  73 }
  74 
  75 void levent_set_record(void) {
  76         levent_post_to_ui_by_name("PressRecButton");
  77         levent_post_to_ui_by_name("UnpressRecButton");
  78 }
  79 
  80 void levent_set_play(void) {
  81         levent_post_to_ui_by_name("PressPBButton");
  82         levent_post_to_ui_by_name("UnpressPBButton");
  83 }

/* [<][>][^][v][top][bottom][index][help] */