summaryrefslogtreecommitdiffstats
path: root/nexus/Controller.cpp
diff options
context:
space:
mode:
authorSan Mehat <san@google.com>2009-05-20 15:28:43 -0700
committerSan Mehat <san@google.com>2009-05-22 08:40:13 -0700
commit4876567cb9c6a69ce21fd2b1c5bcce5a6f274276 (patch)
treee08d76eed07e530884fb4e4d810a59ca4f017997 /nexus/Controller.cpp
parent463de48fb05cb29388e7763f75f6cfa56a2f5cb1 (diff)
downloadsystem_core-4876567cb9c6a69ce21fd2b1c5bcce5a6f274276.zip
system_core-4876567cb9c6a69ce21fd2b1c5bcce5a6f274276.tar.gz
system_core-4876567cb9c6a69ce21fd2b1c5bcce5a6f274276.tar.bz2
nexus: Switch controllers to use abstracted properties and refactor command protocol
Also fixes a select() bug and removes debugging Signed-off-by: San Mehat <san@google.com> nexus: fix whitespace
Diffstat (limited to 'nexus/Controller.cpp')
-rw-r--r--nexus/Controller.cpp71
1 files changed, 66 insertions, 5 deletions
diff --git a/nexus/Controller.cpp b/nexus/Controller.cpp
index cc1a187..133e796 100644
--- a/nexus/Controller.cpp
+++ b/nexus/Controller.cpp
@@ -14,6 +14,7 @@
* limitations under the License.
*/
#include <stdio.h>
+#include <stdlib.h>
#include <string.h>
#include <fcntl.h>
#include <unistd.h>
@@ -32,8 +33,13 @@
extern "C" int init_module(void *, unsigned int, const char *);
extern "C" int delete_module(const char *, unsigned int);
-Controller::Controller(const char *name) {
+Controller::Controller(const char *name, const char *prefix) {
mName = name;
+ mPropertyPrefix = prefix;
+ mProperties = new PropertyCollection();
+
+ mEnabled = false;
+ registerProperty("enable");
}
int Controller::start() {
@@ -44,12 +50,69 @@ int Controller::stop() {
return 0;
}
+const PropertyCollection & Controller::getProperties() {
+ return *mProperties;
+}
+
+int Controller::setProperty(const char *name, char *value) {
+ if (!strcmp(name, "enable")) {
+ int en = atoi(value);
+ int rc;
+
+ rc = (en ? enable() : disable());
+
+ if (!rc)
+ mEnabled = en;
+
+ return rc;
+ }
+
+ errno = ENOENT;
+ return -1;
+}
+
+const char *Controller::getProperty(const char *name, char *buffer, size_t maxsize) {
+ if (!strcmp(name, "enable")) {
+ snprintf(buffer, maxsize, "%d", mEnabled);
+ return buffer;
+ }
+
+ errno = ENOENT;
+ return NULL;
+}
+
+int Controller::registerProperty(const char *name) {
+ PropertyCollection::iterator it;
+
+ for (it = mProperties->begin(); it != mProperties->end(); ++it) {
+ if (!strcmp(name, (*it))) {
+ errno = EADDRINUSE;
+ LOGE("Failed to register property (%s)", strerror(errno));
+ return -1;
+ }
+ }
+
+ mProperties->push_back(name);
+ return 0;
+}
+
+int Controller::unregisterProperty(const char *name) {
+ PropertyCollection::iterator it;
+
+ for (it = mProperties->begin(); it != mProperties->end(); ++it) {
+ if (!strcmp(name, (*it))) {
+ mProperties->erase(it);
+ return 0;
+ }
+ }
+ errno = ENOENT;
+ return -1;
+}
+
int Controller::loadKernelModule(char *modpath, const char *args) {
void *module;
unsigned int size;
- LOGD("loadKernelModule(%s, %s)", modpath, args);
-
module = loadFile(modpath, &size);
if (!module) {
errno = -EIO;
@@ -65,7 +128,6 @@ int Controller::unloadKernelModule(const char *modtag) {
int rc = -1;
int retries = 10;
- LOGD("unloadKernelModule(%s)", modtag);
while (retries--) {
rc = delete_module(modtag, O_NONBLOCK | O_EXCL);
if (rc < 0 && errno == EAGAIN)
@@ -107,7 +169,6 @@ bool Controller::isKernelModuleLoaded(const char *modtag) {
return false;
}
-
void *Controller::loadFile(char *filename, unsigned int *_size)
{
int ret, fd;