account.h 5.93 KB
Newer Older
yanmorin's avatar
 
yanmorin committed
1
/*
2
3
 *  Copyright (C) 2006-2009 Savoir-Faire Linux inc.
 *  Author: Emmanuel Milou <emmanuel.milou@savoirfairelinux.com>
yanmorin's avatar
 
yanmorin committed
4
5
6
7
 *  Author: Yan Morin <yan.morin@savoirfairelinux.com>
 *                                                                              
 *  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
yanmorin's avatar
 
yanmorin committed
9
10
11
12
13
14
15
16
17
18
19
 *  (at your option) any later version.
 *                                                                                
 *  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.
 *                                                                              
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */
20

yanmorin's avatar
 
yanmorin committed
21
22
23
24
#ifndef ACCOUNT_H
#define ACCOUNT_H

#include <string>
25
#include <vector>
26

yanmorin's avatar
   
yanmorin committed
27
#include "config/config.h"
28
#include "voiplink.h"
yanmorin's avatar
 
yanmorin committed
29
30

class VoIPLink;
yanmorin's avatar
   
yanmorin committed
31

32
33
34
35
36
37
38
/**
 * @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)
 */

yanmorin's avatar
 
yanmorin committed
39
typedef std::string AccountID;
40

41
/** Contains all the state an Voip can be in */
Emmanuel Milou's avatar
Emmanuel Milou committed
42
typedef enum RegistrationState {
43
44
45
46
47
48
49
50
51
        Unregistered, 
        Trying, 
        Registered, 
        Error, 
        ErrorAuth , 
        ErrorNetwork , 
        ErrorHost, 
        ErrorExistStun, 
        ErrorConfStun
Emmanuel Milou's avatar
Emmanuel Milou committed
52
} RegistrationState;
53

yanmorin's avatar
   
yanmorin committed
54
#define AccountNULL ""
55
56
57

// Common account parameters
#define CONFIG_ACCOUNT_TYPE   "Account.type"  
yanmorin's avatar
yanmorin committed
58
#define CONFIG_ACCOUNT_ALIAS  "Account.alias"
59
#define CONFIG_ACCOUNT_MAILBOX	"Account.mailbox"
60
61
62
63
64
65
#define CONFIG_ACCOUNT_ENABLE	"Account.enable"
#define HOSTNAME        "hostname"
#define USERNAME        "username"
#define PASSWORD        "password"

// SIP specific parameters
66
#define SIP_PROXY             "SIP.proxy"
Emmanuel Milou's avatar
Emmanuel Milou committed
67
68
69
#define SIP_STUN_SERVER       "STUN.server"
#define SIP_USE_STUN          "STUN.enable"
#define SIP_STUN_PORT         "STUN.port"
70

yanmorin's avatar
 
yanmorin committed
71
class Account{
72
73
74

    public:

75
        Account(const AccountID& accountID, std::string type);
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98

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

        /**
         * Load the settings for this account.
         */
        virtual void loadConfig();

        /**
         * Get the account ID
         * @return constant account id
         */
        inline const AccountID& getAccountID() { return _accountID; }

        /**
         * Get the voiplink pointer
         * @return VoIPLink* the pointer or 0
         */
        inline VoIPLink* getVoIPLink() { return _link; }

Emmanuel Milou's avatar
Emmanuel Milou committed
99
100
        inline void setVoIPLink (VoIPLink *link) { _link = link; }

101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
        /**
         * Register the underlying VoIPLink. Launch the event listener.
         * This should update the getRegistrationState() return value.
         */
        virtual int registerVoIPLink() = 0;

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

        /**
         * Tell if the account is enable or not. 
         * @return true if enabled
         *	     false otherwise
         */
        bool isEnabled() { return _enabled; }

        /**
         * Get the registration state of the specified link
         * @return RegistrationState	The registration state of underlying VoIPLink
         */
124
        inline RegistrationState getRegistrationState() { return _registrationState; }
125

Emmanuel Milou's avatar
Emmanuel Milou committed
126
        void setRegistrationState( RegistrationState state );
127

128
129
        /* inline functions */
        /* They should be treated like macro definitions by the C++ compiler */
130
131
132
133
134
135
136
137
138
139
140
        inline std::string getUsername( void ) { return _username; }
        inline void setUsername( std::string username) { _username = username; }

        inline std::string getHostname( void ) { return _hostname; }
        inline void setHostname( std::string hostname) { _hostname = hostname; }

        inline std::string getPassword( void ) { return _password; }
        inline void setPassword( std::string password ) { _password = password; }

        inline std::string getAlias( void ) { return _alias; }
        inline void setAlias( std::string alias ) { _alias = alias; }
141

142
143
144
145
        inline std::string getType( void ) { return _type; }
        inline void setType( std::string type ) { _type = type; }

    private:
146
147
148
149
150
151
152
153
154
155
156
157
        // copy constructor
        Account(const Account& rh);

        // assignment operator
        Account& operator=(const Account& rh);

    protected:
        /**
         * Account ID are assign in constructor and shall not changed
         */
        AccountID _accountID;

158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
        /**
         * Account login information: username
         */
        std::string _username;

        /**
         * Account login information: hostname
         */
        std::string _hostname;

        /**
         * Account login information: password
         */
        std::string _password;

        /**
         * Account login information: Alias
         */
        std::string _alias;

        /*
         * The account type
         * IAX2 or SIP
         */
        std::string _type;

184
185
186
187
188
189
190
191
192
193
194
195
        /**
         * Voice over IP Link contains a listener thread and calls
         */
        VoIPLink* _link;

        /**
         * Tells if the link is enabled, active.
         * This implies the link will be initialized on startup.
         * Modified by the configuration (key: ENABLED)
         */
        bool _enabled;

196
197
198
199
200
        /*
         * The registration state of the account
         */
        RegistrationState _registrationState;

yanmorin's avatar
 
yanmorin committed
201
202
203
};

#endif