1 // Copyright (C) 2006-2014 David Sugar, Tycho Softworks.
2 // Copyright (C) 2015 Cherokees of Idaho.
3 //
4 // This program is free software; you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation; either version 3 of the License, or
7 // (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the
12 // GNU General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
16
17 #include <sipwitch-config.h>
18 #include <ucommon/ucommon.h>
19 #include <ucommon/export.h>
25
26 namespace sipwitch {
27
29 {
30 public:
32
34 {Conditional::lock();};
35
37 {Conditional::unlock();};
38
40 {Conditional::signal();};
41
42 private:
43 void exit(void);
44 void run(void);
45 };
46
49 static Mutex private_lock;
50 static memalloc private_heap;
51 static cdrthread run;
52 static bool running = false;
53 static bool down = false;
54 static bool logging = false;
55
57 {
58 }
59
61 {
62 }
63
65 {
66 running = true;
67 linked_pointer<cdr> cp;
69 FILE *fp;
70
71 shell::log(
DEBUG1,
"starting cdr thread");
72
73 for(;;) {
74 Conditional::lock();
75 if(!running) {
76 Conditional::unlock();
77 shell::log(
DEBUG1,
"stopping cdr thread");
78 down = true;
79 return;
80 }
81 Conditional::wait();
82 cp = runlist;
83 fp = NULL;
84 if(runlist && logging)
86 runlist = NULL;
87 logging = false;
88 Conditional::unlock();
89 while(is(cp)) {
90 next = cp->getNext();
92 private_lock.acquire();
93 cp->enlist(&freelist);
94 private_lock.release();
95 cp = next;
96 }
97 if(fp)
98 fclose(fp);
99 }
100 }
101
103 {
107 break;
110 default:
111 break;
112 }
113
115 rec->enlist(&runlist);
117 logging = true;
120 }
121
124
125 private_lock.acquire();
126 if(freelist) {
127 rec = (
cdr *)freelist;
128 freelist = rec->getNext();
129 private_lock.release();
140 return rec;
141 }
142 private_lock.release();
143 return (
cdr *)(private_heap.zalloc(
sizeof(
cdr)));
144 }
145
147 {
148 run.start();
149 }
150
152 {
154 running = false;
157
158 while(!down)
159 Thread::sleep(20);
160 }
161
162 } // end namespace
Used for definitions of plugin modules.
static cdr * get(void)
Get a free cdr node to fill from the cdr memory pool.
static void start(void)
Start cdr subsystem and que dispatch thread.
static void cdrlog(FILE *file, cdr *call)
Post cdr record to a file.
unsigned cid
Internal call sequence identifiers.
enum sipwitch::cdr::@0 type
Start or end of call?
time_t starting
Time the call was received.
static void post(cdr *cdr)
Post cdr record to callbacks through the cdr thread queue.
char reason[16]
Reason the call was terminated.
Basic server call detail record.
Stream events to local clients.
char joined[MAX_IDENT_SIZE]
Call destination eventually joined to.
char dialed[MAX_IDENT_SIZE]
Destination requested on our switch.
static void stop(void)
Stop cdr subsystem.
char display[MAX_DISPLAY_SIZE]
Display name of calling party.
Service configuration and component callbacks.
char ident[MAX_IDENT_SIZE]
Ident of calling parting.
Manage control interface.
Interface class for call detail records.
static void drop(cdr *rec)
Send call disconnected event to clients from cdr stop record.
unsigned long duration
Total duration of the call in seconds.
char uuid[48]
A unique identifier for each and every call.
static const char * env(const char *id)
Return the value of a server environment variable.
static void connect(cdr *rec)
Send call connection to clients from cdr start record.
char network[MAX_NETWORK_SIZE *2]
Subnet interface the caller appeared on.