00001 /* 00002 * Asterisk -- An open source telephony toolkit. 00003 * 00004 * Copyright (C) 2008 - 2009, Digium, Inc. 00005 * 00006 * Terry Wilson <twilson@digium.com> 00007 * 00008 * See http://www.asterisk.org for more information about 00009 * the Asterisk project. Please do not directly contact 00010 * any of the maintainers of this project for assistance; 00011 * the project provides a web site, mailing lists and IRC 00012 * channels for your use. 00013 * 00014 * This program is free software, distributed under the terms of 00015 * the GNU General Public License Version 2. See the LICENSE file 00016 * at the top of the source tree. 00017 */ 00018 00019 #ifndef _ASTERISK_CALENDAR_H 00020 #define _ASTERISK_CALENDAR_H 00021 00022 #include "asterisk.h" 00023 #include "asterisk/stringfields.h" 00024 #include "asterisk/config.h" 00025 #include "asterisk/linkedlists.h" 00026 #include "asterisk/lock.h" 00027 #include "asterisk/dial.h" 00028 00029 /*! \file calendar.h 00030 * \brief A general API for managing calendar events with Asterisk 00031 * 00032 * \author Terry Wilson <twilson@digium.com> 00033 * 00034 * \note This API implements an abstraction for handling different calendaring 00035 * technologies in Asterisk. The services provided by the API are a dialplan 00036 * function to query whether or not a calendar is busy at the present time, a 00037 * adialplan function to query specific information about events in a time range, 00038 * a devicestate provider, and notification of calendar events through execution 00039 * of dialplan apps or dialplan logic at a specific context and extension. The 00040 * information available through the CALENDAR_EVENT() dialplan function are: 00041 * 00042 * SUMMARY, DESCRIPTION, ORGANIZER, LOCATION 00043 * CALENDAR, UID, START, END, and BUSYSTATE 00044 * 00045 * BUSYSTATE can have the values 0 (free), 1 (tentatively busy), or 2 (busy) 00046 * 00047 * Usage 00048 * All calendaring configuration data is located in calendar.conf and is only read 00049 * directly by the Calendaring API. Each calendar technology resource must register 00050 * a load_calendar callback which will be passed an ast_calendar_load_data structure. 00051 * The load_calendar callback function should then set the values it needs from this 00052 * cfg, load the calendar data, and then loop updating the calendar data and events 00053 * baesd on the refresh interval in the ast_calendar object. Each call to 00054 * the load_calendar callback will be will run in its own thread. 00055 * 00056 * Updating events involves creating an astobj2 container of new events and passing 00057 * it to the API through ast_calendar_merge_events. 00058 * 00059 * Calendar technology resource modules must also register an unref_calendar callback 00060 * which will only be called when the resource module calls ast_calendar_unregister() 00061 * to unregister that module's calendar type (usually done in module_unload()) 00062 */ 00063 00064 struct ast_calendar; 00065 struct ast_calendar_event; 00066 00067 /*! \brief Individual calendaring technology data */ 00068 struct ast_calendar_tech { 00069 const char *type; 00070 const char *description; 00071 const char *module; 00072 int (* is_busy)(struct ast_calendar *calendar); /*!< Override default busy determination */ 00073 void *(* load_calendar)(void *data); /*!< Create private structure, add calendar events, etc. */ 00074 void *(* unref_calendar)(void *obj); /*!< Function to be called to free the private structure */ 00075 int (* write_event)(struct ast_calendar_event *event); /*!< Function for writing an event to the calendar */ 00076 AST_LIST_ENTRY(ast_calendar_tech) list; 00077 }; 00078 00079 enum ast_calendar_busy_state { 00080 AST_CALENDAR_BS_FREE = 0, 00081 AST_CALENDAR_BS_BUSY_TENTATIVE, 00082 AST_CALENDAR_BS_BUSY, 00083 }; 00084 00085 struct ast_calendar_attendee { 00086 char *data; 00087 AST_LIST_ENTRY(ast_calendar_attendee) next; 00088 }; 00089 00090 /* \brief Calendar events */ 00091 struct ast_calendar_event { 00092 AST_DECLARE_STRING_FIELDS( 00093 AST_STRING_FIELD(summary); 00094 AST_STRING_FIELD(description); 00095 AST_STRING_FIELD(organizer); 00096 AST_STRING_FIELD(location); 00097 AST_STRING_FIELD(uid); 00098 AST_STRING_FIELD(categories); 00099 ); 00100 int priority; /*!< Priority of event */ 00101 struct ast_calendar *owner; /*!< The calendar that owns this event */ 00102 time_t start; /*!< Start of event (UTC) */ 00103 time_t end; /*!< End of event (UTC) */ 00104 time_t alarm; /*!< Time for event notification */ 00105 enum ast_calendar_busy_state busy_state; /*!< The busy status of the event */ 00106 int notify_sched; /*!< The sched for event notification */ 00107 int bs_start_sched; /*!< The sched for changing the device state at the start of an event */ 00108 int bs_end_sched; /*!< The sched for changing the device state at the end of an event */ 00109 struct ast_dial *dial; 00110 struct ast_channel *notify_chan; 00111 AST_LIST_HEAD_NOLOCK(attendees, ast_calendar_attendee) attendees; 00112 }; 00113 00114 /*! \brief Asterisk calendar structure */ 00115 struct ast_calendar { 00116 const struct ast_calendar_tech *tech; 00117 void *tech_pvt; 00118 AST_DECLARE_STRING_FIELDS( 00119 AST_STRING_FIELD(name); /*!< Name from config file [name] */ 00120 AST_STRING_FIELD(notify_channel); /*!< Channel to use for notification */ 00121 AST_STRING_FIELD(notify_context); /*!< Optional context to execute from for notification */ 00122 AST_STRING_FIELD(notify_extension); /*!< Optional extension to execute from for notification */ 00123 AST_STRING_FIELD(notify_app); /*!< Optional dialplan app to execute for notification */ 00124 AST_STRING_FIELD(notify_appdata); /*!< Optional arguments for dialplan app */ 00125 ); 00126 int autoreminder; /*!< If set, override any calendar_tech specific notification times and use this time (in mins) */ 00127 int notify_waittime; /*!< Maxiumum time to allow for a notification attempt */ 00128 int refresh; /*!< When to refresh the calendar events */ 00129 int timeframe; /*!< Span (in mins) of calendar data to pull with each request */ 00130 pthread_t thread; /*!< The thread that the calendar is loaded/updated in */ 00131 ast_cond_t unload; 00132 int unloading:1; 00133 int pending_deletion:1; 00134 struct ao2_container *events; /*!< The events that are known at this time */ 00135 }; 00136 00137 /*! \brief Register a new calendar technology 00138 * 00139 * \param tech calendar technology to register 00140 * 00141 * \retval 0 success 00142 * \retval -1 failure 00143 */ 00144 int ast_calendar_register(struct ast_calendar_tech *tech); 00145 00146 /*! \brief Unregister a new calendar technology 00147 * 00148 * \param tech calendar technology to unregister 00149 * 00150 * \retval 0 success 00151 * \retval -1 failure 00152 */ 00153 void ast_calendar_unregister(struct ast_calendar_tech *tech); 00154 00155 /*! \brief Allocate an astobj2 ast_calendar_event object 00156 * 00157 * \param cal calendar to allocate an event for 00158 * 00159 * \return a new, initialized calendar event 00160 */ 00161 struct ast_calendar_event *ast_calendar_event_alloc(struct ast_calendar *cal); 00162 00163 /*! \brief Allocate an astobj2 container for ast_calendar_event objects 00164 * 00165 * \return a new event container 00166 */ 00167 struct ao2_container *ast_calendar_event_container_alloc(void); 00168 00169 /*! \brief Add an event to the list of events for a calendar 00170 * 00171 * \param cal calendar containing the events to be merged 00172 * \param new_events an oa2 container of events to be merged into cal->events 00173 */ 00174 void ast_calendar_merge_events(struct ast_calendar *cal, struct ao2_container *new_events); 00175 00176 /*! \brief Unreference an ast_calendar_event 00177 * 00178 * \param event event to unref 00179 * 00180 * \return NULL 00181 */ 00182 struct ast_calendar_event *ast_calendar_unref_event(struct ast_calendar_event *event); 00183 00184 /*! \brief Remove all events from calendar 00185 * 00186 * \param cal calendar whose events need to be cleared 00187 */ 00188 void ast_calendar_clear_events(struct ast_calendar *cal); 00189 00190 /*! \brief Grab and lock pointer to the calendar config (read only) 00191 * 00192 * \note ast_calendar_config_release must be called when finished with the pointer 00193 * 00194 * \return the parsed calendar config 00195 */ 00196 const struct ast_config *ast_calendar_config_acquire(void); 00197 00198 /*! \brief Release the calendar config 00199 */ 00200 void ast_calendar_config_release(void); 00201 00202 #endif /* _ASTERISK_CALENDAR_H */