call.h 3.27 KB
Newer Older
yanmorin's avatar
   
yanmorin committed
1
2
/*
 *  Copyright (C) 2004-2006 Savoir-Faire Linux inc.
jpbl's avatar
jpbl committed
3
 *  Author: Yan Morin <yan.morin@savoirfairelinux.com>
yanmorin's avatar
   
yanmorin committed
4
5
 *  Author : Laurielle Lea <laurielle.lea@savoirfairelinux.com>
 *
jpbl's avatar
jpbl committed
6
7
8
9
 *  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
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
yanmorin's avatar
   
yanmorin committed
10
 *
jpbl's avatar
jpbl committed
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.
yanmorin's avatar
   
yanmorin committed
15
 *
jpbl's avatar
jpbl committed
16
17
18
19
 *  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.
 */
yanmorin's avatar
   
yanmorin committed
20
21
#ifndef CALL_H
#define CALL_H
jpbl's avatar
jpbl committed
22
23

#include <string>
yanmorin's avatar
   
yanmorin committed
24
25
26
27
28
#include <cc++/thread.h> // for mutex

typedef std::string CallID;

/**
yanmorin's avatar
   
yanmorin committed
29
30
31
 * A call is the base classes for protocol-based calls
 * @author Yan Morin <yan.morin@gmail.com>
 */
yanmorin's avatar
   
yanmorin committed
32
33
34
35
36
class Call{
public:
    enum CallType {Incoming, Outgoing};
    enum ConnectionState {Disconnected, Trying, Progressing, Ringing, Connected };
    enum CallState {Inactive, Active, Hold, Busy, Refused, Error};
jpbl's avatar
jpbl committed
37

yanmorin's avatar
   
yanmorin committed
38
39
40
41
42
43
44
    /**
     * Constructor of a call
     * @param id Unique identifier of the call
     * @param type set definitely this call as incoming/outgoing
     */
    Call(const CallID& id, Call::CallType type);
    virtual ~Call();
jpbl's avatar
jpbl committed
45

yanmorin's avatar
   
yanmorin committed
46
47
48
49
50
    /** 
     * Return a reference on the call id
     * @return call id
     */
    CallID& getCallId() {return _id; }
jpbl's avatar
jpbl committed
51

yanmorin's avatar
   
yanmorin committed
52
53
54
55
56
57
58
    /** 
     * Set the peer number (destination on outgoing)
     * not protected by mutex (when created)
     * @param number peer number
     */
    void setPeerNumber(const std::string& number) {  _peerNumber = number; }
    const std::string& getPeerNumber() {  return _peerNumber; }
jpbl's avatar
jpbl committed
59

yanmorin's avatar
   
yanmorin committed
60
61
62
63
64
65
66
67
    /** 
     * Set the peer name (caller in ingoing)
     * not protected by mutex (when created)
     * @param number peer number
     */
    void setPeerName(const std::string& name) {  _peerName = name; }
    const std::string& getPeerName() {  return _peerName; }

yanmorin's avatar
   
yanmorin committed
68
69
70
71
72
    /**
     * Tell if the call is incoming
     */
    bool isIncoming() { return (_type == Incoming) ? true : false; }

yanmorin's avatar
   
yanmorin committed
73
74
75
76
77
78
79
80
    /** 
     * Set the connection state of the call (protected by mutex)
     */
    void setConnectionState(ConnectionState state);
    /** 
     * get the connection state of the call (protected by mutex)
     */
    ConnectionState getConnectionState();
yanmorin's avatar
   
yanmorin committed
81

yanmorin's avatar
   
yanmorin committed
82
83
84
85
86
87
88
89
    /**
     * Set the state of the call (protected by mutex)
     */
    void setState(CallState state);
    /** 
     * get the call state of the call (protected by mutex)
     */
    CallState getState();
jpbl's avatar
jpbl committed
90

yanmorin's avatar
   
yanmorin committed
91
92
93
protected:
    /** Protect every attribute that can be changed by two threads */
    ost::Mutex _callMutex;
jpbl's avatar
jpbl committed
94

yanmorin's avatar
   
yanmorin committed
95
96
97
private:  
    /** Unique ID of the call */
    CallID _id;
jpbl's avatar
jpbl committed
98

yanmorin's avatar
   
yanmorin committed
99
100
101
102
103
104
    /** Type of the call */
    CallType _type;
    /** Disconnected/Progressing/Trying/Ringing/Connected */
    ConnectionState _connectionState;
    /** Inactive/Active/Hold/Busy/Refused/Error */
    CallState _callState;
jpbl's avatar
jpbl committed
105

yanmorin's avatar
   
yanmorin committed
106
107
    /** Name of the peer */
    std::string _peerName;
jpbl's avatar
jpbl committed
108

yanmorin's avatar
   
yanmorin committed
109
110
    /** Number of the peer */
    std::string _peerNumber;
jpbl's avatar
jpbl committed
111
112
};

yanmorin's avatar
   
yanmorin committed
113
#endif