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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 4010 - (hide annotations) (download)
Sat Mar 19 03:54:17 2005 UTC (14 years, 8 months ago) by jason
Original Path: main/sip/resiprocate/dum/test/basicRegister.cxx
File size: 4091 byte(s)
merged changes from b-teltel-20041118-invitesession 3484:HEAD into the trunk


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

webmaster AT resiprocate DOT org
ViewVC Help
Powered by ViewVC 1.1.27