forked from augcampos/asterisk-cpp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTest.cpp
More file actions
69 lines (55 loc) · 2.2 KB
/
Test.cpp
File metadata and controls
69 lines (55 loc) · 2.2 KB
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
/*
* Test.cpp
*
* Created on: Dec 30, 2011
* Author: augcampos
*/
//man 8 ldconfig (dont forget)
#include <iostream>
#include <asteriskcpp/Manager.hpp>
using namespace asteriskcpp;
void eventCallback(const ManagerEvent& me) {
std::cout << "TEST EVENT START: " << me.getEventName() << std::endl;
if (me.getEventName() == "NewChannel") {
std::cout << "E - " << me.toString() << std::endl;
}
std::cout << "TEST EVENT: " << me.toLog() << std::endl;
}
int main() {
std::cout << asteriskcpp::getCurrentTimeStamp() << " START ASTERISK-CPP-TEST" << std::endl;
LogHandler::getInstance()->setLevel(LL_TRACE);
ManagerConnection mc;
try {
mc.addEventCallback(&eventCallback);
if (mc.connect("192.168.1.10")) {
if (mc.login("administrator", "secret")) {
for (int i = 0; i < 1; i++) {
asteriskcpp::EventsAction ea("OFF");
mc.sendAction(ea);
ea.setEventMask("ON");
mc.sendAction(ea);
asteriskcpp::ManagerResponse* rpc;
asteriskcpp::AbsoluteTimeoutAction ata("SIP/1000", 30);
rpc = mc.syncSendAction(ata);
delete (rpc);
asteriskcpp::ListCommandsAction lca;
rpc = mc.syncSendAction(lca);
delete (rpc);
asteriskcpp::CommandAction coma("sip show peers");
asteriskcpp::CommandResponse* cr = (asteriskcpp::CommandResponse*) (mc.syncSendAction(coma));
std::cout << std::endl << "ZZZZZZ" << cr->toLog() << std::endl;
for (std::vector<std::string>::const_iterator it = cr->getResult().begin(); it != cr->getResult().end(); it++) {
std::cout << "[" << (*it) << "]" << std::endl;
}
delete (cr);
}
mc.logoff();
}
mc.disconnect();
}
} catch (Exception e) {
std::cout << " ERROR :" << e.getMessage() << std::endl;
}
std::cout << asteriskcpp::getCurrentTimeStamp() << " END ASTERISK-CPP-TEST" << std::endl;
exit(0);
}