San Mehat | dc26607 | 2009-05-06 11:16:52 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2008 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 | #ifndef _CONTROLLER_H |
| 17 | #define _CONTROLLER_H |
| 18 | |
San Mehat | 4876567 | 2009-05-20 15:28:43 -0700 | [diff] [blame^] | 19 | #include <unistd.h> |
| 20 | #include <sys/types.h> |
| 21 | |
San Mehat | dc26607 | 2009-05-06 11:16:52 -0700 | [diff] [blame] | 22 | #include "../../../frameworks/base/include/utils/List.h" |
| 23 | |
San Mehat | 4876567 | 2009-05-20 15:28:43 -0700 | [diff] [blame^] | 24 | #include "PropertyCollection.h" |
| 25 | |
San Mehat | dc26607 | 2009-05-06 11:16:52 -0700 | [diff] [blame] | 26 | class Controller { |
| 27 | private: |
| 28 | const char *mName; |
San Mehat | 4876567 | 2009-05-20 15:28:43 -0700 | [diff] [blame^] | 29 | const char *mPropertyPrefix; |
| 30 | PropertyCollection *mProperties; |
| 31 | bool mEnabled; |
San Mehat | dc26607 | 2009-05-06 11:16:52 -0700 | [diff] [blame] | 32 | |
| 33 | public: |
San Mehat | 4876567 | 2009-05-20 15:28:43 -0700 | [diff] [blame^] | 34 | Controller(const char *name, const char *prefix); |
San Mehat | dc26607 | 2009-05-06 11:16:52 -0700 | [diff] [blame] | 35 | virtual ~Controller() {} |
| 36 | |
| 37 | virtual int start(); |
| 38 | virtual int stop(); |
| 39 | |
San Mehat | 4876567 | 2009-05-20 15:28:43 -0700 | [diff] [blame^] | 40 | virtual const PropertyCollection &getProperties(); |
| 41 | virtual int setProperty(const char *name, char *value); |
| 42 | virtual const char *getProperty(const char *name, char *buffer, size_t maxsize); |
San Mehat | dc26607 | 2009-05-06 11:16:52 -0700 | [diff] [blame] | 43 | |
San Mehat | 4876567 | 2009-05-20 15:28:43 -0700 | [diff] [blame^] | 44 | const char *getName() { return mName; } |
| 45 | const char *getPropertyPrefix() { return mPropertyPrefix; } |
San Mehat | dc26607 | 2009-05-06 11:16:52 -0700 | [diff] [blame] | 46 | |
| 47 | protected: |
| 48 | int loadKernelModule(char *modpath, const char *args); |
| 49 | bool isKernelModuleLoaded(const char *modtag); |
| 50 | int unloadKernelModule(const char *modtag); |
| 51 | |
San Mehat | 4876567 | 2009-05-20 15:28:43 -0700 | [diff] [blame^] | 52 | int registerProperty(const char *name); |
| 53 | int unregisterProperty(const char *name); |
| 54 | |
San Mehat | dc26607 | 2009-05-06 11:16:52 -0700 | [diff] [blame] | 55 | private: |
| 56 | void *loadFile(char *filename, unsigned int *_size); |
San Mehat | 4876567 | 2009-05-20 15:28:43 -0700 | [diff] [blame^] | 57 | |
| 58 | virtual int enable() = 0; |
| 59 | virtual int disable() = 0; |
| 60 | |
San Mehat | dc26607 | 2009-05-06 11:16:52 -0700 | [diff] [blame] | 61 | }; |
| 62 | |
| 63 | typedef android::List<Controller *> ControllerCollection; |
| 64 | #endif |