Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: jreceiver/client/rio/status/RioStatusRec.java


1   /* $Header: /cvsroot/jreceiver/jreceiver/src/jreceiver/client/rio/status/RioStatusRec.java,v 1.6 2002/12/29 00:44:09 reedesau Exp $ */
2   
3   package jreceiver.client.rio.status;
4   
5   import java.util.StringTokenizer;
6   
7   //import org.apache.commons.logging.*;
8   
9   import jreceiver.common.callback.rec.DeviceStatus;
10  import jreceiver.common.callback.rec.DeviceStatusRec;
11  import jreceiver.client.rio.RioLauncher;
12  import jreceiver.common.rec.source.Source;
13  import jreceiver.common.rec.source.SourceRec;
14  
15  /**
16   * Rio Status events will be produced when the Rio Status daemon
17   * hears a message from a Rio on the network.
18   * <p>
19   * Listeners will typically include the following devices
20   *   Servlet - which will display the status of all known Rio Servers on a webpage
21   * <p>
22   * The Rio Status Event will include
23   * <p>
24   *     MAC: 00:90:00:11:3f:ae
25   *     Playing: 111      (hexadecimal src_id)
26   *     State: Playing
27   *     Timecode: 27010   (milliseconds into song)
28   * <p>
29   * TODO: include the IP address of the receiver as well.
30   *
31   * @author Reed Esau
32   * @version $Revision: 1.6 $ $Date: 2002/12/29 00:44:09 $
33   */
34  public class RioStatusRec extends DeviceStatusRec {
35  
36      static final String prefix_mac = "MAC: ";
37      static final String prefix_titlecode = "Playing: ";
38      static final String prefix_state = "State: ";
39      static final String prefix_timecode = "Timecode: ";
40  
41      /**
42       * ctor -
43       */
44      public RioStatusRec(int device_id,
45                          int driver_id,
46                          String ip_address,
47                          long timestamp,
48                          String mac_address,
49                          int play_state,
50                          Source source,
51                          long timecode) {
52          super(device_id,
53                driver_id,
54                ip_address,
55                timestamp,
56                mac_address,
57                play_state,
58                source,
59                timecode);
60      }
61  
62      /**
63       * factory
64       */
65      public static RioStatusRec createInstance(int device_id,
66                                                String ip_address,
67                                                String msg) {
68  
69          String mac_address = "";
70          String state = "";
71          Source source = null;
72          long timecode = 0;
73          long timestamp = 0;
74  
75          StringTokenizer line_tokens = new StringTokenizer(msg, "\n\r");
76  
77          while (line_tokens.hasMoreTokens()) {
78              String line = line_tokens.nextToken();
79              if (line.startsWith(prefix_mac)) {
80                  mac_address = line.substring( prefix_mac.length() );
81              }
82              else if (line.startsWith(prefix_titlecode)) {
83                  String s = line.substring( prefix_titlecode.length() );
84                  try {
85                      int src_id = Integer.parseInt(s, 16/*hex*/);
86                      source = new SourceRec(src_id);              // return minimal source info
87                  }
88                  catch (NumberFormatException ignored) {
89                  }
90              }
91              else if (line.startsWith(prefix_state)) {
92                  state = line.substring( prefix_state.length() ).trim();
93              }
94              else if (line.startsWith(prefix_timecode)) {
95                  String s = line.substring( prefix_timecode.length() );
96                  try {
97                      //in milliseconds
98                      timecode = Long.parseLong(s);
99                      //log.debug("raw timecode=" + s + " parsed timecode=" + timecode);
100                 }
101                 catch (NumberFormatException ignored) {
102                 }
103             }
104         }
105 
106         int play_state;
107         if (state.equalsIgnoreCase("Playing"))
108             play_state = DeviceStatus.PLAY_STATE_PLAYING;
109         else if (state.equalsIgnoreCase("On"))
110             play_state = DeviceStatus.PLAY_STATE_PAUSED_OR_STOPPED;
111         else if (state.equalsIgnoreCase("Off"))
112             play_state = DeviceStatus.PLAY_STATE_OFF;
113         else
114             play_state = DeviceStatus.PLAY_STATE_UNKNOWN;
115 
116         return new RioStatusRec( device_id,
117                                  RioLauncher.getDriverId(),
118                                  ip_address,
119                                  timestamp,
120                                  mac_address,
121                                  play_state,
122                                  source,
123                                  timecode);
124     }
125 }
126 /*
127 JRECEIVER MODIFIED BSD LICENSE
128 
129 Copyright (c) 2001-2002, Reed Esau (reed.esau@pobox.com) All rights reserved.
130 
131 Redistribution and use in source and binary forms, with or without
132 modification, are permitted provided that the following conditions are
133 met:
134 
135 Redistributions of source code must retain the above copyright notice,
136 this list of conditions and the following disclaimer.
137 
138 Redistributions in binary form must reproduce the above copyright notice,
139 this list of conditions and the following disclaimer in the documentation
140 and/or other materials provided with the distribution.
141 
142 Neither the name of the JReceiver Project
143 (http://jreceiver.sourceforge.net) nor the names of its contributors may
144 be used to endorse or promote products derived from this software without
145 specific prior written permission.
146 
147 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
148 IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
149 THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
150 PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE
151 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
152 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
153 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
154 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
155 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
156 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
157 POSSIBILITY OF SUCH DAMAGE.
158 */
159