1
2 /*
3 * Copyright (C) 2007 iptego GmbH
4 *
5 * This file is part of SEMS, a free SIP media server.
6 *
7 * SEMS is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * For a license to use the sems software under conditions
13 * other than those described here, or to purchase support for this
14 * software, please contact iptel.org by e-mail at the following addresses:
15 * info@iptel.org
16 *
17 * SEMS is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 */
26 /** @file AmPromptCollection.h */
27 #ifndef AM_PROMPT_COLLECTION_H
28 #define AM_PROMPT_COLLECTION_H
29
lexicographical_compare(const SinglePassRange1 & rng1,const SinglePassRange2 & rng2)30 /**
31 *
32 * Example how to use:
33 *
34 * AM_PROMPT_START;
35 * AM_PROMPT_ADD("enter_pin", "path/to/default/enter_pin.wav");
36 * AM_PROMPT_ADD("ok", "path/to/default/ok.wav");
37 * AM_PROMPT_END(prompts, cfg, APP_NAME);
38 */
39
40 #define AM_PROMPT_START \
41 { \
42 std::vector<std::pair<string, string> > _prompt_names
43
44 #define AM_PROMPT_ADD(_name, _default_file) \
45 _prompt_names.push_back(std::make_pair(_name, _default_file))
46
47 #define AM_PROMPT_END(_prompts, _cfg, _MOD_NAME) \
48 _prompts.configureModule(_cfg, _prompt_names, _MOD_NAME); \
49 }
50
51 #include <map>
52 #include <string>
53 #include <utility>
54 using std::string;
55
56 #include "AmCachedAudioFile.h"
57 #include "AmPlaylist.h"
58 #include "AmConfigReader.h"
59
60 class AudioFileEntry;
61
62 /**
63 * \brief manages AmAudioFiles with name for a session.
64 */
65 class AmPromptCollection {
66
67 // loaded files
68 std::map<string, AudioFileEntry*> store;
69
70 // opened objects
71 std::map<long, vector<AmCachedAudioFile*> > items;
72 // mutex for the above
73 AmMutex items_mut;
74
75 public:
76 AmPromptCollection();
77 ~AmPromptCollection();
78
79 /**
80 * get configuration for announcements from cfg,
81 * check for file existence
82 * @param announcements : name, default file for announcement
83 */
84 int configureModule(AmConfigReader& cfg,
85 vector<std::pair<string, string> >& announcements,
86 const char* mod_name);
87 /**
88 * add a prompt with explicit filename
89 */
90 int setPrompt(const string& name,
91 const string& filename,
92 const char* mod_name);
93
94 /**
95 * check whether prompt exists
96 */
97 bool hasPrompt(const string& name);
98
99 /**
100 * add the announcement identified with @param name
101 * to the playlist @list
102 */
103 int addToPlaylist(const string& name, long sess_id,
104 AmPlaylist& list, bool front=false,
105 bool loop=false);
106 /**
107 * cleanup allocated object of sess_id
108 */
109 void cleanup(long sess_id);
110 };
111
112 /**
113 * \brief AmAudioFile with filename and open flag
114 */
115
116 class AudioFileEntry : public AmAudioFile {
117 AmFileCache cache;
118 bool isopen;
119
120 public:
121 AudioFileEntry();
122 ~AudioFileEntry();
123
124 int load(const std::string& filename);
125 bool isOpen() { return isopen; }
126
127 AmCachedAudioFile* getAudio();
128 };
129
130 #endif
131