File: SipXEventDispatcher.h

package info (click to toggle)
sipxtapi 3.3.0~test18%2Bdfsg.1-0.1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 55,892 kB
  • sloc: cpp: 435,979; ansic: 14,207; makefile: 2,491; java: 2,264; sh: 1,310; perl: 844; xml: 225; awk: 5
file content (103 lines) | stat: -rw-r--r-- 3,254 bytes parent folder | download | duplicates (9)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
//
// Copyright (C) 2006 SIPfoundry Inc.
// Licensed by SIPfoundry under the LGPL license.
//
// Copyright (C) 2006 Robert J. Andreasen, Jr.
// Licensed to SIPfoundry under a Contributor Agreement.
//
// $$
//////////////////////////////////////////////////////////////////////////////

#ifndef _SIPXEVENTDISPATCHER_H_
#define _SIPXEVENTDISPATCHER_H_

// SYSTEM INCLUDES
// APPLICATION INCLUDES
#include "os/OsServerTask.h"
#include "tapi/sipXtapi.h"
#include "tapi/sipXtapiEvents.h"
#include "utl/UtlHashMap.h"
#include "os/OsRWMutex.h"

// DEFINES
// MACROS
// EXTERNAL FUNCTIONS
// CONSTANTS
// STRUCTS
// TYPEDEFS
typedef struct
{   
    SIPX_INST                   hInst ;
    SIPX_EVENT_CALLBACK_PROC    pCallbackProc ;
    void*                       pUserData ;
} SIPX_EVENT_LISTENER_CONTEXT ;

// MACROS

// FORWARD DECLARATIONS
class OsEventMsg ;

/**
 * The SipXEventDispatcher adds a listener to sipXtapi and then redispatches
 * all of the sipXtapi events on its own callback.  Ideally, this should be 
 * part of sipXtapi -- however, I don't want to change the behavior at this 
 * time.  Also, solutions for the TODOs below are needed.
 *
 * TODO: 
 *
 * - The S/MIME (and TLS?) code expects a return value.  This should be broken
 *   into a new/different callback.  Right now, that functionality is lost
 *   and I believe we will accept all certificates (return true at end of 
 *   SipXEventDispatcher::EventCallBack.
 *
 * - Some synchronization is required on the CALL_DESTROY (perhaps other
 *   final events).  Right now, the call could be removed from sipXtapi's
 *   internal bookkeeping structures before the application has the ability
 *   to handle the event.  I believe we should have some sort of "ACK" to the 
 *   call final events (perhaps after it is dispatched from here) and the
 *   call should not be freed up in sipXtapi until after that ACK.  Today,
 *   the call handle is freed in the fire***Event method in 
 *   sipXtapiEvents.cpp.
 */
class SipXEventDispatcher : public OsServerTask
{
public:
/* ============================ CREATORS ================================== */

    SipXEventDispatcher(SIPX_INST hInst);

    virtual ~SipXEventDispatcher(void);
    
/* ============================ MANIPULATORS ============================== */

    /**
     * Implementation of OsServerTask's pure virtual method
     */
    UtlBoolean handleMessage(OsMsg& rMsg);

    bool addListener(SIPX_EVENT_CALLBACK_PROC  pCallbackProc,
                     void*                     pUserData) ;

    bool removeListener(SIPX_EVENT_CALLBACK_PROC  pCallbackProc,
                        void*                     pUserData) ;

    void removeAllListeners() ;

    void serviceListeners(SIPX_EVENT_CATEGORY category, 
                          void*               pInfo) ;

    void setInstanceHandle(SIPX_INST hNew) ;

protected:
    static bool SIPX_CALLING_CONVENTION EventCallBack(SIPX_EVENT_CATEGORY category, 
                                                      void*               pInfo, 
                                                      void*               pUserData);
        
private:
    SIPX_INST  mhInst ;
    UtlHashMap mListeners ;
    OsRWMutex  mListenerLock;
};

#endif // _SIPXEVENTDISPATCHER_H_