calendar.h 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. /*
  2. * Asterisk -- An open source telephony toolkit.
  3. *
  4. * Copyright (C) 2008 - 2009, Digium, Inc.
  5. *
  6. * Terry Wilson <twilson@digium.com>
  7. *
  8. * See http://www.asterisk.org for more information about
  9. * the Asterisk project. Please do not directly contact
  10. * any of the maintainers of this project for assistance;
  11. * the project provides a web site, mailing lists and IRC
  12. * channels for your use.
  13. *
  14. * This program is free software, distributed under the terms of
  15. * the GNU General Public License Version 2. See the LICENSE file
  16. * at the top of the source tree.
  17. */
  18. #ifndef _ASTERISK_CALENDAR_H
  19. #define _ASTERISK_CALENDAR_H
  20. #include "asterisk.h"
  21. #include "asterisk/stringfields.h"
  22. #include "asterisk/config.h"
  23. #include "asterisk/linkedlists.h"
  24. #include "asterisk/lock.h"
  25. #include "asterisk/dial.h"
  26. #include "asterisk/module.h"
  27. /*! \file calendar.h
  28. * \brief A general API for managing calendar events with Asterisk
  29. *
  30. * \author Terry Wilson <twilson@digium.com>
  31. *
  32. * \note This API implements an abstraction for handling different calendaring
  33. * technologies in Asterisk. The services provided by the API are a dialplan
  34. * function to query whether or not a calendar is busy at the present time, a
  35. * adialplan function to query specific information about events in a time range,
  36. * a devicestate provider, and notification of calendar events through execution
  37. * of dialplan apps or dialplan logic at a specific context and extension. The
  38. * information available through the CALENDAR_EVENT() dialplan function are:
  39. *
  40. * SUMMARY, DESCRIPTION, ORGANIZER, LOCATION
  41. * CALENDAR, UID, START, END, and BUSYSTATE
  42. *
  43. * BUSYSTATE can have the values 0 (free), 1 (tentatively busy), or 2 (busy)
  44. *
  45. * Usage
  46. * All calendaring configuration data is located in calendar.conf and is only read
  47. * directly by the Calendaring API. Each calendar technology resource must register
  48. * a load_calendar callback which will be passed an ast_calendar_load_data structure.
  49. * The load_calendar callback function should then set the values it needs from this
  50. * cfg, load the calendar data, and then loop updating the calendar data and events
  51. * baesd on the refresh interval in the ast_calendar object. Each call to
  52. * the load_calendar callback will be will run in its own thread.
  53. *
  54. * Updating events involves creating an astobj2 container of new events and passing
  55. * it to the API through ast_calendar_merge_events.
  56. *
  57. * Calendar technology resource modules must also register an unref_calendar callback
  58. * which will only be called when the resource module calls ast_calendar_unregister()
  59. * to unregister that module's calendar type (usually done in module_unload())
  60. */
  61. struct ast_calendar;
  62. struct ast_calendar_event;
  63. /*! \brief Individual calendaring technology data */
  64. struct ast_calendar_tech {
  65. const char *type;
  66. const char *description;
  67. const char *module;
  68. struct ast_module_user *user;
  69. int (* is_busy)(struct ast_calendar *calendar); /*!< Override default busy determination */
  70. void *(* load_calendar)(void *data); /*!< Create private structure, add calendar events, etc. */
  71. void *(* unref_calendar)(void *obj); /*!< Function to be called to free the private structure */
  72. int (* write_event)(struct ast_calendar_event *event); /*!< Function for writing an event to the calendar */
  73. AST_LIST_ENTRY(ast_calendar_tech) list;
  74. };
  75. enum ast_calendar_busy_state {
  76. AST_CALENDAR_BS_FREE = 0,
  77. AST_CALENDAR_BS_BUSY_TENTATIVE,
  78. AST_CALENDAR_BS_BUSY,
  79. };
  80. struct ast_calendar_attendee {
  81. char *data;
  82. AST_LIST_ENTRY(ast_calendar_attendee) next;
  83. };
  84. /* \brief Calendar events */
  85. struct ast_calendar_event {
  86. AST_DECLARE_STRING_FIELDS(
  87. AST_STRING_FIELD(summary);
  88. AST_STRING_FIELD(description);
  89. AST_STRING_FIELD(organizer);
  90. AST_STRING_FIELD(location);
  91. AST_STRING_FIELD(uid);
  92. AST_STRING_FIELD(categories);
  93. );
  94. int priority; /*!< Priority of event */
  95. struct ast_calendar *owner; /*!< The calendar that owns this event */
  96. time_t start; /*!< Start of event (UTC) */
  97. time_t end; /*!< End of event (UTC) */
  98. time_t alarm; /*!< Time for event notification */
  99. enum ast_calendar_busy_state busy_state; /*!< The busy status of the event */
  100. int notify_sched; /*!< The sched for event notification */
  101. int bs_start_sched; /*!< The sched for changing the device state at the start of an event */
  102. int bs_end_sched; /*!< The sched for changing the device state at the end of an event */
  103. struct ast_dial *dial;
  104. struct ast_channel *notify_chan;
  105. AST_LIST_HEAD_NOLOCK(attendees, ast_calendar_attendee) attendees;
  106. };
  107. /*! \brief Asterisk calendar structure */
  108. struct ast_calendar {
  109. const struct ast_calendar_tech *tech;
  110. void *tech_pvt;
  111. AST_DECLARE_STRING_FIELDS(
  112. AST_STRING_FIELD(name); /*!< Name from config file [name] */
  113. AST_STRING_FIELD(notify_channel); /*!< Channel to use for notification */
  114. AST_STRING_FIELD(notify_context); /*!< Optional context to execute from for notification */
  115. AST_STRING_FIELD(notify_extension); /*!< Optional extension to execute from for notification */
  116. AST_STRING_FIELD(notify_app); /*!< Optional dialplan app to execute for notification */
  117. AST_STRING_FIELD(notify_appdata); /*!< Optional arguments for dialplan app */
  118. );
  119. struct ast_variable *vars; /*!< Channel variables to pass to notification channel */
  120. int autoreminder; /*!< If set, override any calendar_tech specific notification times and use this time (in mins) */
  121. int notify_waittime; /*!< Maxiumum time to allow for a notification attempt */
  122. int refresh; /*!< When to refresh the calendar events */
  123. int timeframe; /*!< Span (in mins) of calendar data to pull with each request */
  124. pthread_t thread; /*!< The thread that the calendar is loaded/updated in */
  125. ast_cond_t unload;
  126. int unloading:1;
  127. int pending_deletion:1; /*!< No longer used */
  128. struct ao2_container *events; /*!< The events that are known at this time */
  129. };
  130. /*! \brief Register a new calendar technology
  131. *
  132. * \param tech calendar technology to register
  133. *
  134. * \retval 0 success
  135. * \retval -1 failure
  136. */
  137. int ast_calendar_register(struct ast_calendar_tech *tech);
  138. /*! \brief Unregister a new calendar technology
  139. *
  140. * \param tech calendar technology to unregister
  141. *
  142. * \retval 0 success
  143. * \retval -1 failure
  144. */
  145. void ast_calendar_unregister(struct ast_calendar_tech *tech);
  146. /*! \brief Allocate an astobj2 ast_calendar_event object
  147. *
  148. * \param cal calendar to allocate an event for
  149. *
  150. * \return a new, initialized calendar event
  151. */
  152. struct ast_calendar_event *ast_calendar_event_alloc(struct ast_calendar *cal);
  153. /*! \brief Allocate an astobj2 container for ast_calendar_event objects
  154. *
  155. * \return a new event container
  156. */
  157. struct ao2_container *ast_calendar_event_container_alloc(void);
  158. /*! \brief Add an event to the list of events for a calendar
  159. *
  160. * \param cal calendar containing the events to be merged
  161. * \param new_events an oa2 container of events to be merged into cal->events
  162. */
  163. void ast_calendar_merge_events(struct ast_calendar *cal, struct ao2_container *new_events);
  164. /*! \brief Unreference an ast_calendar_event
  165. *
  166. * \param event event to unref
  167. *
  168. * \return NULL
  169. */
  170. struct ast_calendar_event *ast_calendar_unref_event(struct ast_calendar_event *event);
  171. /*! \brief Remove all events from calendar
  172. *
  173. * \param cal calendar whose events need to be cleared
  174. */
  175. void ast_calendar_clear_events(struct ast_calendar *cal);
  176. /*! \brief Grab and lock pointer to the calendar config (read only)
  177. *
  178. * \note ast_calendar_config_release must be called when finished with the pointer
  179. *
  180. * \return the parsed calendar config
  181. */
  182. const struct ast_config *ast_calendar_config_acquire(void);
  183. /*! \brief Release the calendar config
  184. */
  185. void ast_calendar_config_release(void);
  186. #endif /* _ASTERISK_CALENDAR_H */