1 #include <johnnyclient.h>	//library headers
 2 #include <iostream>			//streams
 3 
 4 using namespace std;
 5 
 6 int
 7 jcallback (vc::cEvent &sEvent)
 8 {
 9 	cout << vc::cEvent::GetEventText(sEvent);	//print proper text
10 	return VC_OK;
11 }
12 
13 int
14 main(int argc, char *argv[])
15 {
16 	vc::cJohnnyClient johnny;
17 	vc::cReply sReply;
18 	int iTemp;
19 	char c;
20 	string sInput
21 	string sNumber("guest@misery.digium.com/s");	
22 				//could be get from command line
23 
24 	int iResult = johnny.Connect(string("127.0.0.1"), 9991);	
25 				//connect to server
26 	if FAILED(iResult)
27 	{
28 		cerr << johnny::GetConnectErrorText();
29 		return -1;
30 	}
31 	johnny.SetAllCallbacks(jcallback);
32 
33 	while (1)
34 	{
35 		cin >> sInput;
36 		if (!sInput.length())
37 			continue;	//shouldn't happen
38 		c = sInput[0];
39 		if (c == 'q')
40 			break;		//breaking out
41 		else if (c == 'c')
42 		{
43 			iTemp = johnny.Call(sNumber, sReply);	//call
44 			if FAILED(iTemp)
45 				break;	//internal error, breaking out
46 			if (sReply.IsError())
47 				cout << johnny.GetCallErrorText(sReply);
48 		}
49 		else if (c == 'd')
50 		{
51 			iTemp = johnny.DumpCall(sReply);	//dump call
52 			if FAILED(iTemp)
53 				break;	//internal error, breaking out
54 			if (sReply.IsError())
55 				cout << johnny.GetDumpErrorText(sReply);
56 		}
57 		else if (c == 'a')
58 		{
59 			iTemp = johnny.AnswerCall(sReply);	//answer call
60 			if FAILED(iTemp)
61 				break;	//internal error, breaking out
62 			if (sReply.IsError())
63 				cout << johnny.GetAnswerErrorText(sReply);
64 		}
65 		else
66 		{
67 			cout << "Unhandled key (" << c << ")" << endl;
68 		}
69 	}
70 	johnny.Disconnect();	//disconnect from server
71 	return 0;
72 }


syntax highlighted by Code2HTML, v. 0.9.1