PageRenderTime 19ms CodeModel.GetById 12ms app.highlight 4ms RepoModel.GetById 1ms app.codeStats 0ms

/razpubs/src/org/cybergarage/upnp/ssdp/SSDPSearchResponseSocket.java

http://razpub.googlecode.com/
Java | 111 lines | 56 code | 23 blank | 32 comment | 6 complexity | 1a3d358fcfe9baa7e9b71498e3a848db MD5 | raw file
  1/******************************************************************
  2*
  3*   CyberUPnP for Java
  4*
  5*   Copyright (C) Satoshi Konno 2002
  6*
  7*   File: SSDPSearchResponseSocket.java
  8*
  9*   Revision;
 10*
 11*   11/20/02
 12*       - first revision.
 13*   05/28/03
 14*       - Added post() to send a SSDPSearchRequest.
 15*   
 16******************************************************************/
 17
 18package org.cybergarage.upnp.ssdp;
 19
 20import org.cybergarage.upnp.*;
 21
 22public class SSDPSearchResponseSocket extends HTTPUSocket implements Runnable
 23{
 24    ////////////////////////////////////////////////
 25    //  Constructor
 26    ////////////////////////////////////////////////
 27
 28    public SSDPSearchResponseSocket()
 29    {
 30        setControlPoint(null);
 31    }
 32    
 33    public SSDPSearchResponseSocket(String bindAddr, int port)
 34    {
 35        super(bindAddr, port);
 36        setControlPoint(null);
 37    }
 38
 39    ////////////////////////////////////////////////
 40    //  ControlPoint    
 41    ////////////////////////////////////////////////
 42
 43    private ControlPoint controlPoint = null;
 44    
 45    public void setControlPoint(ControlPoint ctrlp)
 46    {
 47        this.controlPoint = ctrlp;
 48    }
 49
 50    public ControlPoint getControlPoint()
 51    {
 52        return controlPoint;
 53    }
 54
 55    ////////////////////////////////////////////////
 56    //  run 
 57    ////////////////////////////////////////////////
 58
 59    private Thread deviceSearchResponseThread = null;
 60        
 61    public void run()
 62    {
 63        Thread thisThread = Thread.currentThread();
 64        
 65        ControlPoint ctrlPoint = getControlPoint();
 66
 67        while (deviceSearchResponseThread == thisThread) {
 68            Thread.yield();
 69            SSDPPacket packet = receive();
 70            if (packet == null)
 71                break;
 72            if (ctrlPoint != null)
 73                ctrlPoint.searchResponseReceived(packet); 
 74        }
 75    }
 76    
 77    public void start()
 78    {
 79        deviceSearchResponseThread = new Thread(this);
 80        
 81        /* Razvan 2008-03: name the thread for debugging*/
 82  		deviceSearchResponseThread.setName("CyberSSDPResponse"+deviceSearchResponseThread.getName());	
 83  		deviceSearchResponseThread.setDaemon(true);
 84  		
 85        deviceSearchResponseThread.start();
 86    }
 87    
 88    public void stop()
 89    {
 90        deviceSearchResponseThread = null;
 91    }
 92
 93    ////////////////////////////////////////////////
 94    //  post
 95    ////////////////////////////////////////////////
 96
 97    public boolean post(String addr, int port, SSDPSearchResponse res)
 98    {
 99        return post(addr, port, res.getHeader());
100    }
101
102    ////////////////////////////////////////////////
103    //  post
104    ////////////////////////////////////////////////
105
106    public boolean post(String addr, int port, SSDPSearchRequest req)
107    {
108        return post(addr, port, req.toString());
109    }
110}
111