libalarm.h

Go to the documentation of this file.
00001 
00101 #ifndef LIBALARM_H_
00102 #define LIBALARM_H_
00103 
00104 #include <stdint.h>
00105 #include <stdarg.h>
00106 #include <time.h>
00107 
00108 #ifdef __cplusplus
00109 extern "C" {
00110 #elif 0
00111 } /* fool JED indentation ... */
00112 #endif
00113 
00114 #pragma GCC visibility push(default)
00115 
00118 typedef long cookie_t;
00119 
00120 /* ------------------------------------------------------------------------- *
00121  * alarm_attr_t
00122  * ------------------------------------------------------------------------- */
00123 
00154 typedef struct alarm_attr_t
00155 {
00157   char *attr_name;
00158 
00160   int   attr_type;
00161 
00163   union
00164   {
00165     char  *sval;
00166     time_t tval;
00167     int    ival;
00168   } attr_data;
00169 } alarm_attr_t;
00170 
00172 typedef enum alarmattrtype
00173 {
00174   ALARM_ATTR_NULL,
00175   ALARM_ATTR_INT,
00176   ALARM_ATTR_TIME,
00177   ALARM_ATTR_STRING,
00178 } alarmattrtype;
00179 
00183 
00192 void          alarm_attr_ctor      (alarm_attr_t *self);
00193 
00202 void          alarm_attr_dtor      (alarm_attr_t *self);
00203 
00212 void          alarm_attr_set_null  (alarm_attr_t *self);
00213 
00224 void          alarm_attr_set_string(alarm_attr_t *self, const char *val);
00225 
00236 void          alarm_attr_set_int   (alarm_attr_t *self, int val);
00237 
00248 void          alarm_attr_set_time  (alarm_attr_t *self, time_t val);
00249 
00260 const char   *alarm_attr_get_string(alarm_attr_t *self);
00261 
00273 int           alarm_attr_get_int   (alarm_attr_t *self);
00274 
00286 time_t        alarm_attr_get_time  (alarm_attr_t *self);
00287 
00298 alarm_attr_t *alarm_attr_create    (const char *name);
00299 
00311 void          alarm_attr_delete    (alarm_attr_t *self);
00312 
00321 void          alarm_attr_delete_cb (void *self);
00322 
00370 typedef enum alarmactionflags
00371 {
00372   // 0                   1
00373   // 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5
00374   // x x x x x x x x x x x x x x x -
00375 
00376   // ---- WHAT ----
00377 
00379   ALARM_ACTION_TYPE_NOP       = 0,
00380 
00382   ALARM_ACTION_TYPE_SNOOZE    = 1 << 0,
00383 
00385   ALARM_ACTION_TYPE_DBUS      = 1 << 1,
00386 
00388   ALARM_ACTION_TYPE_EXEC      = 1 << 2,
00389 
00391   ALARM_ACTION_TYPE_DESKTOP   = 1 << 3,
00392 
00394   ALARM_ACTION_TYPE_ACTDEAD   = 1 << 8,
00395 
00400   ALARM_ACTION_TYPE_DISABLE   = 1 << 10,
00401 
00402   // ---- WHEN ----
00403 
00408   ALARM_ACTION_WHEN_QUEUED    = 1 << 4,
00409 
00418   ALARM_ACTION_WHEN_DELAYED   = 1 << 11,
00419 
00423   ALARM_ACTION_WHEN_TRIGGERED = 1 << 5,
00424 
00435   ALARM_ACTION_WHEN_DISABLED  = 1 << 9,
00436 
00439   ALARM_ACTION_WHEN_RESPONDED = 1 << 6,
00440 
00443   ALARM_ACTION_WHEN_DELETED   = 1 << 7,
00444 
00445   // ---- DBUS ----
00446 
00449   ALARM_ACTION_DBUS_USE_ACTIVATION = 1 << 12,
00450 
00453   ALARM_ACTION_DBUS_USE_SYSTEMBUS  = 1 << 13,
00454 
00457   ALARM_ACTION_DBUS_ADD_COOKIE     = 1 << 14,
00458 
00459   // ---- MASKS ----
00460 
00461   ALARM_ACTION_TYPE_MASK = (ALARM_ACTION_TYPE_SNOOZE |
00462                             ALARM_ACTION_TYPE_DISABLE|
00463                             ALARM_ACTION_TYPE_DBUS   |
00464                             ALARM_ACTION_TYPE_EXEC   |
00465                             ALARM_ACTION_TYPE_DESKTOP|
00466                             ALARM_ACTION_TYPE_ACTDEAD),
00467 
00468   ALARM_ACTION_WHEN_MASK = (ALARM_ACTION_WHEN_QUEUED    |
00469                             ALARM_ACTION_WHEN_TRIGGERED |
00470                             ALARM_ACTION_WHEN_DISABLED  |
00471                             ALARM_ACTION_WHEN_RESPONDED |
00472                             ALARM_ACTION_WHEN_DELETED),
00473 
00474 } alarmactionflags;
00475 
00518 typedef struct alarm_action_t
00519 {
00521   unsigned  flags;
00522 
00535   char     *label;
00536 
00543   char     *exec_command;
00544 
00551   char     *dbus_interface;
00552 
00560   char     *dbus_service;
00561 
00568   char     *dbus_path;
00569 
00576   char     *dbus_name;
00577 
00590   char     *dbus_args;
00591 
00592 } alarm_action_t;
00593 
00594 /* ------------------------------------------------------------------------- *
00595  * alarm_action_t
00596  * ------------------------------------------------------------------------- */
00597 
00601 
00603 void            alarm_action_ctor     (alarm_action_t *self);
00605 void            alarm_action_dtor     (alarm_action_t *self);
00607 alarm_action_t *alarm_action_create   (void);
00609 void            alarm_action_delete   (alarm_action_t *self);
00611 void            alarm_action_delete_cb(void *self);
00612 
00622 int alarm_action_is_button(const alarm_action_t *self);
00623 
00636 int             alarm_action_set_dbus_args       (alarm_action_t *self, int type, ...);
00637 
00642 void            alarm_action_del_dbus_args       (alarm_action_t *self);
00643 
00654 int             alarm_action_set_dbus_args_valist(alarm_action_t *self, int type, va_list va);
00655 
00661 const char     *alarm_action_get_label           (const alarm_action_t *self);
00662 
00668 const char     *alarm_action_get_exec_command    (const alarm_action_t *self);
00669 
00675 const char     *alarm_action_get_dbus_interface  (const alarm_action_t *self);
00676 
00682 const char     *alarm_action_get_dbus_service    (const alarm_action_t *self);
00683 
00689 const char     *alarm_action_get_dbus_path       (const alarm_action_t *self);
00690 
00696 const char     *alarm_action_get_dbus_name       (const alarm_action_t *self);
00697 
00703 void            alarm_action_set_label           (alarm_action_t *self, const char *label);
00704 
00710 void            alarm_action_set_exec_command    (alarm_action_t *self, const char *exec_command);
00711 
00717 void            alarm_action_set_dbus_interface  (alarm_action_t *self, const char *dbus_interface);
00718 
00724 void            alarm_action_set_dbus_service    (alarm_action_t *self, const char *dbus_service);
00725 
00731 void            alarm_action_set_dbus_path       (alarm_action_t *self, const char *dbus_path);
00732 
00738 void            alarm_action_set_dbus_name       (alarm_action_t *self, const char *dbus_name);
00739 
00784 typedef struct alarm_recur_t
00785 {
00786   // NOTE: bit indexing is struct tm compatible
00787 
00796   uint64_t mask_min;    // 0 .. 59
00797 
00804   uint32_t mask_hour;   // 0 .. 23
00805 
00812   uint32_t mask_mday;   // 1 .. 31   1=first
00813 
00820   uint32_t mask_wday;   // 0 .. 6    0=sunday
00827   uint32_t mask_mon;    // 0 .. 11   0=january
00828 
00837   uint32_t special;
00838 
00839 } alarm_recur_t;
00840 
00847 typedef enum alarmrecurflags
00848 {
00850   ALARM_RECUR_MIN_DONTCARE  = 0,
00852   ALARM_RECUR_MIN_ALL       = (1ull << 60) - 1,
00853 
00855   ALARM_RECUR_HOUR_DONTCARE = 0,
00857   ALARM_RECUR_HOUR_ALL      = (1u << 24) - 1,
00858 
00860   ALARM_RECUR_MDAY_DONTCARE = 0,
00862   ALARM_RECUR_MDAY_ALL      = ~1u,
00865   ALARM_RECUR_MDAY_EOM      =  1u,
00866 
00868   ALARM_RECUR_WDAY_DONTCARE = 0,
00870   ALARM_RECUR_WDAY_ALL      = (1u << 7) - 1,
00872   ALARM_RECUR_WDAY_SUN      = (1u << 0),
00874   ALARM_RECUR_WDAY_MON      = (1u << 1),
00876   ALARM_RECUR_WDAY_TUE      = (1u << 2),
00878   ALARM_RECUR_WDAY_WED      = (1u << 3),
00880   ALARM_RECUR_WDAY_THU      = (1u << 4),
00882   ALARM_RECUR_WDAY_FRI      = (1u << 5),
00884   ALARM_RECUR_WDAY_SAT      = (1u << 6),
00886   ALARM_RECUR_WDAY_MONFRI   = ALARM_RECUR_WDAY_SAT - ALARM_RECUR_WDAY_MON,
00888   ALARM_RECUR_WDAY_SATSUN   = ALARM_RECUR_WDAY_SAT | ALARM_RECUR_WDAY_SUN,
00889 
00891   ALARM_RECUR_MON_DONTCARE = 0,
00893   ALARM_RECUR_MON_ALL       = (1u << 12) - 1,
00895   ALARM_RECUR_MON_JAN       = (1u <<  0),
00897   ALARM_RECUR_MON_FEB       = (1u <<  1),
00899   ALARM_RECUR_MON_MAR       = (1u <<  2),
00901   ALARM_RECUR_MON_APR       = (1u <<  3),
00903   ALARM_RECUR_MON_MAY       = (1u <<  4),
00905   ALARM_RECUR_MON_JUN       = (1u <<  5),
00907   ALARM_RECUR_MON_JUL       = (1u <<  6),
00909   ALARM_RECUR_MON_AUG       = (1u <<  7),
00911   ALARM_RECUR_MON_SEP       = (1u <<  8),
00913   ALARM_RECUR_MON_OCT       = (1u <<  9),
00915   ALARM_RECUR_MON_NOW       = (1u << 10),
00917   ALARM_RECUR_MON_DEC       = (1u << 11),
00918 
00920   ALARM_RECUR_SPECIAL_NONE      = 0,
00922   ALARM_RECUR_SPECIAL_BIWEEKLY  = 1,
00924   ALARM_RECUR_SPECIAL_MONTHLY   = 2,
00926   ALARM_RECUR_SPECIAL_YEARLY    = 3,
00927 } alarmrecurflags;
00928 
00932 
00937 void           alarm_recur_ctor           (alarm_recur_t *self);
00938 
00943 void           alarm_recur_dtor           (alarm_recur_t *self);
00944 
00949 alarm_recur_t *alarm_recur_create         (void);
00950 
00955 void           alarm_recur_delete         (alarm_recur_t *self);
00956 
00962 void           alarm_recur_init_from_tm   (alarm_recur_t *self, const struct tm *tm);
00963 
00968 void           alarm_recur_delete_cb      (void *self);
00969 
00978 time_t         alarm_recur_align          (const alarm_recur_t *self, struct tm *trg, const char *tz);
00979 
00988 time_t         alarm_recur_next           (const alarm_recur_t *self, struct tm *trg, const char *tz);
00989 
00998 typedef enum alarmeventflags
00999 {
01000   // 0                   1
01001   // 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5
01002   // - - - x x x x x x x x x x - - -
01003 
01006   ALARM_EVENT_BOOT             = 1 << 3,
01007 
01010   ALARM_EVENT_ACTDEAD          = 1 << 4,
01011 
01015   ALARM_EVENT_SHOW_ICON        = 1 << 5,
01016 
01021   ALARM_EVENT_CONNECTED        = 1 << 7,
01022 
01029   ALARM_EVENT_RUN_DELAYED      = 1 << 6,
01030 
01037   ALARM_EVENT_POSTPONE_DELAYED = 1 << 9,
01038 
01046   ALARM_EVENT_DISABLE_DELAYED  = 1 << 12,
01047 
01053   ALARM_EVENT_BACK_RESCHEDULE  = 1 << 10,
01054 
01055 // QUARANTINE   /** If the system time is moved forwards, the alarm should be
01056 // QUARANTINE    *  rescheduled.
01057 // QUARANTINE    **/
01058 // QUARANTINE   ALARM_EVENT_FORW_RESCHEDULE  = 1 <<  8,
01059 
01064   ALARM_EVENT_DISABLED         = 1 << 11,
01065 
01069   ALARM_EVENT_CLIENT_BITS      = 16,
01070 
01073   ALARM_EVENT_CLIENT_MASK      = (1 << ALARM_EVENT_CLIENT_BITS) - 1,
01074 
01075 } alarmeventflags;
01076 
01078 #define ALARM_RECURRING_SECONDS(n) (n)
01079 
01080 #define ALARM_RECURRING_MINUTES(n) ((n)*60)
01081 
01082 #define ALARM_RECURRING_HOURS(n)   ((n)*60*60)
01083 
01169 typedef struct alarm_event_t
01170 {
01179   cookie_t       cookie;
01180 
01185   time_t         trigger;
01186 
01193   char          *title;
01194 
01201   char          *message;
01202 
01209   char          *sound;
01210 
01217   char          *icon;
01218 
01220   unsigned       flags;
01221 
01228   char          *alarm_appid;
01229 
01236   time_t         alarm_time;
01237 
01244   struct tm      alarm_tm;
01245 
01260   char          *alarm_tz;
01261 
01269   time_t         snooze_secs;
01270 
01275   time_t         snooze_total;
01276 
01283   size_t         action_cnt;
01284 
01291   alarm_action_t *action_tab;
01292 
01294   int            response;
01295 
01301   int             recur_count;
01302 
01305   time_t          recur_secs;
01306 
01311   size_t          recurrence_cnt;
01319   alarm_recur_t  *recurrence_tab;
01320 
01325   size_t          attr_cnt;
01341   alarm_attr_t  **attr_tab;
01342 
01343   /* - - - - - - - - - - - - - - - - - - - *
01344    * changes to this structure -> check also:
01345    *
01346    * event.c:
01347    *   alarm_event_ctor()
01348    *   alarm_event_dtor()
01349    *
01350    * codec.c:
01351    *   encode_event()
01352    *   decode_event()
01353    *
01354    * queue.c:
01355    *   queue_save_to_path()
01356    *   queue_load_from_path()
01357    *
01358    * - - - - - - - - - - - - - - - - - - - */
01359 
01360 } alarm_event_t;
01361 
01362 /* ------------------------------------------------------------------------- *
01363  * alarm_event_t
01364  * ------------------------------------------------------------------------- */
01365 
01369 
01378 void alarm_event_delete(alarm_event_t *self);
01379 
01389 alarm_event_t *alarm_event_create(void);
01390 
01397 alarm_event_t *alarm_event_create_ex(size_t actions);
01398 
01403 void alarm_event_delete_cb(void *self);
01404 
01409 void alarm_event_ctor(alarm_event_t *self);
01410 
01415 void alarm_event_dtor(alarm_event_t *self);
01416 
01422 const char     *alarm_event_get_title           (const alarm_event_t *self);
01423 
01429 void            alarm_event_set_title           (alarm_event_t *self, const char *title);
01430 
01436 const char     *alarm_event_get_message           (const alarm_event_t *self);
01437 
01443 void            alarm_event_set_message           (alarm_event_t *self, const char *message);
01444 
01450 const char     *alarm_event_get_sound           (const alarm_event_t *self);
01451 
01457 void            alarm_event_set_sound           (alarm_event_t *self, const char *sound);
01458 
01464 const char     *alarm_event_get_icon           (const alarm_event_t *self);
01465 
01471 void            alarm_event_set_icon           (alarm_event_t *self, const char *icon);
01472 
01478 const char     *alarm_event_get_alarm_appid           (const alarm_event_t *self);
01479 
01485 void            alarm_event_set_alarm_appid           (alarm_event_t *self, const char *alarm_appid);
01486 
01492 const char     *alarm_event_get_alarm_tz           (const alarm_event_t *self);
01493 
01499 void            alarm_event_set_alarm_tz           (alarm_event_t *self, const char *alarm_tz);
01500 
01513 int             alarm_event_is_recurring(const alarm_event_t *self);
01514 
01525 alarm_action_t *alarm_event_add_actions(alarm_event_t *self, size_t count);
01526 
01532 alarm_action_t *alarm_event_get_action(const alarm_event_t *self, int index);
01533 
01539 void alarm_event_del_actions(alarm_event_t *self);
01540 
01553 int alarm_event_set_action_dbus_args(const alarm_event_t *self, int index, int type, ...);
01554 
01564 const char *alarm_event_get_action_dbus_args(const alarm_event_t *self, int index);
01565 
01573 void alarm_event_del_action_dbus_args(const alarm_event_t *self, int index);
01574 
01585 alarm_recur_t *alarm_event_add_recurrences(alarm_event_t *self, size_t count);
01586 
01599 alarm_recur_t *alarm_event_get_recurrence(const alarm_event_t *self, int index);
01600 
01606 void alarm_event_del_recurrences(alarm_event_t *self);
01607 
01619 void alarm_event_set_time(alarm_event_t *self, const struct tm *tm);
01620 
01630 void alarm_event_get_time(const alarm_event_t *self, struct tm *tm);
01631 
01650 int alarm_event_is_sane(const alarm_event_t *self);
01651 
01661 void            alarm_event_del_attrs           (alarm_event_t *self);
01662 
01672 void            alarm_event_rem_attr            (alarm_event_t *self, const char *name);
01673 
01685 alarm_attr_t   *alarm_event_get_attr            (alarm_event_t *self, const char *name);
01686 
01698 int             alarm_event_has_attr            (alarm_event_t *self, const char *name);
01699 
01713 alarm_attr_t   *alarm_event_add_attr            (alarm_event_t *self, const char *name);
01714 
01726 void            alarm_event_set_attr_int        (alarm_event_t *self, const char *name, int val);
01727 
01739 void            alarm_event_set_attr_time       (alarm_event_t *self, const char *name, time_t val);
01740 
01752 void            alarm_event_set_attr_string     (alarm_event_t *self, const char *name, const char *val);
01753 
01767 int             alarm_event_get_attr_int        (alarm_event_t *self, const char *name, int def);
01768 
01782 time_t          alarm_event_get_attr_time       (alarm_event_t *self, const char *name, time_t def);
01783 
01797 const char     *alarm_event_get_attr_string     (alarm_event_t *self, const char *name, const char *def);
01798 
01801 /* ------------------------------------------------------------------------- *
01802  * alarmd functions
01803  * ------------------------------------------------------------------------- */
01804 
01808 
01820 cookie_t alarmd_event_add(const alarm_event_t *event);
01821 
01844 cookie_t alarmd_event_add_with_dbus_params(const alarm_event_t *event,
01845                                            int type, ...);
01846 
01856 int alarmd_event_del(cookie_t cookie);
01857 
01879 cookie_t alarmd_event_update(const alarm_event_t *event);
01880 
01906 cookie_t *alarmd_event_query(const time_t first, const time_t last,
01907                              int32_t flag_mask, int32_t flags,
01908                              const char *appid);
01909 
01921 alarm_event_t *alarmd_event_get(cookie_t cookie);
01922 
01934 int alarmd_set_default_snooze(unsigned int snooze);
01935 
01942 unsigned int alarmd_get_default_snooze(void);
01943 
01945 cookie_t alarmd_event_add_valist(const alarm_event_t *event, int type, va_list va);
01946 
01949 /* ------------------------------------------------------------------------- *
01950  * systemui functions
01951  * ------------------------------------------------------------------------- */
01952 
01957 
01959 int alarmd_ack_dialog(cookie_t cookie, int button);
01960 
01962 int alarmd_ack_queue(cookie_t *cookies, int count);
01963 
01966 /* ------------------------------------------------------------------------- *
01967  * debug functions
01968  * ------------------------------------------------------------------------- */
01969 
01974 
01976 int alarmd_set_debug(unsigned mask_set, unsigned mask_clr,
01977                      unsigned flag_set, unsigned flag_clr);
01978 
01981 #pragma GCC visibility pop
01982 
01983 #ifdef __cplusplus
01984 };
01985 #endif
01986 
01987 #endif /* LIBALARM_H_ */

Generated on Tue Feb 24 16:21:30 2009 for libalarm by  doxygen 1.5.1