/[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 2955 - (hide annotations) (download)
Wed Jun 9 21:12:11 2004 UTC (15 years, 6 months ago) by derek
Original Path: main/sip/resiprocate/dum/test/basicRegister.cxx
File size: 3442 byte(s)
Makefile fixes, slight rework of AppDialog and AppDialogSet
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 2941 #include "resiprocate/dum/Profile.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    
19 derek 2955 class RegisterAppDialogSet : public AppDialogSet
20     {
21     public:
22     RegisterAppDialogSet(DialogUsageManager& dum) : AppDialogSet(dum)
23     {}
24     };
25    
26    
27    
28 derek 2850 class Client : public ClientRegistrationHandler
29     {
30     public:
31     Client() : done(false) {}
32    
33 jason 2941 virtual void onSuccess(ClientRegistrationHandle h, const SipMessage& response)
34 derek 2850 {
35 derek 2929 #ifdef WIN32
36     Sleep(2000);
37     #else
38     sleep(5);
39     #endif
40 alan 2906 InfoLog( << "Client::Success: " << endl << response );
41 derek 2929 h->removeAll();
42     done = true;
43 derek 2850 }
44    
45 jason 2941 virtual void onFailure(ClientRegistrationHandle, const SipMessage& response)
46 derek 2850 {
47 alan 2906 InfoLog ( << "Client::Failure: " << response );
48 derek 2929 done = true;
49 derek 2850 }
50 alan 2906
51 derek 2850 bool done;
52     };
53    
54     /*
55     class RegistrationServer : public ServerRegistrationHandler
56     {
57     public:
58     RegistrationServer() : done(false) {}
59 jason 2941 virtual void onRefresh(ServerRegistrationHandle, const SipMessage& reg)=0;
60 derek 2850
61     /// called when one of the contacts is removed
62 jason 2941 virtual void onRemoveOne(ServerRegistrationHandle, const SipMessage& reg)=0;
63 derek 2850
64     /// Called when all the contacts are removed
65 jason 2941 virtual void onRemoveAll(ServerRegistrationHandle, const SipMessage& reg)=0;
66 derek 2850
67     /// Called when a new contact is added. This is after authentication has
68     /// all sucseeded
69 jason 2941 virtual void onAdd(ServerRegistrationHandle, const SipMessage& reg)=0;
70 derek 2850
71     /// Called when an registration expires
72 jason 2941 virtual void onExpired(ServerRegistrationHandle, const NameAddr& contact)=0;
73 derek 2850
74     private:
75     bool done;
76     };
77     */
78    
79     int
80     main (int argc, char** argv)
81     {
82 derek 2948 int level=(int)Log::Debug;
83 alan 2877 if (argc >1 ) level = atoi(argv[1]);
84    
85 derek 2948 Log::initialize(Log::Cout, (resip::Log::Level)level, argv[0]);
86 alan 2877
87 derek 2850 SipStack clientStack;
88 jason 2894 clientStack.addTransport(UDP, 15060);
89 alan 2877 NameAddr aor("sip:502@jasomi.com");
90 derek 2850
91     Client client;
92 derek 2929 Profile profile;
93     ClientAuthManager clientAuth(profile);
94    
95 derek 2850 DialogUsageManager clientDum(clientStack);
96 derek 2929 clientDum.setProfile(&profile);
97 alan 2895
98 derek 2850 clientDum.setClientRegistrationHandler(&client);
99 derek 2929 clientDum.setClientAuthManager(&clientAuth);
100 derek 2850 clientDum.getProfile()->setDefaultRegistrationTime(70);
101 alan 2877 clientDum.getProfile()->setDefaultAor(aor);
102    
103 derek 2929 profile.addDigestCredential( "sip.jasomi.com", "502", "resiprocate" );
104 fluffy 2882
105 derek 2955 SipMessage & regMessage = clientDum.makeRegistration(new RegisterAppDialogSet(clientDum), aor);
106 alan 2877
107 alan 2906 InfoLog( << regMessage << "Generated register: " << endl << regMessage );
108 fluffy 2870 clientDum.send( regMessage );
109 alan 2877
110     int n = 0;
111     while ( !client.done )
112    
113 derek 2850 {
114     FdSet fdset;
115 fluffy 2870
116 alan 2877 // Should these be buildFdSet on the DUM?
117 fluffy 2870 clientStack.buildFdSet(fdset);
118 derek 2850 int err = fdset.selectMilliSeconds(100);
119     assert ( err != -1 );
120 alan 2877
121     clientDum.process(fdset);
122     if (!(n++ % 10)) cerr << "|/-\\"[(n/10)%4] << '\b';
123    
124 derek 2850 }
125 alan 2877
126 derek 2850 }

webmaster AT resiprocate DOT org
ViewVC Help
Powered by ViewVC 1.1.27