@@ -191,6 +191,86 @@ public boolean shutdown()
191191
192192 return true ;
193193 }
194+
195+ public void refreshNetworking (int expiry )
196+ {
197+ // keep the old contact around to use for unregistration
198+ Address oldAddress = createContactAddress ();
199+ if (udpListeningPoint != null ) {
200+ try {
201+ sipProvider .removeSipListener (this );
202+ sipStack .deleteSipProvider (sipProvider );
203+ sipStack .deleteListeningPoint (udpListeningPoint );
204+
205+ udpListeningPoint = null ;
206+ } catch (ObjectInUseException e ) {
207+ e .printStackTrace ();
208+ }
209+ }
210+ if (udpListeningPoint == null ) {
211+ // new network interface is up, let's retrieve its ip address
212+ this .sipProfile .setLocalIp (getIPAddress (true ));
213+ try {
214+ udpListeningPoint = sipStack .createListeningPoint (
215+ sipProfile .getLocalIp (), sipProfile .getLocalPort (),
216+ sipProfile .getTransport ());
217+ sipProvider = sipStack .createSipProvider (udpListeningPoint );
218+ sipProvider .addSipListener (this );
219+ } catch (TransportNotSupportedException e ) {
220+ e .printStackTrace ();
221+ } catch (InvalidArgumentException e ) {
222+ e .printStackTrace ();
223+ } catch (ObjectInUseException e ) {
224+ e .printStackTrace ();
225+ } catch (TooManyListenersException e ) {
226+ e .printStackTrace ();
227+ }
228+ }
229+ // unregister the old contact (keep in mind that the new interface will be used to send this request)
230+ Unregister (oldAddress );
231+ // register the new contact with the given expiry
232+ Register (expiry );
233+ }
234+
235+ // release JAIN networking facilities
236+ public void unbind ()
237+ {
238+ if (udpListeningPoint != null ) {
239+ try {
240+ sipProvider .removeSipListener (this );
241+ sipStack .deleteSipProvider (sipProvider );
242+ sipStack .deleteListeningPoint (udpListeningPoint );
243+
244+ udpListeningPoint = null ;
245+ } catch (ObjectInUseException e ) {
246+ e .printStackTrace ();
247+ }
248+ }
249+ }
250+
251+ // setup JAIN networking facilities
252+ public void bind ()
253+ {
254+ if (udpListeningPoint == null ) {
255+ this .sipProfile .setLocalIp (getIPAddress (true ));
256+ try {
257+ udpListeningPoint = sipStack .createListeningPoint (
258+ sipProfile .getLocalIp (), sipProfile .getLocalPort (),
259+ sipProfile .getTransport ());
260+ sipProvider = sipStack .createSipProvider (udpListeningPoint );
261+ sipProvider .addSipListener (this );
262+ } catch (TransportNotSupportedException e ) {
263+ e .printStackTrace ();
264+ } catch (InvalidArgumentException e ) {
265+ e .printStackTrace ();
266+ } catch (ObjectInUseException e ) {
267+ e .printStackTrace ();
268+ } catch (TooManyListenersException e ) {
269+ e .printStackTrace ();
270+ }
271+ }
272+ }
273+
194274 // *** Setters/Getters *** //
195275 public boolean isInitialized () {
196276 return initialized ;
@@ -332,7 +412,7 @@ public void Register(int expiry) {
332412
333413 Register registerRequest = new Register ();
334414 try {
335- final Request r = registerRequest .MakeRequest (this , expiry );
415+ final Request r = registerRequest .MakeRequest (this , expiry , null );
336416 final SipProvider sipProvider = this .sipProvider ;
337417 // Send the request statefully, through the client transaction.
338418 Thread thread = new Thread () {
@@ -357,7 +437,7 @@ public void run() {
357437 }
358438 }
359439
360- public void Unregister () {
440+ public void Unregister (Address contact ) {
361441 if (!latestProxyIp .equals (sipProfile .getRemoteIp ())) {
362442 // proxy ip address has been updated, need to re-initialize
363443 if (!initialize ())
@@ -366,7 +446,7 @@ public void Unregister() {
366446
367447 Register registerRequest = new Register ();
368448 try {
369- final Request r = registerRequest .MakeRequest (this , 0 );
449+ final Request r = registerRequest .MakeRequest (this , 0 , contact );
370450 final SipProvider sipProvider = this .sipProvider ;
371451 // Send the request statefully, through the client transaction.
372452 Thread thread = new Thread () {
@@ -706,21 +786,23 @@ else if (response.getStatusCode() == Response.RINGING) {
706786
707787 // *** JAIN SIP: Exception *** //
708788 public void processIOException (IOExceptionEvent exceptionEvent ) {
709- System . out . println ( "IOException happened for "
710- + exceptionEvent .getHost () + " port = "
711- + exceptionEvent .getPort ());
789+ Log . e ( TAG , "SipManager.processIOException: " + exceptionEvent . toString () + " \n " +
790+ " \t host: " + exceptionEvent .getHost () + "\n " +
791+ " \t port: " + exceptionEvent .getPort ());
712792 }
713793
714794 // *** JAIN SIP: Transaction terminated *** //
715- public void processTransactionTerminated (
716- TransactionTerminatedEvent transactionTerminatedEvent ) {
717- System .out .println ("Transaction terminated event recieved" );
795+ public void processTransactionTerminated (TransactionTerminatedEvent transactionTerminatedEvent ) {
796+ Log .i (TAG , "SipManager.processTransactionTerminated: " + transactionTerminatedEvent .toString () + "\n " +
797+ "\t client transaction: " + transactionTerminatedEvent .getClientTransaction () + "\n " +
798+ "\t server transaction: " + transactionTerminatedEvent .getServerTransaction () + "\n " +
799+ "\t isServerTransaction: " + transactionTerminatedEvent .isServerTransaction ());
718800 }
719801
720802 // *** JAIN SIP: Dialog terminated *** //
721- public void processDialogTerminated (
722- DialogTerminatedEvent dialogTerminatedEvent ) {
723- System . out . println ( "dialogTerminatedEvent" );
803+ public void processDialogTerminated (DialogTerminatedEvent dialogTerminatedEvent ) {
804+ Log . i ( TAG , "SipManager.processDialogTerminated: " + dialogTerminatedEvent . toString () + " \n " +
805+ " \t dialog: " + dialogTerminatedEvent . getDialog () );
724806 }
725807
726808 // *** JAIN SIP: Time out *** //
0 commit comments