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
17package com.android.ddmlib;
18
19import java.io.IOException;
20import java.nio.ByteBuffer;
21
22/**
23 * Submit an exit request.
24 */
25final class HandleExit extends ChunkHandler {
26
27    public static final int CHUNK_EXIT = type("EXIT");
28
29    private static final HandleExit mInst = new HandleExit();
30
31
32    private HandleExit() {}
33
34    /**
35     * Register for the packets we expect to get from the client.
36     */
37    public static void register(MonitorThread mt) {}
38
39    /**
40     * Client is ready.
41     */
42    @Override
43    public void clientReady(Client client) throws IOException {}
44
45    /**
46     * Client went away.
47     */
48    @Override
49    public void clientDisconnected(Client client) {}
50
51    /**
52     * Chunk handler entry point.
53     */
54    @Override
55    public void handleChunk(Client client, int type, ByteBuffer data, boolean isReply, int msgId) {
56        handleUnknownChunk(client, type, data, isReply, msgId);
57    }
58
59    /**
60     * Send an EXIT request to the client.
61     */
62    public static void sendEXIT(Client client, int status)
63        throws IOException
64    {
65        ByteBuffer rawBuf = allocBuffer(4);
66        JdwpPacket packet = new JdwpPacket(rawBuf);
67        ByteBuffer buf = getChunkDataBuf(rawBuf);
68
69        buf.putInt(status);
70
71        finishChunkPacket(packet, CHUNK_EXIT, buf.position());
72        Log.d("ddm-exit", "Sending " + name(CHUNK_EXIT) + ": " + status);
73        client.sendAndConsume(packet, mInst);
74    }
75}
76
77