nexus: Use constants for errorcodes

Signed-off-by: San Mehat <san@google.com>
diff --git a/nexus/CommandListener.cpp b/nexus/CommandListener.cpp
index e9a358c..5967550 100644
--- a/nexus/CommandListener.cpp
+++ b/nexus/CommandListener.cpp
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2008 The Android Open Source Project
+ * Copyright (C) ErrorCode::CommandOkay8 The Android Open Source Project
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -25,6 +25,7 @@
 #include "Controller.h"
 #include "NetworkManager.h"
 #include "WifiController.h"
+#include "ErrorCode.h"
 
 CommandListener::CommandListener() :
                  FrameworkListener("nexus") {
@@ -49,9 +50,9 @@
     Controller *c = NetworkManager::Instance()->findController("WIFI");
 
     if (c->enable())
-        cli->sendMsg(400, "Failed to enable wifi", true);
+        cli->sendMsg(ErrorCode::OperationFailed, "Failed to enable wifi", true);
     else
-        cli->sendMsg(200, "Wifi Enabled", false);
+        cli->sendMsg(ErrorCode::CommandOkay, "Wifi Enabled", false);
     return 0;
 }
 
@@ -63,9 +64,9 @@
     Controller *c = NetworkManager::Instance()->findController("WIFI");
 
     if (c->disable())
-        cli->sendMsg(400, "Failed to disable wifi", true);
+        cli->sendMsg(ErrorCode::OperationFailed, "Failed to disable wifi", true);
     else
-        cli->sendMsg(200, "Wifi Disabled", false);
+        cli->sendMsg(ErrorCode::CommandOkay, "Wifi Disabled", false);
     return 0;
 }
 
@@ -78,25 +79,10 @@
 
     WifiController *wc = (WifiController *) NetworkManager::Instance()->findController("WIFI");
 
-    int mode = 0;
-    char *bword, *last;
-
-    if (!(bword = strtok_r(data, ":", &last))) {
-        errno = EINVAL;
-        return -1;
-    }
-
-    if (!(bword = strtok_r(NULL, ":", &last))) {
-        errno = EINVAL;
-        return -1;
-    }
-
-    mode = atoi(bword);
-
-    if (wc->setScanMode(mode))
-        cli->sendMsg(400, "Failed to set scan mode", true);
+    if (wc->setScanMode(atoi(data)))
+        cli->sendMsg(ErrorCode::OperationFailed, "Failed to set scan mode", true);
     else
-        cli->sendMsg(200, "Scan mode set", false);
+        cli->sendMsg(ErrorCode::CommandOkay, "Scan mode set", false);
 
     return 0;
 }
@@ -124,7 +110,7 @@
     }
 
     delete src;
-    cli->sendMsg(200, "Scan results complete", false);
+    cli->sendMsg(ErrorCode::CommandOkay, "Scan results complete", false);
     return 0;
 }
 
@@ -139,9 +125,9 @@
     Controller *c = NetworkManager::Instance()->findController("VPN");
 
     if (c->enable())
-        cli->sendMsg(400, "Failed to enable VPN", true);
+        cli->sendMsg(ErrorCode::OperationFailed, "Failed to enable VPN", true);
     else
-        cli->sendMsg(200, "VPN enabled", false);
+        cli->sendMsg(ErrorCode::CommandOkay, "VPN enabled", false);
     return 0;
 }
 
@@ -153,8 +139,8 @@
     Controller *c = NetworkManager::Instance()->findController("VPN");
 
     if (c->disable())
-        cli->sendMsg(400, "Failed to disable VPN", true);
+        cli->sendMsg(ErrorCode::OperationFailed, "Failed to disable VPN", true);
     else
-        cli->sendMsg(200, "VPN disabled", false);
+        cli->sendMsg(ErrorCode::CommandOkay, "VPN disabled", false);
     return 0;
 }
diff --git a/nexus/ErrorCode.h b/nexus/ErrorCode.h
new file mode 100644
index 0000000..dd2ea3b
--- /dev/null
+++ b/nexus/ErrorCode.h
@@ -0,0 +1,40 @@
+/*
+ * Copyright (C) 2008 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef _ERRORCODE_H
+#define _ERRORCODE_H
+
+class ErrorCode {
+public:
+    // 100 series - Requestion action was initiated; expect another reply
+    // before proceeding with a new command.
+    static const int ActionInitiated = 100;
+
+    // 200 series - Requested action has been successfully completed
+    static const int CommandOkay = 200;
+
+    // 400 series - The command was accepted but the requested action
+    // did not take place.
+    static const int OperationFailed = 400;
+
+    // 500 series - The command was not accepted and the requested
+    // action did not take place.
+    static const int CommandSyntaxError = 500;
+
+    // 600 series - Unsolicited broadcasts
+    static const int UnsolicitedInformational = 600;
+};
+#endif
diff --git a/nexus/Supplicant.cpp b/nexus/Supplicant.cpp
index 63ab503..fd56128 100644
--- a/nexus/Supplicant.cpp
+++ b/nexus/Supplicant.cpp
@@ -38,6 +38,7 @@
 #include "SupplicantEvent.h"
 #include "ScanResult.h"
 #include "NetworkManager.h"
+#include "ErrorCode.h"
 
 #include "libwpa_client/wpa_ctrl.h"
 
@@ -173,9 +174,7 @@
 bool Supplicant::isStarted() {
     char supp_status[PROPERTY_VALUE_MAX] = {'\0'};
 
-    int rc = property_get(SUPP_PROP_NAME, supp_status, NULL);
-
-    LOGD("rc = %d, property = '%s'", rc, supp_status);
+    property_get(SUPP_PROP_NAME, supp_status, NULL);
 
     if (!strcmp(supp_status, "running"))
         return true;
@@ -359,7 +358,8 @@
     
         char tmp[128];
         sprintf(tmp, "%d scan results ready", mLatestScanResults->size());
-        NetworkManager::Instance()->getBroadcaster()->sendBroadcast(600, tmp, false);
+        NetworkManager::Instance()->getBroadcaster()->
+                                    sendBroadcast(ErrorCode::UnsolicitedInformational, tmp, false);
         pthread_mutex_unlock(&mLatestScanResultsLock);
         free(reply);
     } else {
diff --git a/nexus/WifiController.cpp b/nexus/WifiController.cpp
index cba00ec..66c5378 100644
--- a/nexus/WifiController.cpp
+++ b/nexus/WifiController.cpp
@@ -23,6 +23,7 @@
 #include "WifiController.h"
 #include "WifiScanner.h"
 #include "NetworkManager.h"
+#include "ErrorCode.h";
 
 WifiController::WifiController(char *modpath, char *modname, char *modargs) :
                 Controller("WIFI") {
@@ -94,7 +95,9 @@
 }
 
 void WifiController::sendStatusBroadcast(char *msg) {
-    NetworkManager::Instance()->getBroadcaster()->sendBroadcast(600, msg, false);
+    NetworkManager::Instance()->
+                    getBroadcaster()->
+                    sendBroadcast(ErrorCode::UnsolicitedInformational, msg, false);
 }
 
 int WifiController::disable() {