View Javadoc

1   /**
2    *  BlueCove - Java library for Bluetooth
3    *  Copyright (C) 2006-2008 Vlad Skarzhevskyy
4    * 
5    *  Licensed to the Apache Software Foundation (ASF) under one
6    *  or more contributor license agreements.  See the NOTICE file
7    *  distributed with this work for additional information
8    *  regarding copyright ownership.  The ASF licenses this file
9    *  to you under the Apache License, Version 2.0 (the
10   *  "License"); you may not use this file except in compliance
11   *  with the License.  You may obtain a copy of the License at
12   *
13   *    http://www.apache.org/licenses/LICENSE-2.0
14   *
15   *  Unless required by applicable law or agreed to in writing,
16   *  software distributed under the License is distributed on an
17   *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
18   *  KIND, either express or implied.  See the License for the
19   *  specific language governing permissions and limitations
20   *  under the License.
21   *
22   *  @author vlads
23   *  @version $Id: Console.java 2607 2008-12-17 23:51:33Z skarzhevskyy $
24   */
25  package net.sf.bluecove.se;
26  
27  import java.io.IOException;
28  
29  import org.bluecove.tester.log.Logger;
30  
31  import net.sf.bluecove.Configuration;
32  import net.sf.bluecove.Switcher;
33  
34  /**
35   * 
36   */
37  public class Console {
38  
39  	public static void main(String[] args) {
40  		JavaSECommon.initOnce();
41  		Configuration.storage = new FileStorage();
42  		help();
43  
44  		while (true) {
45  			try {
46  				String cmd = readCommand();
47  				if (cmd == null) {
48  					quit();
49  					return;
50  				}
51  				if (cmd.length() == 0) {
52  					help();
53  					continue;
54  				}
55  				cmd = cmd.toUpperCase();
56  				char user_input = cmd.charAt(0);
57  				switch (user_input) {
58  				case 'Q':
59  					quit();
60  					break;
61  				case '\n':
62  				case '?':
63  				case 'H':
64  					help();
65  					break;
66  				case '4':
67  					UIHelper.printFailureLog();
68  					break;
69  				case '*':
70  					Switcher.startDiscovery();
71  					break;
72  				case '7':
73  					Switcher.startServicesSearch();
74  					break;
75  				case '2':
76  					Switcher.startClient();
77  					break;
78  				case '3':
79  					Switcher.clientShutdown();
80  					break;
81  				case '5':
82  					Switcher.startServer();
83  					break;
84  				case '6':
85  					Switcher.serverShutdown();
86  					break;
87  				case 'D':
88  					boolean dbg = BlueCoveSpecific.changeDebug();
89  					if (dbg) {
90  						System.out.println("BlueCove Debug ON");
91  					} else {
92  						System.out.println("BlueCove Debug OFF");
93  					}
94  					break;
95  				case 'T':
96  				    Switcher.startTCKAgent();
97  				    break;
98  				}
99  			} catch (IOException e) {
100 				return;
101 			}
102 		}
103 	}
104 
105 	private static String readCommand() throws IOException {
106 		int b = System.in.read();
107 		if (b == -1) {
108 			return null;
109 		}
110 		return new String("" + (char) b);
111 	}
112 
113 	private static void help() {
114 		System.out.println("BlueCove tester Console application (keyboard codes the same as in MIDP application)");
115 		System.out.println("\t2 - Start Client");
116 		System.out.println("\t3 - Stop Client");
117 		System.out.println("\t5 - Start Server");
118 		System.out.println("\t6 - Stop Server");
119 		System.out.println("\t* - Run Discovery");
120 		System.out.println("\t7 - Services Search");
121 		System.out.println("\td - toggle BlueCove Debug");
122 		System.out.println("\tT - Start TCK Agent");
123 		System.out.println("\tq - Quit");
124 		System.out.flush();
125 	}
126 
127 	private static void quit() {
128 		Logger.debug("quit");
129 		Switcher.clientShutdown();
130 		Switcher.serverShutdownOnExit();
131 		System.exit(0);
132 	}
133 }