~ubuntu-branches/ubuntu/vivid/linphone/vivid

« back to all changes in this revision

Viewing changes to oRTP/src/dll_entry.c

  • Committer: Bazaar Package Importer
  • Author(s): Samuel Mimram
  • Date: 2006-11-15 10:34:50 UTC
  • mfrom: (1.2.1 upstream) (2.1.8 feisty)
  • Revision ID: james.westby@ubuntu.com-20061115103450-qgafwcks2lkhctlj
* New upstream release.
* Enable video support.
* Fix mismatched #endif in mscommon.h, closes: #398307.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
#ifdef WIN32
 
3
#include "ortp-config-win32.h"
 
4
#else
 
5
#include "ortp-config.h"
 
6
#endif
 
7
#include "ortp/ortp.h"  
 
8
 
 
9
typedef struct __STRUCT_SHARED_DATA__
 
10
{
 
11
        DWORD                           m_nReference;
 
12
        DWORD                           m_dwStartTime;
 
13
        BOOL                            m_bInitialize;
 
14
 
 
15
} SHARED_DATA, * LPSHARED_DATA;
 
16
 
 
17
#ifdef EXTERNAL_LOGGER
 
18
#include "logger.h"
 
19
#else
 
20
#define RegisterLog(logVar, logString);
 
21
#define UnregisterLog(logVar, logString);
 
22
#endif
 
23
 
 
24
extern DWORD dwoRTPLogLevel;
 
25
 
 
26
#define SHMEMSIZE       sizeof(SHARED_DATA)
 
27
 
 
28
static  LPSHARED_DATA   lpSharedData;
 
29
static  HANDLE                  hMapObject       = NULL;  // handle to file mapping
 
30
 
 
31
BOOL WINAPI DllMain( 
 
32
                                         HINSTANCE hinstDLL,    // handle to DLL module
 
33
                                         DWORD fdwReason,               // reason for calling function
 
34
                                         LPVOID lpReserved              // reserved
 
35
                                   )  
 
36
{
 
37
        BOOL    fInit = FALSE;
 
38
        WORD    wVersionRequested;
 
39
        WSADATA wsaData;
 
40
 
 
41
    // Perform actions based on the reason for calling.
 
42
    switch( fdwReason ) 
 
43
    { 
 
44
        case DLL_PROCESS_ATTACH:
 
45
 
 
46
                        OutputDebugString("--> dll_entry.c - oRTP.dll - DLL_PROCESS_ATTACH()\n");
 
47
                 
 
48
                        wVersionRequested = MAKEWORD( 1, 0 );
 
49
 
 
50
                        if (WSAStartup(wVersionRequested,&wsaData)!=0) 
 
51
                        {
 
52
                                return FALSE;
 
53
                        }
 
54
 
 
55
            // Create a named file mapping object. 
 
56
            hMapObject = CreateFileMapping( INVALID_HANDLE_VALUE,       // use paging file
 
57
                                                                                        NULL,                                   // default security attributes
 
58
                                                                                        PAGE_READWRITE,                 // read/write access
 
59
                                                                                        0,                                              // size: high 32-bits
 
60
                                                                                        SHMEMSIZE,                              // size: low 32-bits
 
61
                                                                                        "oRTPSharedMemory");  // name of map object
 
62
 
 
63
            if (hMapObject == NULL) 
 
64
                return FALSE; 
 
65
 
 
66
            // The first process to attach initializes memory. 
 
67
            fInit = (GetLastError() != ERROR_ALREADY_EXISTS); 
 
68
 
 
69
            // Get a pointer to the file-mapped shared memory.
 
70
 
 
71
            lpSharedData = (LPSHARED_DATA) MapViewOfFile(   hMapObject,     // object to map view of
 
72
                                                                                                                        FILE_MAP_WRITE, // read/write access
 
73
                                                                                                                        0,              // high offset:  map from
 
74
                                                                                                                        0,              // low offset:   beginning
 
75
                                                                                                                        0);             // default: map entire file
 
76
            if (lpSharedData == NULL) 
 
77
                return FALSE; 
 
78
 
 
79
            // Initialize memory if this is the first process.
 
80
 
 
81
            if (fInit) 
 
82
                        {
 
83
                                OutputDebugString("--> dll_entry.c - oRTP.dll - Initializing module\n");
 
84
 
 
85
                                lpSharedData->m_dwStartTime     = GetTickCount();
 
86
                                lpSharedData->m_nReference      = 1;
 
87
                                lpSharedData->m_bInitialize = FALSE;
 
88
 
 
89
                                // Register the log
 
90
                                RegisterLog(&dwoRTPLogLevel, "LOG_ORTP");
 
91
                        }
 
92
                        else
 
93
                        {
 
94
                                OutputDebugString("--> dll_entry.c - oRTP.dll - Binding\n");
 
95
                                lpSharedData->m_nReference++;
 
96
                        }
 
97
            break;
 
98
 
 
99
        case DLL_THREAD_ATTACH:
 
100
 
 
101
                        if (lpSharedData != NULL)
 
102
                        {
 
103
                                if (lpSharedData->m_bInitialize == FALSE)
 
104
                                {
 
105
                                        // Initialize oRTP
 
106
                                        ortp_init();
 
107
 
 
108
                                        // Start the scheduler
 
109
                                        //ortp_scheduler_init();
 
110
 
 
111
                                        lpSharedData->m_bInitialize = TRUE;
 
112
                                }
 
113
                        }
 
114
            break;
 
115
 
 
116
        case DLL_THREAD_DETACH:
 
117
                        break;
 
118
 
 
119
        case DLL_PROCESS_DETACH:
 
120
 
 
121
                        if (lpSharedData != NULL)
 
122
                        {                       
 
123
                                OutputDebugString("--> dll_entry.c - oRTP.dll - Binding\n");
 
124
                                lpSharedData->m_nReference--;
 
125
 
 
126
                                if (lpSharedData->m_nReference == 0)
 
127
                                {
 
128
                                        OutputDebugString("--> dll_entry.c - oRTP.dll - Detaching\n");
 
129
 
 
130
                                        ortp_exit();
 
131
                                        UnregisterLog(&dwoRTPLogLevel, "LOG_ORTP");
 
132
 
 
133
 
 
134
                                        // Unmap shared memory from the process's address space. 
 
135
                                        UnmapViewOfFile(lpSharedData);
 
136
                                        lpSharedData = NULL;
 
137
         
 
138
                                        // Close the process's handle to the file-mapping object.
 
139
                                        CloseHandle(hMapObject); 
 
140
                                        hMapObject = INVALID_HANDLE_VALUE;
 
141
                                }
 
142
                        }
 
143
            break;
 
144
    }
 
145
 
 
146
    return TRUE;  // Successful DLL_PROCESS_ATTACH.
 
147
}