Source code: com/synchrona/jred/irlap/IrLAPStateQuery.java
1 /*
2 **************************************************************************
3 ** $Header: /cvsroot/jred/jred/src/com/synchrona/jred/irlap/IrLAPStateQuery.java,v 1.2 2000/07/30 20:18:12 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.Assert;
21 import com.synchrona.util.Log;
22 import java.io.PrintWriter;
23
24 class IrLAPStateQuery extends IrLAPState {
25 private Log _log;
26
27 //--------------------------------------------------------------------
28 // Static stuff
29 //--------------------------------------------------------------------
30
31 // You'll want to do this in each subclass of IrLAPState to
32 // create a single instance of that subclass.
33 private static IrLAPState s_instance = new IrLAPStateQuery();
34
35 // Will late binding make sure we get the correct instance? Need
36 // to test this (see IrLAPStateNDM). It may be compiler-dependent.
37 public static IrLAPState getInstance() {
38 return s_instance;
39 }
40
41 public void handleSlotTimerExpired(IrLAPContext context) throws Exception {
42 logIfEnabled("slot-timer-expired");
43
44 if ( context.getSlotCount() < 6 ) {
45 context.setSlotCount((byte) (context.getSlotCount() + 1));
46 } else {
47 context.setSlotCount((byte) 0xFF);
48 context.setMediaBusy(false);
49 context.nextState(IrLAPStateNDM.getInstance());
50 }
51 context.sendDiscoveryRequest();
52 context.startSlotTimer();
53 }
54
55 public void handleXID(IrLAPContext context, int nSource, int nDestination, byte ySlot, boolean bCommand, byte [] ayHints) throws Exception {
56 Assert.fail(null != context, "IrLAPContext is null.");
57 Assert.fail(null != ayHints, "Service hints are null.");
58
59 logIfEnabled("XID (empty) [source=" + nSource
60 + " destination=" + nDestination
61 + " slot=" + ySlot
62 + " command?=" + bCommand + "]");
63
64 System.err.println("(IrLAPStateQuery.handleXID) creating service hints");
65 ServiceHints hints = new ServiceHints(ayHints, 0, ayHints.length);
66
67 System.err.println("(IrLAPStateQuery.handleXID) creating discovery info");
68 DiscoveryInformation discoveryInfo = new DiscoveryInformation(nSource, hints);
69
70 System.err.println("(IrLAPStateQuery.handleXID) sending discoveryIndication");
71 context.discoveryIndication(discoveryInfo);
72 System.err.println("(IrLAPStateQuery.handleXID) finished sending discoveryIndication");
73 }
74
75 //--------------------------------------------------------------------
76 // End of event handlers, start of support stuff
77 //--------------------------------------------------------------------
78
79 public void debug(String strCategory, String strMessage) {
80 _log.debug(strCategory, strMessage);
81 }
82
83 public void setLog(Log log) {
84 _log = log;
85 }
86
87 public void setLog(PrintWriter log) {
88 }
89
90 public void setLogging(boolean bDoLogging) {
91 }
92
93 //--------------------------------------------------------------------
94 // End of public methods, start protected methdods
95 //--------------------------------------------------------------------
96
97 protected void logIfEnabled(String strMessage) throws Exception {
98 }
99
100 //--------------------------------------------------------------------
101 // End of protected methods, start private methods
102 //--------------------------------------------------------------------
103
104 protected IrLAPStateQuery() {
105 _log = null;
106 }
107
108 }