OSDN Git Service

original
[gb-231r1-is01/Gingerbread_2.3.3_r1_IS01.git] / sdk / ddms / libs / ddmlib / src / com / android / ddmlib / HandleWait.java
1 /*
2  * Copyright (C) 2007 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 package com.android.ddmlib;
18
19 import com.android.ddmlib.ClientData.DebuggerStatus;
20
21 import java.io.IOException;
22 import java.nio.ByteBuffer;
23
24 /**
25  * Handle the "wait" chunk (WAIT).  These are sent up when the client is
26  * waiting for something, e.g. for a debugger to attach.
27  */
28 final class HandleWait extends ChunkHandler {
29
30     public static final int CHUNK_WAIT = ChunkHandler.type("WAIT");
31
32     private static final HandleWait mInst = new HandleWait();
33
34
35     private HandleWait() {}
36
37     /**
38      * Register for the packets we expect to get from the client.
39      */
40     public static void register(MonitorThread mt) {
41         mt.registerChunkHandler(CHUNK_WAIT, mInst);
42     }
43
44     /**
45      * Client is ready.
46      */
47     @Override
48     public void clientReady(Client client) throws IOException {}
49
50     /**
51      * Client went away.
52      */
53     @Override
54     public void clientDisconnected(Client client) {}
55
56     /**
57      * Chunk handler entry point.
58      */
59     @Override
60     public void handleChunk(Client client, int type, ByteBuffer data, boolean isReply, int msgId) {
61
62         Log.d("ddm-wait", "handling " + ChunkHandler.name(type));
63
64         if (type == CHUNK_WAIT) {
65             assert !isReply;
66             handleWAIT(client, data);
67         } else {
68             handleUnknownChunk(client, type, data, isReply, msgId);
69         }
70     }
71
72     /*
73      * Handle a reply to our WAIT message.
74      */
75     private static void handleWAIT(Client client, ByteBuffer data) {
76         byte reason;
77
78         reason = data.get();
79
80         Log.d("ddm-wait", "WAIT: reason=" + reason);
81
82
83         ClientData cd = client.getClientData();
84         synchronized (cd) {
85             cd.setDebuggerConnectionStatus(DebuggerStatus.WAITING);
86         }
87
88         client.update(Client.CHANGE_DEBUGGER_STATUS);
89     }
90 }
91