Mark Salyzyn | 12bac90 | 2014-02-26 09:50:16 -0800 | [diff] [blame] | 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> |
Mark Salyzyn | 12bac90 | 2014-02-26 09:50:16 -0800 | [diff] [blame] | 21 | #include "LogBuffer.h" |
Mark Salyzyn | 6505953 | 2017-03-10 14:31:54 -0800 | [diff] [blame] | 22 | #include "LogCommand.h" |
Mark Salyzyn | 12bac90 | 2014-02-26 09:50:16 -0800 | [diff] [blame] | 23 | #include "LogListener.h" |
Mark Salyzyn | 6505953 | 2017-03-10 14:31:54 -0800 | [diff] [blame] | 24 | #include "LogReader.h" |
Mark Salyzyn | 12bac90 | 2014-02-26 09:50:16 -0800 | [diff] [blame] | 25 | |
Mark Salyzyn | 3fe2593 | 2015-03-10 16:45:17 -0700 | [diff] [blame] | 26 | // See main.cpp for implementation |
| 27 | void reinit_signal_handler(int /*signal*/); |
| 28 | |
Mark Salyzyn | 12bac90 | 2014-02-26 09:50:16 -0800 | [diff] [blame] | 29 | class CommandListener : public FrameworkListener { |
Mark Salyzyn | 6505953 | 2017-03-10 14:31:54 -0800 | [diff] [blame] | 30 | public: |
| 31 | CommandListener(LogBuffer* buf, LogReader* reader, LogListener* swl); |
| 32 | virtual ~CommandListener() { |
| 33 | } |
Mark Salyzyn | 12bac90 | 2014-02-26 09:50:16 -0800 | [diff] [blame] | 34 | |
Mark Salyzyn | 6505953 | 2017-03-10 14:31:54 -0800 | [diff] [blame] | 35 | private: |
Mark Salyzyn | 3f6151e | 2014-03-24 10:26:47 -0700 | [diff] [blame] | 36 | static int getLogSocket(); |
| 37 | |
Mark Salyzyn | 12bac90 | 2014-02-26 09:50:16 -0800 | [diff] [blame] | 38 | class ShutdownCmd : public LogCommand { |
Mark Salyzyn | 6505953 | 2017-03-10 14:31:54 -0800 | [diff] [blame] | 39 | LogReader& mReader; |
| 40 | LogListener& mSwl; |
Mark Salyzyn | 12bac90 | 2014-02-26 09:50:16 -0800 | [diff] [blame] | 41 | |
Mark Salyzyn | 6505953 | 2017-03-10 14:31:54 -0800 | [diff] [blame] | 42 | public: |
| 43 | ShutdownCmd(LogReader* reader, LogListener* swl); |
| 44 | virtual ~ShutdownCmd() { |
| 45 | } |
| 46 | int runCommand(SocketClient* c, int argc, char** argv); |
Mark Salyzyn | 12bac90 | 2014-02-26 09:50:16 -0800 | [diff] [blame] | 47 | }; |
| 48 | |
Mark Salyzyn | 6505953 | 2017-03-10 14:31:54 -0800 | [diff] [blame] | 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); \ |
Mark Salyzyn | 4c60373 | 2016-09-08 13:16:59 -0700 | [diff] [blame] | 58 | } |
Mark Salyzyn | 12bac90 | 2014-02-26 09:50:16 -0800 | [diff] [blame] | 59 | |
Mark Salyzyn | 4c60373 | 2016-09-08 13:16:59 -0700 | [diff] [blame] | 60 | LogBufferCmd(Clear); |
| 61 | LogBufferCmd(GetBufSize); |
| 62 | LogBufferCmd(SetBufSize); |
| 63 | LogBufferCmd(GetBufSizeUsed); |
| 64 | LogBufferCmd(GetStatistics); |
| 65 | LogBufferCmd(GetPruneList); |
| 66 | LogBufferCmd(SetPruneList); |
Mark Salyzyn | 9472b4d | 2016-09-12 14:51:54 -0700 | [diff] [blame] | 67 | LogBufferCmd(GetEventTag); |
Mark Salyzyn | 3fe2593 | 2015-03-10 16:45:17 -0700 | [diff] [blame] | 68 | |
Mark Salyzyn | 6505953 | 2017-03-10 14:31:54 -0800 | [diff] [blame] | 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); \ |
Mark Salyzyn | 4c60373 | 2016-09-08 13:16:59 -0700 | [diff] [blame] | 76 | } |
| 77 | |
| 78 | LogCmd(Reinit); |
| 79 | |
Mark Salyzyn | 6505953 | 2017-03-10 14:31:54 -0800 | [diff] [blame] | 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 | } \ |
Mark Salyzyn | 4c60373 | 2016-09-08 13:16:59 -0700 | [diff] [blame] | 93 | } |
| 94 | |
| 95 | LogParentCmd(Exit); |
Mark Salyzyn | 12bac90 | 2014-02-26 09:50:16 -0800 | [diff] [blame] | 96 | }; |
| 97 | |
| 98 | #endif |