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

Quick Search    Search Deep

Source code: com/synchrona/jred/irlap/IrLAPState.java


1   /*
2   **************************************************************************
3   ** $Header: /cvsroot/jred/jred/src/com/synchrona/jred/irlap/IrLAPState.java,v 1.1.1.1 2000/07/05 04:41:52 mpatters Exp $
4   **
5   ** Copyright (C) 2000 Synchrona, Inc. All rights reserved.
6   **
7   ** This file is part of JRed, a 100% Java implementation of the IrDA
8   ** infrared communications protocols.
9   **
10  ** This file may be distributed under the terms of the Synchrona Public
11  ** License as defined by Synchrona, Inc. and appearing in the file
12  ** LICENSE included in the packaging of this file. The Synchrona Public
13  ** License is based on the Q Public License as defined by Troll Tech AS
14  ** of Norway; it differs only in its use of the courts of Florida, USA
15  ** rather than those of Oslo, Norway.
16  **************************************************************************
17  */
18  package com.synchrona.jred.irlap;
19  
20  import com.synchrona.util.Log;
21  import java.io.PrintWriter;
22  
23  /**
24   * IrLAPState is a base class for all of the IrLAP states. You shouldn't
25   * use this in production, but it provides stub implementations of the
26   * event handlers so you can see what's going on (or at least get some
27   * indication when something that you aren't expecting happens).
28   * <p>
29   * IrLAPState is part of the implementation of the ObjectsAsStates pattern,
30   * which can be found in the Gang of Four book. IrLAPContext provides access
31   * to variables that are shared by all states, as well as methods to change
32   * state and respond to events.
33   * <p>
34   * IrLAPState also implements the Singleton pattern. There is at most one
35   * instance of each subclass of IrLAPState.
36   */
37  class IrLAPState {
38    protected Log m_log;         // log stream
39  
40    //--------------------------------------------------------------------
41    // Static stuff
42    //--------------------------------------------------------------------
43  
44    // You'll want to do this in each subclass of IrLAPState to 
45    // create a single instance of that subclass.
46    private static IrLAPState s_instance = new IrLAPState();
47  
48    // Will late binding make sure we get the correct instance? Need
49    // to test this (see IrLAPStateNDM). It may be compiler-dependent.
50    public static IrLAPState getInstance() {
51      return s_instance;
52    }
53  
54    //--------------------------------------------------------------------
55    // Start event handlers. These are the things you'll want to modify as
56    // you implement new IrLAP states or change the behavior of existing
57    // ones. The names suck but they're based on the IrLAP specification;
58    // it's kind of hard to check compliance if you have to keep translating
59    // from their terse names to more meaningful ones.
60    //--------------------------------------------------------------------
61  
62    public void connectResponse(IrLAPContext context, int nDestination, byte yConnection, byte [] ayParameters) throws Exception {
63      logIfEnabled("connectionRequest (empty)");
64    }
65  
66    public void discoveryRequest(IrLAPContext context) throws Exception {
67      logIfEnabled("discoveryRequest (empty)");
68    }
69  
70    /**
71     * Somebody has sent us data.
72     */
73    public void handleData(IrLAPContext context, byte yConnection, int nNr, boolean bCommand, boolean bPoll, byte [] ayData) throws Exception {
74      logIfEnabled("data (empty)");
75    }
76  
77    /**
78     * An IrLAP service user wants to send data to an IrLAP client.
79     */
80    public void handleDataRequest(IrLAPContext context, byte ayData, int nOffset, int nLength) throws Exception {
81      logIfEnabled("data-request (empty)");
82    }
83  
84    public void handleDisconnect(IrLAPContext context, int nSource, byte yConnection) throws Exception {
85      logIfEnabled("DISC (empty)");
86    }
87  
88    public void handleFTimerExpired(IrLAPContext context) throws Exception {
89      logIfEnabled("F-timer-expired (empty)");
90    }
91  
92    public void handlePTimerExpired(IrLAPContext context) throws Exception {
93      logIfEnabled("P-timer-expired (empty)");
94    }
95  
96    public void handleQueryTimerExpired(IrLAPContext context) throws Exception {
97      logIfEnabled("query-timer-expired (empty)");
98    }
99  
100   public void handleRR(IrLAPContext context, byte yConnection, int nNr, boolean bCommand, boolean bPoll) throws Exception {
101     logIfEnabled("RR (empty)");
102   }
103 
104   public void handleSNRM(IrLAPContext context, int nSource, int nDestination, byte yConnection, byte [] ayParameters) throws Exception {
105     logIfEnabled("SNRM (empty) source=" + nSource + " destination=" + nDestination + " connection=" + yConnection);
106   }
107 
108   public void handleUA(IrLAPContext context, byte [] ayParams, int nOffset, int nLength) throws Exception {
109     logIfEnabled("UA (empty)");
110   }
111 
112   public void handleWatchdogTimerExpired(IrLAPContext context) throws Exception {
113     logIfEnabled("WD-timer-expired (empty)");
114   }
115 
116   public void handleXID(IrLAPContext context, int nSource, int nDestination, byte ySlot, boolean bCommand, byte [] ayHints) throws Exception {
117     logIfEnabled("XID (empty) [source=" + nSource + " destination=" + nDestination + " slot=" + ySlot + " command?=" + bCommand + "]");
118   }
119 
120   //--------------------------------------------------------------------
121   // End of event handlers, start of support stuff
122   //--------------------------------------------------------------------
123 
124   public void debug(String strCategory, String strMessage) {
125     m_log.debug(strCategory, strMessage);
126   }
127 
128   public void setLog(Log log) {
129     m_log = log;
130   }
131 
132   public void setLog(PrintWriter log) {
133   }
134 
135   public void setLogging(boolean bDoLogging) {
136   }
137 
138   //--------------------------------------------------------------------
139   // End of public methods, start protected methdods
140   //--------------------------------------------------------------------
141 
142   protected void logIfEnabled(String strMessage) throws Exception {
143   }
144 
145   //--------------------------------------------------------------------
146   // End of protected methods, start private methods
147   //--------------------------------------------------------------------
148 
149   protected IrLAPState() {
150     m_log        = null;
151   }
152 
153 }