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 #pragma once 18 19 #include <sysutils/FrameworkCommand.h> 20 #include <sysutils/FrameworkListener.h> 21 22 #include "LogBuffer.h" 23 #include "LogListener.h" 24 #include "LogStatistics.h" 25 #include "LogTags.h" 26 #include "PruneList.h" 27 28 class CommandListener : public FrameworkListener { 29 public: 30 CommandListener(LogBuffer* buf, LogTags* tags, PruneList* prune, LogStatistics* log_statistics); ~CommandListener()31 virtual ~CommandListener() {} 32 33 private: 34 static int getLogSocket(); 35 36 LogBuffer* buf_; 37 LogTags* tags_; 38 PruneList* prune_; 39 LogStatistics* stats_; 40 41 #define LogCmd(name, command_string) \ 42 class name##Cmd : public FrameworkCommand { \ 43 public: \ 44 explicit name##Cmd(CommandListener* parent) \ 45 : FrameworkCommand(#command_string), parent_(parent) {} \ 46 virtual ~name##Cmd() {} \ 47 int runCommand(SocketClient* c, int argc, char** argv); \ 48 \ 49 private: \ 50 LogBuffer* buf() const { return parent_->buf_; } \ 51 LogTags* tags() const { return parent_->tags_; } \ 52 PruneList* prune() const { return parent_->prune_; } \ 53 LogStatistics* stats() const { return parent_->stats_; } \ 54 CommandListener* parent_; \ 55 } 56 57 LogCmd(Clear, clear); 58 LogCmd(GetBufSize, getLogSize); 59 LogCmd(SetBufSize, setLogSize); 60 LogCmd(GetBufSizeUsed, getLogSizeUsed); 61 LogCmd(GetStatistics, getStatistics); 62 LogCmd(GetPruneList, getPruneList); 63 LogCmd(SetPruneList, setPruneList); 64 LogCmd(GetEventTag, getEventTag); 65 LogCmd(Reinit, reinit); 66 LogCmd(Exit, EXIT); 67 #undef LogCmd 68 }; 69