src/libalarm.h

Go to the documentation of this file.
00001 
00136 #ifndef LIBALARM_H_
00137 #define LIBALARM_H_
00138 
00139 #include <stdint.h>
00140 #include <stdarg.h>
00141 #include <time.h>
00142 
00143 #ifdef __cplusplus
00144 extern "C" {
00145 #elif 0
00146 } /* fool JED indentation ... */
00147 #endif
00148 
00149 /* Crude preprocessor tricks to make direct access to
00150  * some member variables more visible - used for alarmd
00151  * compilation, hidden from doxygen scanner */
00152 
00153 #ifndef DOXYGEN_SHOULD_SKIP_THIS
00154 # ifdef ALARMD_MANGLE_MEMBERS
00155 #  define ALARMD_CAT2(a,b) a##b
00156 #  define ALARMD_PRIVATE(x) ALARMD_CAT2(x,_private)
00157 # else
00158 #  define ALARMD_PRIVATE(x) x
00159 # endif
00160 #endif
00161 
00162 #pragma GCC visibility push(default)
00163 
00166 typedef long cookie_t;
00167 
00168 /* ------------------------------------------------------------------------- *
00169  * alarm_attr_t
00170  * ------------------------------------------------------------------------- */
00171 
00202 typedef struct alarm_attr_t
00203 {
00205   char *attr_name;
00206 
00208   int   attr_type;
00209 
00211   union
00212   {
00213     char  *sval;
00214     time_t tval;
00215     int    ival;
00216   } attr_data;
00217 } alarm_attr_t;
00218 
00220 typedef enum alarmattrtype
00221 {
00222   ALARM_ATTR_NULL,
00223   ALARM_ATTR_INT,
00224   ALARM_ATTR_TIME,
00225   ALARM_ATTR_STRING,
00226 } alarmattrtype;
00227 
00231 
00240 void          alarm_attr_ctor      (alarm_attr_t *self);
00241 
00250 void          alarm_attr_dtor      (alarm_attr_t *self);
00251 
00260 void          alarm_attr_set_null  (alarm_attr_t *self);
00261 
00272 void          alarm_attr_set_string(alarm_attr_t *self, const char *val);
00273 
00284 void          alarm_attr_set_int   (alarm_attr_t *self, int val);
00285 
00296 void          alarm_attr_set_time  (alarm_attr_t *self, time_t val);
00297 
00308 const char   *alarm_attr_get_string(alarm_attr_t *self);
00309 
00321 int           alarm_attr_get_int   (alarm_attr_t *self);
00322 
00334 time_t        alarm_attr_get_time  (alarm_attr_t *self);
00335 
00346 alarm_attr_t *alarm_attr_create    (const char *name);
00347 
00359 void          alarm_attr_delete    (alarm_attr_t *self);
00360 
00369 void          alarm_attr_delete_cb (void *self);
00370 
00423 typedef enum alarmactionflags
00424 {
00425   // 0                   1                   2                   3
00426   // 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
00427   // x x x x x x x x x x x x x x x x
00428 
00429   // ---- WHAT ----
00430 
00432   ALARM_ACTION_TYPE_NOP       = 0,
00433 
00443   ALARM_ACTION_TYPE_SNOOZE    = 1 << 0,
00444 
00454   ALARM_ACTION_TYPE_DBUS      = 1 << 1,
00455 
00461   ALARM_ACTION_TYPE_EXEC      = 1 << 2,
00462 
00463 #if ALARMD_ACTION_BOOTFLAGS
00464 
00465   ALARM_ACTION_TYPE_DESKTOP   = 1 << 3,
00466 
00468   ALARM_ACTION_TYPE_ACTDEAD   = 1 << 8,
00469 #endif
00470 
00475   ALARM_ACTION_TYPE_DISABLE   = 1 << 10,
00476 
00477   // ---- WHEN ----
00478 
00483   ALARM_ACTION_WHEN_QUEUED    = 1 << 4,
00484 
00493   ALARM_ACTION_WHEN_DELAYED   = 1 << 11,
00494 
00498   ALARM_ACTION_WHEN_TRIGGERED = 1 << 5,
00499 
00510   ALARM_ACTION_WHEN_DISABLED  = 1 << 9,
00511 
00514   ALARM_ACTION_WHEN_RESPONDED = 1 << 6,
00515 
00518   ALARM_ACTION_WHEN_DELETED   = 1 << 7,
00519 
00520   // ---- DBUS ----
00521 
00524   ALARM_ACTION_DBUS_USE_ACTIVATION = 1 << 12,
00525 
00528   ALARM_ACTION_DBUS_USE_SYSTEMBUS  = 1 << 13,
00529 
00532   ALARM_ACTION_DBUS_ADD_COOKIE     = 1 << 14,
00533 
00534   // ---- EXEC ----
00535 
00550   ALARM_ACTION_EXEC_ADD_COOKIE     = 1 << 15,
00551 
00552   // ---- MASKS ----
00553 
00554   ALARM_ACTION_TYPE_MASK = (ALARM_ACTION_TYPE_SNOOZE |
00555                             ALARM_ACTION_TYPE_DISABLE|
00556                             ALARM_ACTION_TYPE_DBUS   |
00557                             ALARM_ACTION_TYPE_EXEC   |
00558 #if ALARMD_ACTION_BOOTFLAGS
00559                             ALARM_ACTION_TYPE_DESKTOP|
00560                             ALARM_ACTION_TYPE_ACTDEAD|
00561 #endif
00562                             0),
00563 
00564   ALARM_ACTION_WHEN_MASK = (ALARM_ACTION_WHEN_QUEUED    |
00565                             ALARM_ACTION_WHEN_DELAYED   |
00566                             ALARM_ACTION_WHEN_TRIGGERED |
00567                             ALARM_ACTION_WHEN_DISABLED  |
00568                             ALARM_ACTION_WHEN_RESPONDED |
00569                             ALARM_ACTION_WHEN_DELETED),
00570 
00571 } alarmactionflags;
00572 
00615 typedef struct alarm_action_t
00616 {
00618   unsigned  flags;
00619 
00632   char     *label;
00633 
00640   char     *exec_command;
00641 
00648   char     *dbus_interface;
00649 
00657   char     *dbus_service;
00658 
00665   char     *dbus_path;
00666 
00673   char     *dbus_name;
00674 
00687   char     *dbus_args;
00688 
00689 } alarm_action_t;
00690 
00691 /* ------------------------------------------------------------------------- *
00692  * alarm_action_t
00693  * ------------------------------------------------------------------------- */
00694 
00698 
00700 void            alarm_action_ctor     (alarm_action_t *self);
00702 void            alarm_action_dtor     (alarm_action_t *self);
00704 alarm_action_t *alarm_action_create   (void);
00706 void            alarm_action_delete   (alarm_action_t *self);
00708 void            alarm_action_delete_cb(void *self);
00709 
00719 int alarm_action_is_button(const alarm_action_t *self);
00720 
00733 int             alarm_action_set_dbus_args       (alarm_action_t *self, int type, ...);
00734 
00739 void            alarm_action_del_dbus_args       (alarm_action_t *self);
00740 
00751 int             alarm_action_set_dbus_args_valist(alarm_action_t *self, int type, va_list va);
00752 
00758 const char     *alarm_action_get_label           (const alarm_action_t *self);
00759 
00765 const char     *alarm_action_get_exec_command    (const alarm_action_t *self);
00766 
00772 const char     *alarm_action_get_dbus_interface  (const alarm_action_t *self);
00773 
00779 const char     *alarm_action_get_dbus_service    (const alarm_action_t *self);
00780 
00786 const char     *alarm_action_get_dbus_path       (const alarm_action_t *self);
00787 
00793 const char     *alarm_action_get_dbus_name       (const alarm_action_t *self);
00794 
00800 void            alarm_action_set_label           (alarm_action_t *self, const char *label);
00801 
00807 void            alarm_action_set_exec_command    (alarm_action_t *self, const char *exec_command);
00808 
00814 void            alarm_action_set_dbus_interface  (alarm_action_t *self, const char *dbus_interface);
00815 
00821 void            alarm_action_set_dbus_service    (alarm_action_t *self, const char *dbus_service);
00822 
00828 void            alarm_action_set_dbus_path       (alarm_action_t *self, const char *dbus_path);
00829 
00835 void            alarm_action_set_dbus_name       (alarm_action_t *self, const char *dbus_name);
00836 
00881 typedef struct alarm_recur_t
00882 {
00883   // NOTE: bit indexing is struct tm compatible
00884 
00893   uint64_t mask_min;    // 0 .. 59
00894 
00901   uint32_t mask_hour;   // 0 .. 23
00902 
00909   uint32_t mask_mday;   // 1 .. 31   1=first
00910 
00917   uint32_t mask_wday;   // 0 .. 6    0=sunday
00924   uint32_t mask_mon;    // 0 .. 11   0=january
00925 
00934   uint32_t special;
00935 
00936 } alarm_recur_t;
00937 
00944 typedef enum alarmrecurflags
00945 {
00947   ALARM_RECUR_MIN_DONTCARE  = 0,
00949   ALARM_RECUR_MIN_ALL       = (1ull << 60) - 1,
00950 
00952   ALARM_RECUR_HOUR_DONTCARE = 0,
00954   ALARM_RECUR_HOUR_ALL      = (1u << 24) - 1,
00955 
00957   ALARM_RECUR_MDAY_DONTCARE = 0,
00959   ALARM_RECUR_MDAY_ALL      = ~1u,
00962   ALARM_RECUR_MDAY_EOM      =  1u,
00963 
00965   ALARM_RECUR_WDAY_DONTCARE = 0,
00967   ALARM_RECUR_WDAY_ALL      = (1u << 7) - 1,
00969   ALARM_RECUR_WDAY_SUN      = (1u << 0),
00971   ALARM_RECUR_WDAY_MON      = (1u << 1),
00973   ALARM_RECUR_WDAY_TUE      = (1u << 2),
00975   ALARM_RECUR_WDAY_WED      = (1u << 3),
00977   ALARM_RECUR_WDAY_THU      = (1u << 4),
00979   ALARM_RECUR_WDAY_FRI      = (1u << 5),
00981   ALARM_RECUR_WDAY_SAT      = (1u << 6),
00983   ALARM_RECUR_WDAY_MONFRI   = ALARM_RECUR_WDAY_SAT - ALARM_RECUR_WDAY_MON,
00985   ALARM_RECUR_WDAY_SATSUN   = ALARM_RECUR_WDAY_SAT | ALARM_RECUR_WDAY_SUN,
00986 
00988   ALARM_RECUR_MON_DONTCARE = 0,
00990   ALARM_RECUR_MON_ALL       = (1u << 12) - 1,
00992   ALARM_RECUR_MON_JAN       = (1u <<  0),
00994   ALARM_RECUR_MON_FEB       = (1u <<  1),
00996   ALARM_RECUR_MON_MAR       = (1u <<  2),
00998   ALARM_RECUR_MON_APR       = (1u <<  3),
01000   ALARM_RECUR_MON_MAY       = (1u <<  4),
01002   ALARM_RECUR_MON_JUN       = (1u <<  5),
01004   ALARM_RECUR_MON_JUL       = (1u <<  6),
01006   ALARM_RECUR_MON_AUG       = (1u <<  7),
01008   ALARM_RECUR_MON_SEP       = (1u <<  8),
01010   ALARM_RECUR_MON_OCT       = (1u <<  9),
01012   ALARM_RECUR_MON_NOW       = (1u << 10),
01014   ALARM_RECUR_MON_DEC       = (1u << 11),
01015 
01017   ALARM_RECUR_SPECIAL_NONE      = 0,
01019   ALARM_RECUR_SPECIAL_BIWEEKLY  = 1,
01021   ALARM_RECUR_SPECIAL_MONTHLY   = 2,
01023   ALARM_RECUR_SPECIAL_YEARLY    = 3,
01024 } alarmrecurflags;
01025 
01029 
01034 void           alarm_recur_ctor           (alarm_recur_t *self);
01035 
01040 void           alarm_recur_dtor           (alarm_recur_t *self);
01041 
01046 alarm_recur_t *alarm_recur_create         (void);
01047 
01052 void           alarm_recur_delete         (alarm_recur_t *self);
01053 
01059 void           alarm_recur_init_from_tm   (alarm_recur_t *self, const struct tm *tm);
01060 
01065 void           alarm_recur_delete_cb      (void *self);
01066 
01075 time_t         alarm_recur_align          (const alarm_recur_t *self, struct tm *trg, const char *tz);
01076 
01085 time_t         alarm_recur_next           (const alarm_recur_t *self, struct tm *trg, const char *tz);
01086 
01095 typedef enum alarmeventflags
01096 {
01097   // 0                   1                   2                   3
01098   // 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
01099   // - - - x x x x x - x x x x - - - R R R R R R R R R R R R R R R R
01100 
01103   ALARM_EVENT_BOOT             = 1 << 3,
01104 
01107   ALARM_EVENT_ACTDEAD          = 1 << 4,
01108 
01112   ALARM_EVENT_SHOW_ICON        = 1 << 5,
01113 
01118   ALARM_EVENT_CONNECTED        = 1 << 7,
01119 
01126   ALARM_EVENT_RUN_DELAYED      = 1 << 6,
01127 
01134   ALARM_EVENT_POSTPONE_DELAYED = 1 << 9,
01135 
01143   ALARM_EVENT_DISABLE_DELAYED  = 1 << 12,
01144 
01150   ALARM_EVENT_BACK_RESCHEDULE  = 1 << 10,
01151 
01156   ALARM_EVENT_DISABLED         = 1 << 11,
01157 
01161   ALARM_EVENT_CLIENT_BITS      = 16,
01162 
01165   ALARM_EVENT_CLIENT_MASK      = (1 << ALARM_EVENT_CLIENT_BITS) - 1,
01166 
01167 } alarmeventflags;
01168 
01170 #define ALARM_RECURRING_SECONDS(n) (n)
01171 
01172 #define ALARM_RECURRING_MINUTES(n) ((n)*60)
01173 
01174 #define ALARM_RECURRING_HOURS(n)   ((n)*60*60)
01175 
01262 typedef struct alarm_event_t
01263 {
01274   cookie_t       ALARMD_PRIVATE(cookie);
01275 
01282   time_t         ALARMD_PRIVATE(trigger);
01283 
01290   char          *title;
01291 
01298   char          *message;
01299 
01306   char          *sound;
01307 
01314   char          *icon;
01315 
01317   unsigned       flags;
01318 
01325   char          *alarm_appid;
01326 
01346   time_t         alarm_time;
01347 
01364   struct tm      alarm_tm;
01365 
01381   char          *alarm_tz;
01382 
01390   time_t         snooze_secs;
01391 
01396   time_t         snooze_total;
01397 
01404   size_t         action_cnt;
01405 
01412   alarm_action_t *action_tab;
01413 
01415   int            response;
01416 
01422   int             recur_count;
01423 
01426   time_t          recur_secs;
01427 
01432   size_t          recurrence_cnt;
01440   alarm_recur_t  *recurrence_tab;
01441 
01446   size_t          attr_cnt;
01462   alarm_attr_t  **attr_tab;
01463 
01464   /* - - - - - - - - - - - - - - - - - - - *
01465    * changes to this structure -> check also:
01466    *
01467    * event.c:
01468    *   alarm_event_ctor()
01469    *   alarm_event_dtor()
01470    *
01471    * codec.c:
01472    *   encode_event()
01473    *   decode_event()
01474    *
01475    * queue.c:
01476    *   queue_save_to_memory()
01477    *   queue_load_from_path()
01478    *
01479    * - - - - - - - - - - - - - - - - - - - */
01480 
01481 } alarm_event_t;
01482 
01483 /* ------------------------------------------------------------------------- *
01484  * alarm_event_t
01485  * ------------------------------------------------------------------------- */
01486 
01490 
01499 void alarm_event_delete(alarm_event_t *self);
01500 
01510 alarm_event_t *alarm_event_create(void);
01511 
01518 alarm_event_t *alarm_event_create_ex(size_t actions);
01519 
01524 void alarm_event_delete_cb(void *self);
01525 
01530 void alarm_event_ctor(alarm_event_t *self);
01531 
01536 void alarm_event_dtor(alarm_event_t *self);
01537 
01546 cookie_t alarm_event_get_cookie(const alarm_event_t *self);
01547 
01556 void alarm_event_set_cookie(alarm_event_t *self, cookie_t cookie);
01557 
01566 time_t alarm_event_get_trigger(const alarm_event_t *self);
01567 
01576 void alarm_event_set_trigger(alarm_event_t *self, time_t trigger);
01577 
01583 const char     *alarm_event_get_title           (const alarm_event_t *self);
01584 
01590 void            alarm_event_set_title           (alarm_event_t *self, const char *title);
01591 
01597 const char     *alarm_event_get_message           (const alarm_event_t *self);
01598 
01604 void            alarm_event_set_message           (alarm_event_t *self, const char *message);
01605 
01611 const char     *alarm_event_get_sound           (const alarm_event_t *self);
01612 
01618 void            alarm_event_set_sound           (alarm_event_t *self, const char *sound);
01619 
01625 const char     *alarm_event_get_icon           (const alarm_event_t *self);
01626 
01632 void            alarm_event_set_icon           (alarm_event_t *self, const char *icon);
01633 
01639 const char     *alarm_event_get_alarm_appid           (const alarm_event_t *self);
01640 
01646 void            alarm_event_set_alarm_appid           (alarm_event_t *self, const char *alarm_appid);
01647 
01653 const char     *alarm_event_get_alarm_tz           (const alarm_event_t *self);
01654 
01660 void            alarm_event_set_alarm_tz           (alarm_event_t *self, const char *alarm_tz);
01661 
01674 int             alarm_event_is_recurring(const alarm_event_t *self);
01675 
01686 alarm_action_t *alarm_event_add_actions(alarm_event_t *self, size_t count);
01687 
01693 alarm_action_t *alarm_event_get_action(const alarm_event_t *self, int index);
01694 
01700 void alarm_event_del_actions(alarm_event_t *self);
01701 
01714 int alarm_event_set_action_dbus_args(const alarm_event_t *self, int index, int type, ...);
01715 
01725 const char *alarm_event_get_action_dbus_args(const alarm_event_t *self, int index);
01726 
01734 void alarm_event_del_action_dbus_args(const alarm_event_t *self, int index);
01735 
01746 alarm_recur_t *alarm_event_add_recurrences(alarm_event_t *self, size_t count);
01747 
01760 alarm_recur_t *alarm_event_get_recurrence(const alarm_event_t *self, int index);
01761 
01767 void alarm_event_del_recurrences(alarm_event_t *self);
01768 
01780 void alarm_event_set_time(alarm_event_t *self, const struct tm *tm);
01781 
01791 void alarm_event_get_time(const alarm_event_t *self, struct tm *tm);
01792 
01811 int alarm_event_is_sane(const alarm_event_t *self);
01812 
01822 void            alarm_event_del_attrs           (alarm_event_t *self);
01823 
01833 void            alarm_event_rem_attr            (alarm_event_t *self, const char *name);
01834 
01846 alarm_attr_t   *alarm_event_get_attr            (alarm_event_t *self, const char *name);
01847 
01859 int             alarm_event_has_attr            (alarm_event_t *self, const char *name);
01860 
01874 alarm_attr_t   *alarm_event_add_attr            (alarm_event_t *self, const char *name);
01875 
01887 void            alarm_event_set_attr_int        (alarm_event_t *self, const char *name, int val);
01888 
01900 void            alarm_event_set_attr_time       (alarm_event_t *self, const char *name, time_t val);
01901 
01913 void            alarm_event_set_attr_string     (alarm_event_t *self, const char *name, const char *val);
01914 
01928 int             alarm_event_get_attr_int        (alarm_event_t *self, const char *name, int def);
01929 
01943 time_t          alarm_event_get_attr_time       (alarm_event_t *self, const char *name, time_t def);
01944 
01958 const char     *alarm_event_get_attr_string     (alarm_event_t *self, const char *name, const char *def);
01959 
01962 /* ------------------------------------------------------------------------- *
01963  * alarmd functions
01964  * ------------------------------------------------------------------------- */
01965 
01969 
01981 cookie_t alarmd_event_add(const alarm_event_t *event);
01982 
02005 cookie_t alarmd_event_add_with_dbus_params(const alarm_event_t *event,
02006                                            int type, ...);
02007 
02017 int alarmd_event_del(cookie_t cookie);
02018 
02040 cookie_t alarmd_event_update(const alarm_event_t *event);
02041 
02067 cookie_t *alarmd_event_query(const time_t first, const time_t last,
02068                              int32_t flag_mask, int32_t flags,
02069                              const char *appid);
02070 
02082 alarm_event_t *alarmd_event_get(cookie_t cookie);
02083 
02095 int alarmd_set_default_snooze(unsigned int snooze);
02096 
02103 unsigned int alarmd_get_default_snooze(void);
02104 
02106 cookie_t alarmd_event_add_valist(const alarm_event_t *event, int type, va_list va);
02107 
02110 /* ------------------------------------------------------------------------- *
02111  * systemui functions
02112  * ------------------------------------------------------------------------- */
02113 
02118 
02120 int alarmd_ack_dialog(cookie_t cookie, int button);
02121 
02123 int alarmd_ack_queue(cookie_t *cookies, int count);
02124 
02127 /* ------------------------------------------------------------------------- *
02128  * debug functions
02129  * ------------------------------------------------------------------------- */
02130 
02135 
02137 int alarmd_set_debug(unsigned mask_set, unsigned mask_clr,
02138                      unsigned flag_set, unsigned flag_clr);
02139 
02142 #pragma GCC visibility pop
02143 
02144 #ifdef __cplusplus
02145 };
02146 #endif
02147 
02148 #endif /* LIBALARM_H_ */

Generated on Sat Apr 7 17:11:23 2012 for libalarm by  doxygen 1.5.1