ControlPoint.java文件学习笔记

  看看构造函数,

 1     ////////////////////////////////////////////////
 2     //    Constructor
 3     ////////////////////////////////////////////////
 4 
 5     public ControlPoint(int ssdpPort, int httpPort,InetAddress[] binds){
 6         ssdpNotifySocketList = new SSDPNotifySocketList(binds);
 7         ssdpSearchResponseSocketList = new SSDPSearchResponseSocketList(binds);
 8         
 9         setSSDPPort(ssdpPort);
10         setHTTPPort(httpPort);
11         
12         setDeviceDisposer(null);//设置过期device清除接口,这儿为空
13         setExpiredDeviceMonitoringInterval(DEFAULT_EXPIRED_DEVICE_MONITORING_INTERVAL);//这儿有设置设备过期时间
14 
15         setRenewSubscriber(null);//设置更新订购? 不解ing
16                 
17         setNMPRMode(false);//NMPR模式是什么模式?
18         setRenewSubscriber(null);//再设置一次?
19     }

 

  DLNA服务器列表的搜索开始于此文件中的start()接口,此接口实际上是调用start(ST.ROOT_DEVICE, SSDP.DEFAULT_MSEARCH_MX)。

 1     ////////////////////////////////////////////////
 2     //    run    
 3     ////////////////////////////////////////////////
 4 
 5     public boolean start(String target, int mx)
 6     {
 7         stop(); 
 8         
 9         ////////////////////////////////////////
10         // HTTP Server
11         ////////////////////////////////////////
12         //开启http server 并且试着绑定端口,如果失败,将继续
13         int retryCnt = 0;
14         int bindPort = getHTTPPort();
15         HTTPServerList httpServerList = getHTTPServerList();
16         while (httpServerList.open(bindPort) == false) {
17             retryCnt++;
18             if (UPnP.SERVER_RETRY_COUNT < retryCnt)
19                 return false;
20             setHTTPPort(bindPort + 1);
21             bindPort = getHTTPPort();
22         }
23         httpServerList.addRequestListener(this);//设置响应监听
24         httpServerList.start();//启动响应监听
25         
26         ////////////////////////////////////////
27         // Notify Socket
28         ////////////////////////////////////////
29         //启动通知监听
30         SSDPNotifySocketList ssdpNotifySocketList = getSSDPNotifySocketList();
31         if (ssdpNotifySocketList.open() == false)
32             return false;
33         ssdpNotifySocketList.setControlPoint(this);            
34         ssdpNotifySocketList.start();
35         
36         ////////////////////////////////////////
37         // SeachResponse Socket
38         ////////////////////////////////////////
39         //启动搜索监听
40         int ssdpPort = getSSDPPort();
41         retryCnt = 0;
42         SSDPSearchResponseSocketList ssdpSearchResponseSocketList = getSSDPSearchResponseSocketList();
43         while (ssdpSearchResponseSocketList.open(ssdpPort) == false) {
44             retryCnt++;
45             if (UPnP.SERVER_RETRY_COUNT < retryCnt)
46                 return false;
47             setSSDPPort(ssdpPort + 1);
48             ssdpPort = getSSDPPort();
49         }
50         ssdpSearchResponseSocketList.setControlPoint(this);
51         ssdpSearchResponseSocketList.start();
52 
53         ////////////////////////////////////////
54         // search root devices
55         ////////////////////////////////////////
56         //搜索
57         search(target, mx);
58         
59         ////////////////////////////////////////
60         // Disposer
61         ////////////////////////////////////////
62     //过期device处理
63         Disposer disposer = new Disposer(this);
64         setDeviceDisposer(disposer);
65         disposer.start();
66                 
67         ////////////////////////////////////////
68         // Subscriber
69         ////////////////////////////////////////
70         //????
71         if (isNMPRMode() == true) {
72             RenewSubscriber renewSub = new RenewSubscriber(this);
73             setRenewSubscriber(renewSub);
74             renewSub.start();
75         }
76         
77         return true;
78     }

我们直接查看search接口:

1     public void search(String target, int mx)
2     {
3         SSDPSearchRequest msReq = new SSDPSearchRequest(target, mx);//设置搜索响应过滤条件
4         SSDPSearchResponseSocketList ssdpSearchResponseSocketList = getSSDPSearchResponseSocketList();
5         ssdpSearchResponseSocketList.post(msReq);
6     }

 

 查看SSDPSearchResponseSocketList.post

 1     ////////////////////////////////////////////////
 2     //    Methods
 3     ////////////////////////////////////////////////
 4 
 5     public boolean post(SSDPSearchRequest req)
 6     {
 7         boolean ret = true;
 8         int nSockets = size();
 9         for (int n=0; n<nSockets; n++) {
10             SSDPSearchResponseSocket sock = getSSDPSearchResponseSocket(n);
11             String bindAddr = sock.getLocalAddress();
12             req.setLocalAddress(bindAddr);
13             String ssdpAddr = SSDP.ADDRESS;
14             if (HostInterface.isIPv6Address(bindAddr) == true)
15                 ssdpAddr = SSDP.getIPv6Address();
16             //sock.joinGroup(ssdpAddr, SSDP.PORT, bindAddr);
17             if (sock.post(ssdpAddr, SSDP.PORT, req) == false)
18                 ret = false;
19             //sock.leaveGroup(ssdpAddr, SSDP.PORT, bindAddr);
20         }
21         return ret;
22     }

 

posted on 2012-07-04 17:58  J.evan  阅读(576)  评论(0编辑  收藏  举报