CommandListener.h revision 51a29c8dc445e4fb89860561933e54a231e6ffb4
1/*
2 * Copyright (C) 2012-2014 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#ifndef _COMMANDLISTENER_H__
18#define _COMMANDLISTENER_H__
19
20#include <sysutils/FrameworkListener.h>
21#include "LogCommand.h"
22#include "LogBuffer.h"
23#include "LogReader.h"
24#include "LogListener.h"
25
26class CommandListener : public FrameworkListener {
27    LogBuffer &mBuf;
28
29public:
30    CommandListener(LogBuffer *buf, LogReader *reader, LogListener *swl);
31    virtual ~CommandListener() {}
32
33private:
34    class ShutdownCmd : public LogCommand {
35        LogBuffer &mBuf;
36        LogReader &mReader;
37        LogListener &mSwl;
38
39    public:
40        ShutdownCmd(LogBuffer *buf, LogReader *reader, LogListener *swl);
41        virtual ~ShutdownCmd() {}
42        int runCommand(SocketClient *c, int argc, char ** argv);
43    };
44
45#define LogBufferCmd(name)                                       \
46    class name##Cmd : public LogCommand {                        \
47        LogBuffer &mBuf;                                         \
48    public:                                                      \
49        name##Cmd(LogBuffer *buf);                               \
50        virtual ~name##Cmd() {}                                  \
51        int runCommand(SocketClient *c, int argc, char ** argv); \
52    };
53
54    LogBufferCmd(Clear)
55    LogBufferCmd(GetBufSize)
56    LogBufferCmd(GetBufSizeUsed)
57    LogBufferCmd(GetStatistics)
58};
59
60#endif
61