nexus: Use constants for errorcodes
Signed-off-by: San Mehat <san@google.com>
This commit is contained in:
parent
d530592848
commit
8d3fc3fde3
4 changed files with 62 additions and 33 deletions
|
@ -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 @@ int CommandListener::WifiEnableCmd::runCommand(SocketClient *cli, char *data) {
|
|||
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 @@ int CommandListener::WifiDisableCmd::runCommand(SocketClient *cli, char *data) {
|
|||
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 @@ int CommandListener::WifiScanCmd::runCommand(SocketClient *cli, char *data) {
|
|||
|
||||
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 @@ int CommandListener::WifiScanResultsCmd::runCommand(SocketClient *cli, char *dat
|
|||
}
|
||||
|
||||
delete src;
|
||||
cli->sendMsg(200, "Scan results complete", false);
|
||||
cli->sendMsg(ErrorCode::CommandOkay, "Scan results complete", false);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -139,9 +125,9 @@ int CommandListener::VpnEnableCmd::runCommand(SocketClient *cli, char *data) {
|
|||
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 @@ int CommandListener::VpnDisableCmd::runCommand(SocketClient *cli, char *data) {
|
|||
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;
|
||||
}
|
||||
|
|
40
nexus/ErrorCode.h
Normal file
40
nexus/ErrorCode.h
Normal file
|
@ -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
|
|
@ -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 @@ int Supplicant::stop() {
|
|||
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 @@ int Supplicant::onScanResultsEvent(SupplicantEvent *evt) {
|
|||
|
||||
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 {
|
||||
|
|
|
@ -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 @@ out_powerdown:
|
|||
}
|
||||
|
||||
void WifiController::sendStatusBroadcast(char *msg) {
|
||||
NetworkManager::Instance()->getBroadcaster()->sendBroadcast(600, msg, false);
|
||||
NetworkManager::Instance()->
|
||||
getBroadcaster()->
|
||||
sendBroadcast(ErrorCode::UnsolicitedInformational, msg, false);
|
||||
}
|
||||
|
||||
int WifiController::disable() {
|
||||
|
|
Loading…
Reference in a new issue