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>
@@ -22,6 +22,7 @@ LOCAL_SRC_FILES:= \ | ||
22 | 22 | WifiScanner.cpp \ |
23 | 23 | WifiNetwork.cpp \ |
24 | 24 | OpenVpnController.cpp \ |
25 | + InterfaceConfig.cpp \ | |
25 | 26 | |
26 | 27 | LOCAL_MODULE:= nexus |
27 | 28 |
@@ -202,3 +202,11 @@ out_inval: | ||
202 | 202 | cli->sendMsg(ErrorCode::CommandParameterError, "Failed to set property.", true); |
203 | 203 | return 0; |
204 | 204 | } |
205 | + | |
206 | +CommandListener::ListCmd::ListCmd() : | |
207 | + NexusCommand("list") { | |
208 | +} | |
209 | + | |
210 | +int CommandListener::ListCmd::runCommand(SocketClient *cli, char *data) { | |
211 | + return 0; | |
212 | +} |
@@ -74,6 +74,13 @@ private: | ||
74 | 74 | virtual ~GetCmd() {} |
75 | 75 | int runCommand(SocketClient *c, char *data); |
76 | 76 | }; |
77 | + | |
78 | + class ListCmd : public NexusCommand { | |
79 | + public: | |
80 | + ListCmd(); | |
81 | + virtual ~ListCmd() {} | |
82 | + int runCommand(SocketClient *c, char *data); | |
83 | + }; | |
77 | 84 | }; |
78 | 85 | |
79 | 86 | #endif |
@@ -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 | + |
@@ -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 |
@@ -21,6 +21,7 @@ | ||
21 | 21 | #include <cutils/log.h> |
22 | 22 | |
23 | 23 | #include "NetworkManager.h" |
24 | +#include "InterfaceConfig.h" | |
24 | 25 | |
25 | 26 | NetworkManager *NetworkManager::sInstance = NULL; |
26 | 27 |
@@ -150,12 +151,23 @@ const PropertyCollection &NetworkManager::getProperties() { | ||
150 | 151 | return *mProperties; |
151 | 152 | } |
152 | 153 | |
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 | + } | |
155 | 167 | return 0; |
156 | 168 | } |
157 | 169 | |
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()); | |
160 | 172 | return 0; |
161 | 173 | } |
@@ -21,6 +21,8 @@ | ||
21 | 21 | #include "Controller.h" |
22 | 22 | #include "PropertyCollection.h" |
23 | 23 | |
24 | +class InterfaceConfig; | |
25 | + | |
24 | 26 | class NetworkManager { |
25 | 27 | private: |
26 | 28 | static NetworkManager *sInstance; |
@@ -57,9 +59,15 @@ private: | ||
57 | 59 | NetworkManager(); |
58 | 60 | |
59 | 61 | 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); | |
63 | 67 | |
68 | + /* | |
69 | + * Called from a controller when an interface should be shut down | |
70 | + */ | |
71 | + int onInterfaceStop(Controller *c, const char *name); | |
64 | 72 | }; |
65 | 73 | #endif |