/[resiprocate]/main/resip/dum/test/basicRegister.cxx
ViewVC logotype

Contents of /main/resip/dum/test/basicRegister.cxx

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3458 - (show annotations) (download)
Tue Nov 16 14:27:08 2004 UTC (15 years, 1 month ago) by sgodin
Original Path: main/sip/resiprocate/dum/test/basicRegister.cxx
File size: 4049 byte(s)
fixed to compile with latest dum changes
1 #include "resiprocate/SipStack.hxx"
2 #include "resiprocate/dum/ClientAuthManager.hxx"
3 #include "resiprocate/dum/ClientRegistration.hxx"
4 #include "resiprocate/dum/DialogUsageManager.hxx"
5 #include "resiprocate/dum/InviteSessionHandler.hxx"
6 #include "resiprocate/dum/Profile.hxx"
7 #include "resiprocate/dum/RegistrationHandler.hxx"
8 #include "resiprocate/os/Log.hxx"
9 #include "resiprocate/os/Logger.hxx"
10 #include "resiprocate/os/Subsystem.hxx"
11 #include "resiprocate/dum/AppDialogSet.hxx"
12 #include "resiprocate/dum/AppDialog.hxx"
13
14
15 #define RESIPROCATE_SUBSYSTEM Subsystem::TEST
16
17 using namespace resip;
18
19 class RegisterAppDialogSet : public AppDialogSet
20 {
21 public:
22 RegisterAppDialogSet(DialogUsageManager& dum) : AppDialogSet(dum)
23 {}
24 };
25
26
27
28 class Client : public ClientRegistrationHandler
29 {
30 public:
31 Client() : done(false), removing(true) {}
32
33 virtual void onSuccess(ClientRegistrationHandle h, const SipMessage& response)
34 {
35 InfoLog( << "Client::Success: " << endl << response );
36 if (removing)
37 {
38 removing = false;
39 #ifdef WIN32
40 Sleep(2000);
41 #else
42 sleep(5);
43 #endif
44 ClientRegistration* foo = h.get();
45 h->removeAll();
46 }
47 else
48 {
49 done = true;
50 }
51 }
52
53 virtual void onRemoved(ClientRegistrationHandle)
54 {
55 InfoLog ( << "Client::onRemoved ");
56 }
57
58 virtual void onFailure(ClientRegistrationHandle, const SipMessage& response)
59 {
60 InfoLog ( << "Client::onFailure: " << response );
61 done = true;
62 }
63
64 bool done;
65 bool removing;
66 };
67
68 /*
69 class RegistrationServer : public ServerRegistrationHandler
70 {
71 public:
72 RegistrationServer() : done(false) {}
73 virtual void onRefresh(ServerRegistrationHandle, const SipMessage& reg)=0;
74
75 /// called when one of the contacts is removed
76 virtual void onRemoveOne(ServerRegistrationHandle, const SipMessage& reg)=0;
77
78 /// Called when all the contacts are removed
79 virtual void onRemoveAll(ServerRegistrationHandle, const SipMessage& reg)=0;
80
81 /// Called when a new contact is added. This is after authentication has
82 /// all sucseeded
83 virtual void onAdd(ServerRegistrationHandle, const SipMessage& reg)=0;
84
85 /// Called when an registration expires
86 virtual void onExpired(ServerRegistrationHandle, const NameAddr& contact)=0;
87 private:
88 bool done;
89 };
90 */
91
92 int
93 main (int argc, char** argv)
94 {
95 int level=(int)Log::Info;
96 if (argc >1 ) level = atoi(argv[1]);
97
98 Log::initialize(Log::Cout, (resip::Log::Level)level, argv[0]);
99
100 Client client;
101 Profile profile;
102 auto_ptr<ClientAuthManager> clientAuth(new ClientAuthManager(profile));
103
104 DialogUsageManager clientDum;
105 clientDum.addTransport(UDP, 15060);
106 clientDum.setProfile(&profile);
107
108 clientDum.setClientRegistrationHandler(&client);
109 clientDum.setClientAuthManager(clientAuth);
110 clientDum.getProfile()->setDefaultRegistrationTime(70);
111
112 NameAddr from("sip:101@proxy.internal.xten.net");
113 clientDum.getProfile()->setDefaultFrom(from);
114
115
116 // profile.addDigestCredential( "xten.gloo.net", "derek@xten.gloo.net", "123456" );
117 // profile.addDigestCredential( "sphone.vopr.vonage.net", "13015604286", "" );
118
119 SipMessage & regMessage = clientDum.makeRegistration(from, new RegisterAppDialogSet(clientDum));
120 NameAddr contact;
121 // contact.uri().user() = "13015604286";
122 // regMessage.header(h_Contacts).push_back(contact);
123
124 InfoLog( << regMessage << "Generated register: " << endl << regMessage );
125 clientDum.send( regMessage );
126
127 int n = 0;
128 while ( !client.done )
129
130 {
131 FdSet fdset;
132
133 // Should these be buildFdSet on the DUM?
134 clientDum.buildFdSet(fdset);
135 int err = fdset.selectMilliSeconds(100);
136 assert ( err != -1 );
137
138 clientDum.process(fdset);
139 if (!(n++ % 10)) cerr << "|/-\\"[(n/10)%4] << '\b';
140
141 }
142 return 0;
143 }

webmaster AT resiprocate DOT org
ViewVC Help
Powered by ViewVC 1.1.27