1 /* 2 * Copyright 2018, 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 "../result.h" 20 21 // An interface for commands coming through the pipe. Note that each instance 22 // can handle any number of commands, all it has to do is differentiate based 23 // on the incoming command string or arguments. It will have to be registered 24 // multiple times, once for each command though. 25 class Command { 26 public: 27 virtual ~Command() = default; 28 29 // Work to perform when a command is received. The result will be used to 30 // report the result to the user. If the result indicates success the user 31 // will see an "OK" response, on failure the error message in the result 32 // will be presented to the user. This means that the result error string 33 // should be fairly user-friendly. 34 virtual Result onCommand(const char* command, const char* args) = 0; 35 36 }; 37 38