• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "LogBuffer.h"
22 #include "LogCommand.h"
23 #include "LogListener.h"
24 #include "LogReader.h"
25 
26 // See main.cpp for implementation
27 void reinit_signal_handler(int /*signal*/);
28 
29 class CommandListener : public FrameworkListener {
30    public:
31     CommandListener(LogBuffer* buf, LogReader* reader, LogListener* swl);
~CommandListener()32     virtual ~CommandListener() {
33     }
34 
35    private:
36     static int getLogSocket();
37 
38     class ShutdownCmd : public LogCommand {
39         LogReader& mReader;
40         LogListener& mSwl;
41 
42        public:
43         ShutdownCmd(LogReader* reader, LogListener* swl);
~ShutdownCmd()44         virtual ~ShutdownCmd() {
45         }
46         int runCommand(SocketClient* c, int argc, char** argv);
47     };
48 
49 #define LogBufferCmd(name)                                      \
50     class name##Cmd : public LogCommand {                       \
51         LogBuffer& mBuf;                                        \
52                                                                 \
53        public:                                                  \
54         explicit name##Cmd(LogBuffer* buf);                     \
55         virtual ~name##Cmd() {                                  \
56         }                                                       \
57         int runCommand(SocketClient* c, int argc, char** argv); \
58     }
59 
60     LogBufferCmd(Clear);
61     LogBufferCmd(GetBufSize);
62     LogBufferCmd(SetBufSize);
63     LogBufferCmd(GetBufSizeUsed);
64     LogBufferCmd(GetStatistics);
65     LogBufferCmd(GetPruneList);
66     LogBufferCmd(SetPruneList);
67     LogBufferCmd(GetEventTag);
68 
69 #define LogCmd(name)                                            \
70     class name##Cmd : public LogCommand {                       \
71        public:                                                  \
72         name##Cmd();                                            \
73         virtual ~name##Cmd() {                                  \
74         }                                                       \
75         int runCommand(SocketClient* c, int argc, char** argv); \
76     }
77 
78     LogCmd(Reinit);
79 
80 #define LogParentCmd(name)                                      \
81     class name##Cmd : public LogCommand {                       \
82         CommandListener& mParent;                               \
83                                                                 \
84        public:                                                  \
85         name##Cmd();                                            \
86         explicit name##Cmd(CommandListener* parent);            \
87         virtual ~name##Cmd() {                                  \
88         }                                                       \
89         int runCommand(SocketClient* c, int argc, char** argv); \
90         void release(SocketClient* c) {                         \
91             mParent.release(c);                                 \
92         }                                                       \
93     }
94 
95     LogParentCmd(Exit);
96 };
97 
98 #endif
99