account.h 8.95 KB
Newer Older
1
/*
2
 *  Copyright (C) 2004-2012 Savoir-Faire Linux Inc.
3
 *  Author: Emmanuel Milou <emmanuel.milou@savoirfairelinux.com>
4
 *  Author: Yan Morin <yan.morin@savoirfairelinux.com>
Julien Bonjean's avatar
Julien Bonjean committed
5
 *
6 7
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
8
 *  the Free Software Foundation; either version 3 of the License, or
9
 *  (at your option) any later version.
Julien Bonjean's avatar
Julien Bonjean committed
10
 *
11 12 13 14
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
Julien Bonjean's avatar
Julien Bonjean committed
15
 *
16 17
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
18
 *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA.
19 20 21 22 23 24 25 26 27 28 29
 *
 *  Additional permission under GNU GPL version 3 section 7:
 *
 *  If you modify this program, or any covered work, by linking or
 *  combining it with the OpenSSL project's OpenSSL library (or a
 *  modified version of that library), containing parts covered by the
 *  terms of the OpenSSL or SSLeay licenses, Savoir-Faire Linux Inc.
 *  grants you additional permission to convey the resulting work.
 *  Corresponding Source for a non-source form of such a combination
 *  shall include the source code for the parts of OpenSSL used as well
 *  as that of the covered work.
30
 */
31

32 33 34 35
#ifndef ACCOUNT_H
#define ACCOUNT_H

#include <string>
36
#include <vector>
37

38
#include "noncopyable.h"
39
#include "config/sfl_config.h"
40
#include "config/serializable.h"
41
#include "registration_states.h"
42

43
class Account;
44
class VoIPLink;
45

46 47 48
/** Define a type for a AccountMap container */
typedef std::map<std::string, Account*> AccountMap;

49 50 51 52 53 54 55
/**
 * @file account.h
 * @brief Interface to protocol account (SIPAccount, IAXAccount)
 * It can be enable on loading or activate after.
 * It contains account, configuration, VoIP Link and Calls (inside the VoIPLink)
 */

56
class Account : public Serializable {
57 58 59

    public:

60
        Account(const std::string& accountID, const std::string &type);
61 62 63 64 65 66

        /**
         * Virtual destructor
         */
        virtual ~Account();

67
        virtual void setAccountDetails(std::map<std::string, std::string> details) = 0;
Julien Bonjean's avatar
Julien Bonjean committed
68

69
        virtual std::map<std::string, std::string> getAccountDetails() const = 0;
70

71 72 73
        /**
         * Load the settings for this account.
         */
74
        virtual void loadConfig() = 0;
75 76 77 78 79

        /**
         * Get the account ID
         * @return constant account id
         */
80 81
        std::string getAccountID() const {
            return accountID_;
Julien Bonjean's avatar
Julien Bonjean committed
82
        }
83 84 85 86 87

        /**
         * Get the voiplink pointer
         * @return VoIPLink* the pointer or 0
         */
88
        virtual VoIPLink* getVoIPLink() = 0;
89 90 91 92 93

        /**
         * Register the underlying VoIPLink. Launch the event listener.
         * This should update the getRegistrationState() return value.
         */
94
        virtual void registerVoIPLink() = 0;
95 96 97 98 99

        /**
         * Unregister the underlying VoIPLink. Stop the event listener.
         * This should update the getRegistrationState() return value.
         */
100
        virtual void unregisterVoIPLink() = 0;
101 102

        /**
Julien Bonjean's avatar
Julien Bonjean committed
103
         * Tell if the account is enable or not.
104 105 106
         * @return true if enabled
         *	     false otherwise
         */
107
        bool isEnabled() const {
108
            return enabled_;
Julien Bonjean's avatar
Julien Bonjean committed
109
        }
110

111
        void setEnabled(bool enable) {
112
            enabled_ = enable;
Julien Bonjean's avatar
Julien Bonjean committed
113
        }
114

115 116 117 118
        /**
         * Set the registration state of the specified link
         * @param state	The registration state of underlying VoIPLink
         */
119
        void setRegistrationState(const RegistrationState &state);
Julien Bonjean's avatar
Julien Bonjean committed
120

121
        /* They should be treated like macro definitions by the C++ compiler */
122
        std::string getUsername() const {
123
            return username_;
Julien Bonjean's avatar
Julien Bonjean committed
124
        }
125

126
        std::string getHostname() const {
127
            return hostname_;
Julien Bonjean's avatar
Julien Bonjean committed
128
        }
129
        void setHostname(const std::string &hostname) {
130
            hostname_ = hostname;
Julien Bonjean's avatar
Julien Bonjean committed
131 132
        }

133
        std::string getAlias() const {
134
            return alias_;
Julien Bonjean's avatar
Julien Bonjean committed
135
        }
136

137
        void setAlias(const std::string &alias) {
138
            alias_ = alias;
Julien Bonjean's avatar
Julien Bonjean committed
139 140
        }

141 142 143 144 145
        std::vector<std::map<std::string, std::string> >
        getAllVideoCodecs() const;

        std::vector<std::map<std::string, std::string> >
        getActiveVideoCodecs() const;
146

147 148
        static std::vector<int> getDefaultAudioCodecs();

149
         /* Accessor to data structures
150
         * @return The list that reflects the user's choice
Julien Bonjean's avatar
Julien Bonjean committed
151
         */
152
        std::vector<int> getActiveAudioCodecs() const {
153
            return audioCodecList_;
Julien Bonjean's avatar
Julien Bonjean committed
154
        }
155 156 157 158 159

        /**
         * Update both the codec order structure and the codec string used for
         * SDP offer and configuration respectively
         */
160
        void setActiveAudioCodecs(const std::vector<std::string>& list);
161
        void setVideoCodecs(const std::vector<std::map<std::string, std::string> > &codecs);
Julien Bonjean's avatar
Julien Bonjean committed
162

163
        std::string getRingtonePath() const {
164
            return ringtonePath_;
Julien Bonjean's avatar
Julien Bonjean committed
165
        }
166
        void setRingtonePath(const std::string &path) {
167
            ringtonePath_ = path;
Julien Bonjean's avatar
Julien Bonjean committed
168 169
        }

170
        bool getRingtoneEnabled() const {
171
            return ringtoneEnabled_;
Julien Bonjean's avatar
Julien Bonjean committed
172
        }
173
        void setRingtoneEnabled(bool enable) {
174
            ringtoneEnabled_ = enable;
Julien Bonjean's avatar
Julien Bonjean committed
175 176
        }

177
        std::string getDisplayName() const {
178
            return displayName_;
Julien Bonjean's avatar
Julien Bonjean committed
179
        }
180
        void setDisplayName(const std::string &name) {
181
            displayName_ = name;
Julien Bonjean's avatar
Julien Bonjean committed
182 183
        }

184
        std::string getMailBox() const {
185
            return mailBox_;
186 187
        }

188
        void setMailBox(const std::string &mb) {
189
            mailBox_ = mb;
190 191
        }

192
        static const char * const VIDEO_CODEC_ENABLED;
193
        static const char * const VIDEO_CODEC_NAME;
194
        static const char * const VIDEO_CODEC_PARAMETERS;
195
        static const char * const VIDEO_CODEC_BITRATE;
196
    private:
197
        NON_COPYABLE(Account);
198

199 200 201
        /**
         * Helper function used to load the default codec order from the codec factory
         */
202
        void loadDefaultCodecs();
203

204
    protected:
205 206 207 208 209 210 211 212 213 214 215 216 217 218 219
        friend class ConfigurationTest;
        // General configuration keys for accounts
        static const char * const AUDIO_CODECS_KEY;
        static const char * const VIDEO_CODECS_KEY;
        static const char * const RINGTONE_PATH_KEY;
        static const char * const RINGTONE_ENABLED_KEY;
        static const char * const DISPLAY_NAME_KEY;
        static const char * const ALIAS_KEY;
        static const char * const TYPE_KEY;
        static const char * const ID_KEY;
        static const char * const USERNAME_KEY;
        static const char * const AUTHENTICATION_USERNAME_KEY;
        static const char * const PASSWORD_KEY;
        static const char * const HOSTNAME_KEY;
        static const char * const ACCOUNT_ENABLE_KEY;
220
        static const char * const ACCOUNT_AUTOANSWER_KEY;
221 222
        static const char * const MAILBOX_KEY;

223
        static std::string mapStateNumberToString(RegistrationState state);
224

225 226 227
        /**
         * Account ID are assign in constructor and shall not changed
         */
228
        const std::string accountID_;
229

230 231 232
        /**
         * Account login information: username
         */
233
        std::string username_;
234 235 236 237

        /**
         * Account login information: hostname
         */
238
        std::string hostname_;
239 240 241 242

        /**
         * Account login information: Alias
         */
243
        std::string alias_;
244

245 246 247 248 249
        /**
         * Tells if the link is enabled, active.
         * This implies the link will be initialized on startup.
         * Modified by the configuration (key: ENABLED)
         */
250
        bool enabled_;
251

252 253 254
        /* If true, automatically answer calls to this account */
        bool autoAnswerEnabled_;

255 256 257 258
        /*
         * The account type
         * IAX2 or SIP
         */
259
        std::string type_;
260

261
        /*
Julien Bonjean's avatar
Julien Bonjean committed
262
         * The general, protocol neutral registration
263
         * state of the account
264
         */
265
        RegistrationState registrationState_;
266

267
        /**
Julien Bonjean's avatar
Julien Bonjean committed
268
         * Vector containing the order of the codecs
269
         */
270 271
        std::vector<int> audioCodecList_;

Julien Bonjean's avatar
Julien Bonjean committed
272
        /**
273
         * Vector containing the video codecs in order
Julien Bonjean's avatar
Julien Bonjean committed
274
         */
275
        std::vector<std::map<std::string, std::string> > videoCodecList_;
Julien Bonjean's avatar
Julien Bonjean committed
276 277

        /**
278 279 280 281 282
         * List of audio codecs obtained when parsing configuration and used
         * to generate codec order list
         */
        std::string audioCodecStr_;

Julien Bonjean's avatar
Julien Bonjean committed
283 284 285
        /**
         * Ringtone .au file used for this account
         */
286
        std::string ringtonePath_;
Julien Bonjean's avatar
Julien Bonjean committed
287 288 289 290

        /**
         * Play ringtone when receiving a call
         */
291
        bool ringtoneEnabled_;
Julien Bonjean's avatar
Julien Bonjean committed
292 293 294 295

        /**
         * Display name when calling
         */
296
        std::string displayName_;
297

Julien Bonjean's avatar
Julien Bonjean committed
298 299 300
        /**
         * Useragent used for registration
         */
301
        std::string userAgent_;
302 303 304 305

        /**
             * Account mail box
         */
306
        std::string mailBox_;
307

308 309 310
};

#endif