Asterisk - The Open Source Telephony Project GIT-master-a358458
calendar.h
Go to the documentation of this file.
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
19#ifndef _ASTERISK_CALENDAR_H
20#define _ASTERISK_CALENDAR_H
21
22#include "asterisk.h"
24#include "asterisk/config.h"
26#include "asterisk/lock.h"
27#include "asterisk/dial.h"
28#include "asterisk/module.h"
29
30/*!
31 * \file
32 *
33 * \brief A general API for managing calendar events with Asterisk
34 *
35 * \author Terry Wilson <twilson@digium.com>
36 *
37 * \note This API implements an abstraction for handling different calendaring
38 * technologies in Asterisk. The services provided by the API are a dialplan
39 * function to query whether or not a calendar is busy at the present time, a
40 * adialplan function to query specific information about events in a time range,
41 * a devicestate provider, and notification of calendar events through execution
42 * of dialplan apps or dialplan logic at a specific context and extension. The
43 * information available through the CALENDAR_EVENT() dialplan function are:
44 *
45 * SUMMARY, DESCRIPTION, ORGANIZER, LOCATION
46 * CALENDAR, UID, START, END, and BUSYSTATE
47 *
48 * BUSYSTATE can have the values 0 (free), 1 (tentatively busy), or 2 (busy)
49 *
50 * Usage
51 * All calendaring configuration data is located in calendar.conf and is only read
52 * directly by the Calendaring API. Each calendar technology resource must register
53 * a load_calendar callback which will be passed an ast_calendar_load_data structure.
54 * The load_calendar callback function should then set the values it needs from this
55 * cfg, load the calendar data, and then loop updating the calendar data and events
56 * based on the refresh interval in the ast_calendar object. Each call to
57 * the load_calendar callback will be will run in its own thread.
58 *
59 * Updating events involves creating an astobj2 container of new events and passing
60 * it to the API through ast_calendar_merge_events.
61 *
62 * Calendar technology resource modules must also register an unref_calendar callback
63 * which will only be called when the resource module calls ast_calendar_unregister()
64 * to unregister that module's calendar type (usually done in module_unload())
65 */
66
67struct ast_calendar;
69
70/*! \brief Individual calendaring technology data */
72 const char *type;
73 const char *description;
74 const char *module;
76 int (* is_busy)(struct ast_calendar *calendar); /*!< Override default busy determination */
77 void *(* load_calendar)(void *data); /*!< Create private structure, add calendar events, etc. */
78 void *(* unref_calendar)(void *obj); /*!< Function to be called to free the private structure */
79 int (* write_event)(struct ast_calendar_event *event); /*!< Function for writing an event to the calendar */
81};
82
87};
88
90 char *data;
92};
93
94/*! \brief Calendar events */
103 );
104 int priority; /*!< Priority of event */
105 struct ast_calendar *owner; /*!< The calendar that owns this event */
106 time_t start; /*!< Start of event (UTC) */
107 time_t end; /*!< End of event (UTC) */
108 time_t alarm; /*!< Time for event notification */
109 enum ast_calendar_busy_state busy_state; /*!< The busy status of the event */
110 int notify_sched; /*!< The sched for event notification */
111 int bs_start_sched; /*!< The sched for changing the device state at the start of an event */
112 int bs_end_sched; /*!< The sched for changing the device state at the end of an event */
113 struct ast_dial *dial;
116};
117
118/*! \brief Asterisk calendar structure */
120 const struct ast_calendar_tech *tech;
121 void *tech_pvt;
123 AST_STRING_FIELD(name); /*!< Name from config file [name] */
124 AST_STRING_FIELD(notify_channel); /*!< Channel to use for notification */
125 AST_STRING_FIELD(notify_context); /*!< Optional context to execute from for notification */
126 AST_STRING_FIELD(notify_extension); /*!< Optional extension to execute from for notification */
127 AST_STRING_FIELD(notify_app); /*!< Optional dialplan app to execute for notification */
128 AST_STRING_FIELD(notify_appdata); /*!< Optional arguments for dialplan app */
129 );
130 struct ast_variable *vars; /*!< Channel variables to pass to notification channel */
131 int autoreminder; /*!< If set, override any calendar_tech specific notification times and use this time (in mins) */
132 int notify_waittime; /*!< Maxiumum time to allow for a notification attempt */
133 int refresh; /*!< When to refresh the calendar events */
134 int fetch_again_at_reload; /*!< To reload the calendar content when the module is reloaded */
135 int timeframe; /*!< Span (in mins) of calendar data to pull with each request */
136 pthread_t thread; /*!< The thread that the calendar is loaded/updated in */
138 unsigned int unloading:1;
139 unsigned int pending_deletion:1;
140 struct ao2_container *events; /*!< The events that are known at this time */
141};
142
143/*! \brief Register a new calendar technology
144 *
145 * \param tech calendar technology to register
146 *
147 * \retval 0 success
148 * \retval -1 failure
149 */
151
152/*! \brief Unregister a new calendar technology
153 *
154 * \param tech calendar technology to unregister
155 */
157
158/*! \brief Allocate an astobj2 ast_calendar_event object
159 *
160 * \param cal calendar to allocate an event for
161 *
162 * \return a new, initialized calendar event
163 */
165
166/*! \brief Allocate an astobj2 container for ast_calendar_event objects
167 *
168 * \return a new event container
169 */
171
172/*! \brief Add an event to the list of events for a calendar
173 *
174 * \param cal calendar containing the events to be merged
175 * \param new_events an oa2 container of events to be merged into cal->events
176 */
177void ast_calendar_merge_events(struct ast_calendar *cal, struct ao2_container *new_events);
178
179/*! \brief Unreference an ast_calendar_event
180 *
181 * \param event event to unref
182 *
183 * \return NULL
184 */
186
187/*! \brief Remove all events from calendar
188 *
189 * \param cal calendar whose events need to be cleared
190 */
192
193/*! \brief Grab and lock pointer to the calendar config (read only)
194 *
195 * \note ast_calendar_config_release must be called when finished with the pointer
196 *
197 * \return the parsed calendar config
198 */
199const struct ast_config *ast_calendar_config_acquire(void);
200
201/*! \brief Release the calendar config
202 */
204
205#endif /* _ASTERISK_CALENDAR_H */
Asterisk main include file. File version handling, generic pbx functions.
void ast_calendar_unregister(struct ast_calendar_tech *tech)
Unregister a new calendar technology.
Definition: res_calendar.c:589
void ast_calendar_merge_events(struct ast_calendar *cal, struct ao2_container *new_events)
Add an event to the list of events for a calendar.
void ast_calendar_config_release(void)
Release the calendar config.
Definition: res_calendar.c:272
ast_calendar_busy_state
Definition: calendar.h:83
@ AST_CALENDAR_BS_FREE
Definition: calendar.h:84
@ AST_CALENDAR_BS_BUSY_TENTATIVE
Definition: calendar.h:85
@ AST_CALENDAR_BS_BUSY
Definition: calendar.h:86
struct ao2_container * ast_calendar_event_container_alloc(void)
Allocate an astobj2 container for ast_calendar_event objects.
Definition: res_calendar.c:691
void ast_calendar_clear_events(struct ast_calendar *cal)
Remove all events from calendar.
Definition: res_calendar.c:662
int ast_calendar_register(struct ast_calendar_tech *tech)
Register a new calendar technology.
Definition: res_calendar.c:551
struct ast_calendar_event * ast_calendar_event_alloc(struct ast_calendar *cal)
Allocate an astobj2 ast_calendar_event object.
Definition: res_calendar.c:669
struct ast_calendar_event * ast_calendar_unref_event(struct ast_calendar_event *event)
Unreference an ast_calendar_event.
Definition: res_calendar.c:323
const struct ast_config * ast_calendar_config_acquire(void)
Grab and lock pointer to the calendar config (read only)
Definition: res_calendar.c:260
Dialing API.
Configuration File Parser.
A set of macros to manage forward-linked lists.
#define AST_LIST_HEAD_NOLOCK(name, type)
Defines a structure to be used to hold a list of specified type (with no lock).
Definition: linkedlists.h:225
#define AST_LIST_ENTRY(type)
Declare a forward link structure inside a list entry.
Definition: linkedlists.h:410
Asterisk locking-related definitions:
pthread_cond_t ast_cond_t
Definition: lock.h:178
Asterisk module definitions.
#define AST_DECLARE_STRING_FIELDS(field_list)
Declare the fields needed in a structure.
Definition: stringfields.h:341
#define AST_STRING_FIELD(name)
Declare a string field.
Definition: stringfields.h:303
Generic container type.
struct ast_calendar_attendee * next
Definition: calendar.h:91
Calendar events.
Definition: calendar.h:95
const ast_string_field uid
Definition: calendar.h:103
enum ast_calendar_busy_state busy_state
Definition: calendar.h:109
struct ast_calendar * owner
Definition: calendar.h:105
struct ast_dial * dial
Definition: calendar.h:113
const ast_string_field location
Definition: calendar.h:103
const ast_string_field description
Definition: calendar.h:103
struct ast_channel * notify_chan
Definition: calendar.h:114
const ast_string_field categories
Definition: calendar.h:103
const ast_string_field organizer
Definition: calendar.h:103
struct ast_calendar_event::attendees attendees
const ast_string_field summary
Definition: calendar.h:103
Individual calendaring technology data.
Definition: calendar.h:71
struct ast_calendar_tech::@201 list
const char * description
Definition: calendar.h:73
const char * type
Definition: calendar.h:72
const char * module
Definition: calendar.h:74
struct ast_module_user * user
Definition: calendar.h:75
int(* is_busy)(struct ast_calendar *calendar)
Definition: calendar.h:76
int(* write_event)(struct ast_calendar_event *event)
Definition: calendar.h:79
Asterisk calendar structure.
Definition: calendar.h:119
pthread_t thread
Definition: calendar.h:136
struct ast_variable * vars
Definition: calendar.h:130
void * tech_pvt
Definition: calendar.h:121
const struct ast_calendar_tech * tech
Definition: calendar.h:120
int autoreminder
Definition: calendar.h:131
int timeframe
Definition: calendar.h:135
struct ao2_container * events
Definition: calendar.h:140
int fetch_again_at_reload
Definition: calendar.h:134
const ast_string_field notify_context
Definition: calendar.h:129
const ast_string_field notify_app
Definition: calendar.h:129
unsigned int pending_deletion
Definition: calendar.h:139
const ast_string_field notify_channel
Definition: calendar.h:129
ast_cond_t unload
Definition: calendar.h:137
int notify_waittime
Definition: calendar.h:132
unsigned int unloading
Definition: calendar.h:138
const ast_string_field name
Definition: calendar.h:129
const ast_string_field notify_extension
Definition: calendar.h:129
const ast_string_field notify_appdata
Definition: calendar.h:129
Main Channel structure associated with a channel.
Main dialing structure. Contains global options, channels being dialed, and more!
Definition: dial.c:48
Structure for variables, used for configurations and for channel variables.
Definition: astman.c:222