-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathTest.cpp
More file actions
76 lines (62 loc) · 2.71 KB
/
Test.cpp
File metadata and controls
76 lines (62 loc) · 2.71 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
70
71
72
73
74
75
76
/*
* Test.cpp
*
* Created on: Dec 30, 2011
* Author: augcampos
*/
//man 8 ldconfig (dont forget)
#include <iostream>
#include <asteriskcpp/Manager.hpp>
#include <asteriskcpp/manager/responses/ManagerError.h>
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 = new asteriskcpp::EventsAction("OFF");
mc.sendAction(ea);
asteriskcpp::EventsAction *ea2 = new asteriskcpp::EventsAction("ON");
mc.sendAction(ea2);
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::ManagerResponse* mr = mc.syncSendAction(coma);
if (mr->getType() == asteriskcpp::ManagerResponse::Type_ERROR) {
asteriskcpp::ManagerError *me = (asteriskcpp::ManagerError*)mr;
std::cout << std::endl << "XXXXXX" << me->toLog() << std::endl;
} else {
asteriskcpp::CommandResponse* cr = (asteriskcpp::CommandResponse*)mr;
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 mr;
}
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);
}