• R/O
  • HTTP
  • SSH
  • HTTPS

コミット

タグ
未設定

よく使われているワード(クリックで追加)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

system/corennnnn


コミットメタ情報

リビジョン192331d9060763b92f7989124bedbd136689d735 (tree)
日時2009-05-30 07:26:00
作者San Mehat <san@goog...>
コミッターSan Mehat

ログメッセージ

nexus: Add ListCmd to CommandListener

Signed-off-by: San Mehat <san@google.com>

nexus: Add InterfaceConfig and flesh out some more flow

Signed-off-by: San Mehat <san@google.com>

変更サマリ

差分

--- a/nexus/Android.mk
+++ b/nexus/Android.mk
@@ -22,6 +22,7 @@ LOCAL_SRC_FILES:= \
2222 WifiScanner.cpp \
2323 WifiNetwork.cpp \
2424 OpenVpnController.cpp \
25+ InterfaceConfig.cpp \
2526
2627 LOCAL_MODULE:= nexus
2728
--- a/nexus/CommandListener.cpp
+++ b/nexus/CommandListener.cpp
@@ -202,3 +202,11 @@ out_inval:
202202 cli->sendMsg(ErrorCode::CommandParameterError, "Failed to set property.", true);
203203 return 0;
204204 }
205+
206+CommandListener::ListCmd::ListCmd() :
207+ NexusCommand("list") {
208+}
209+
210+int CommandListener::ListCmd::runCommand(SocketClient *cli, char *data) {
211+ return 0;
212+}
--- a/nexus/CommandListener.h
+++ b/nexus/CommandListener.h
@@ -74,6 +74,13 @@ private:
7474 virtual ~GetCmd() {}
7575 int runCommand(SocketClient *c, char *data);
7676 };
77+
78+ class ListCmd : public NexusCommand {
79+ public:
80+ ListCmd();
81+ virtual ~ListCmd() {}
82+ int runCommand(SocketClient *c, char *data);
83+ };
7784 };
7885
7986 #endif
--- /dev/null
+++ b/nexus/InterfaceConfig.cpp
@@ -0,0 +1,67 @@
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+
17+#include <string.h>
18+
19+#define LOG_TAG "InterfaceConfig"
20+#include <cutils/log.h>
21+
22+#include "InterfaceConfig.h"
23+
24+InterfaceConfig::InterfaceConfig(const char *name) {
25+ mName = strdup(name);
26+ mUseDhcp = true;
27+}
28+
29+InterfaceConfig::~InterfaceConfig() {
30+ free(mName);
31+}
32+
33+InterfaceConfig::InterfaceConfig(const char *name, const char *ip, const char *nm,
34+ const char *gw, const char *dns1, const char *dns2,
35+ const char *dns3) {
36+ mName = strdup(name);
37+ mUseDhcp = false;
38+
39+ if (!inet_aton(ip, &mIp))
40+ LOGW("Unable to parse ip (%s)", ip);
41+ if (!inet_aton(nm, &mIp))
42+ LOGW("Unable to parse netmask (%s)", nm);
43+ if (!inet_aton(gw, &mIp))
44+ LOGW("Unable to parse gateway (%s)", gw);
45+ if (!inet_aton(dns1, &mIp))
46+ LOGW("Unable to parse dns1 (%s)", dns1);
47+ if (!inet_aton(dns2, &mIp))
48+ LOGW("Unable to parse dns2 (%s)", dns2);
49+ if (!inet_aton(dns3, &mIp))
50+ LOGW("Unable to parse dns3 (%s)", dns3);
51+}
52+
53+InterfaceConfig::InterfaceConfig(const char *name, const struct in_addr *ip,
54+ const struct in_addr *nm, const struct in_addr *gw,
55+ const struct in_addr *dns1, const struct in_addr *dns2,
56+ const struct in_addr *dns3) {
57+ mName = strdup(name);
58+ mUseDhcp = false;
59+
60+ memcpy(&mIp, ip, sizeof(struct in_addr));
61+ memcpy(&mNetmask, nm, sizeof(struct in_addr));
62+ memcpy(&mGateway, gw, sizeof(struct in_addr));
63+ memcpy(&mDns1, dns1, sizeof(struct in_addr));
64+ memcpy(&mDns2, dns2, sizeof(struct in_addr));
65+ memcpy(&mDns3, dns3, sizeof(struct in_addr));
66+}
67+
--- /dev/null
+++ b/nexus/InterfaceConfig.h
@@ -0,0 +1,58 @@
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+
17+#ifndef _INTERFACE_CONFIG_H
18+#define _INTERFACE_CONFIG_H
19+
20+#include <netinet/in.h>
21+#include <arpa/inet.h>
22+
23+class InterfaceConfig {
24+private:
25+ char *mName;
26+ bool mUseDhcp;
27+ struct in_addr mIp;
28+ struct in_addr mNetmask;
29+ struct in_addr mGateway;
30+ struct in_addr mDns1;
31+ struct in_addr mDns2;
32+ struct in_addr mDns3;
33+
34+public:
35+ InterfaceConfig(const char *name);
36+ InterfaceConfig(const char *name, const char *ip, const char *nm,
37+ const char *gw, const char *dns1, const char *dns2,
38+ const char *dns3);
39+
40+ InterfaceConfig(const char *name, const struct in_addr *ip,
41+ const struct in_addr *nm, const struct in_addr *gw,
42+ const struct in_addr *dns1, const struct in_addr *dns2,
43+ const struct in_addr *dns3);
44+
45+ virtual ~InterfaceConfig();
46+
47+ const char *getName() const { return mName; }
48+ bool getUseDhcp() const { return mUseDhcp; }
49+ const struct in_addr &getIp() const { return mIp; }
50+ const struct in_addr &getNetmask() const { return mNetmask; }
51+ const struct in_addr &getGateway() const { return mGateway; }
52+ const struct in_addr &getDns1() const { return mDns1; }
53+ const struct in_addr &getDns2() const { return mDns2; }
54+ const struct in_addr &getDns3() const { return mDns3; }
55+};
56+
57+
58+#endif
--- a/nexus/NetworkManager.cpp
+++ b/nexus/NetworkManager.cpp
@@ -21,6 +21,7 @@
2121 #include <cutils/log.h>
2222
2323 #include "NetworkManager.h"
24+#include "InterfaceConfig.h"
2425
2526 NetworkManager *NetworkManager::sInstance = NULL;
2627
@@ -150,12 +151,23 @@ const PropertyCollection &NetworkManager::getProperties() {
150151 return *mProperties;
151152 }
152153
153-int NetworkManager::onInterfaceCreated(Controller *c, char *name) {
154- LOGD("Interface %s created by controller %s", name, c->getName());
154+int NetworkManager::onInterfaceStart(Controller *c, const InterfaceConfig *cfg) {
155+ LOGD("Interface %s started by controller %s", cfg->getName(), c->getName());
156+
157+ // Look up the interface
158+
159+ if (0) { // already started?
160+ errno = EADDRINUSE;
161+ return -1;
162+ }
163+
164+ if (cfg->getUseDhcp()) {
165+ } else {
166+ }
155167 return 0;
156168 }
157169
158-int NetworkManager::onInterfaceDestroyed(Controller *c, char *name) {
159- LOGD("Interface %s destroyed by controller %s", name, c->getName());
170+int NetworkManager::onInterfaceStop(Controller *c, const char *name) {
171+ LOGD("Interface %s stopped by controller %s", name, c->getName());
160172 return 0;
161173 }
--- a/nexus/NetworkManager.h
+++ b/nexus/NetworkManager.h
@@ -21,6 +21,8 @@
2121 #include "Controller.h"
2222 #include "PropertyCollection.h"
2323
24+class InterfaceConfig;
25+
2426 class NetworkManager {
2527 private:
2628 static NetworkManager *sInstance;
@@ -57,9 +59,15 @@ private:
5759 NetworkManager();
5860
5961 public:
60-// XXX: Extract these into an interface
61- int onInterfaceCreated(Controller *c, char *name);
62- int onInterfaceDestroyed(Controller *c, char *name);
62+ /*
63+ * Called from a controller when an interface is available/ready for use.
64+ * 'cfg' contains information on how this interface should be configured.
65+ */
66+ int onInterfaceStart(Controller *c, const InterfaceConfig *cfg);
6367
68+ /*
69+ * Called from a controller when an interface should be shut down
70+ */
71+ int onInterfaceStop(Controller *c, const char *name);
6472 };
6573 #endif