Skip to content
Browse files

make plan9 optional build, not built by default use make PLAN9=1 to b…

…uild it

refactor Network to remove most of the statics
  • Loading branch information...
1 parent 883443c commit 54be3babc8e17f39637afc95b5fa798e0d3c9350 @wolfmanjm wolfmanjm committed Apr 10, 2016
Showing with 43 additions and 23 deletions.
  1. +7 −1 build/common.mk
  2. +20 −16 src/libs/Network/uip/Network.cpp
  3. +16 −6 src/libs/Network/uip/Network.h
View
8 build/common.mk
@@ -96,11 +96,17 @@ ASRCS = $(wildcard $(SRC)/*.S $(SRC)/*/*.S $(SRC)/*/*/*.S $(SRC)/*/*/*/*.S $(SR
ifneq "$(OS)" "Windows_NT"
ASRCS += $(wildcard $(SRC)/*.s $(SRC)/*/*.s $(SRC)/*/*/*.s $(SRC)/*/*/*/*.s $(SRC)/*/*/*/*/*.s)
endif
+
CPPSRCS1 = $(wildcard $(SRC)/*.cpp $(SRC)/*/*.cpp $(SRC)/*/*/*.cpp $(SRC)/*/*/*/*.cpp $(SRC)/*/*/*/*/*.cpp $(SRC)/*/*/*/*/*/*.cpp)
ifeq "$(NONETWORK)" "1"
CPPSRCS2 = $(filter-out $(SRC)/libs/Network/%,$(CPPSRCS1))
else
-CPPSRCS2 = $(CPPSRCS1)
+ ifneq "$(PLAN9)" "1"
+ DEFINES += -DNOPLAN9
+ CPPSRCS2 = $(filter-out $(SRC)/libs/Network/uip/plan9/%,$(CPPSRCS1))
+ else
+ CPPSRCS2 = $(CPPSRCS1)
+ endif
endif
# Totally exclude any modules listed in EXCLUDE_MODULES
View
36 src/libs/Network/uip/Network.cpp
@@ -23,7 +23,10 @@
#include "webserver.h"
#include "dhcpc.h"
#include "sftpd.h"
+
+#ifndef NOPLAN9
#include "plan9.h"
+#endif
#include <mri.h>
@@ -44,20 +47,17 @@ extern "C" void uip_log(char *m)
printf("uIP log message: %s\n", m);
}
-static bool webserver_enabled, telnet_enabled, plan9_enabled, use_dhcp;
-static Network *theNetwork;
-static Sftpd *sftpd;
-static CommandQueue *command_q= CommandQueue::getInstance();
+static Network* theNetwork;
-Network* Network::instance;
Network::Network()
{
+ theNetwork= this;
ethernet = new LPC17XX_Ethernet();
tickcnt= 0;
- theNetwork= this;
sftpd= NULL;
- instance= this;
hostname = NULL;
+ plan9_enabled= false;
+ command_q= CommandQueue::getInstance();
}
Network::~Network()
@@ -66,6 +66,7 @@ Network::~Network()
if (hostname != NULL) {
delete hostname;
}
+ theNetwork= nullptr;
}
static uint32_t getSerialNumberHash()
@@ -131,7 +132,6 @@ void Network::on_module_loaded()
webserver_enabled = THEKERNEL->config->value( network_checksum, network_webserver_checksum, network_enable_checksum )->by_default(false)->as_bool();
telnet_enabled = THEKERNEL->config->value( network_checksum, network_telnet_checksum, network_enable_checksum )->by_default(false)->as_bool();
plan9_enabled = THEKERNEL->config->value( network_checksum, network_plan9_checksum, network_enable_checksum )->by_default(false)->as_bool();
-
string mac = THEKERNEL->config->value( network_checksum, network_mac_override_checksum )->by_default("")->as_string();
if (mac.size() == 17 ) { // parse mac address
if (!parse_ip_str(mac, mac_address, 6, 16, ':')) {
@@ -292,7 +292,7 @@ void Network::on_idle(void *argument)
}
}
-static void setup_servers()
+void Network::setup_servers()
{
if (webserver_enabled) {
// Initialize the HTTP server, listen to port 80.
@@ -306,11 +306,13 @@ static void setup_servers()
printf("Telnetd initialized\n");
}
+#ifndef NOPLAN9
if (plan9_enabled) {
// Initialize the plan9 server
Plan9::init();
printf("Plan9 initialized\n");
}
+#endif
// sftpd service, which is lazily created on reciept of first packet
uip_listen(HTONS(115));
@@ -396,24 +398,26 @@ extern "C" void app_select_appcall(void)
{
switch (uip_conn->lport) {
case HTONS(80):
- if (webserver_enabled) httpd_appcall();
+ if (theNetwork->webserver_enabled) httpd_appcall();
break;
case HTONS(23):
- if (telnet_enabled) Telnetd::appcall();
+ if (theNetwork->telnet_enabled) Telnetd::appcall();
break;
+#ifndef NOPLAN9
case HTONS(564):
- if (plan9_enabled) Plan9::appcall();
+ if (theNetwork->plan9_enabled) Plan9::appcall();
break;
+#endif
case HTONS(115):
- if(sftpd == NULL) {
- sftpd= new Sftpd();
- sftpd->init();
+ if(theNetwork->sftpd == NULL) {
+ theNetwork->sftpd= new Sftpd();
+ theNetwork->sftpd->init();
printf("Created sftpd service\n");
}
- sftpd->appcall();
+ theNetwork->sftpd->appcall();
break;
default:
View
22 src/libs/Network/uip/Network.h
@@ -5,6 +5,8 @@
#include "LPC17XX_Ethernet.h"
#include "Module.h"
+class Sftpd;
+class CommandQueue;
class Network : public Module
{
@@ -17,26 +19,34 @@ class Network : public Module
void on_main_loop(void* argument);
void on_get_public_data(void* argument);
void dhcpc_configured(uint32_t ipaddr, uint32_t ipmask, uint32_t ipgw);
- static Network *getInstance() { return instance;}
void tapdev_send(void *pPacket, unsigned int size);
+ // accessed from C
+ Sftpd *sftpd;
+ struct {
+ bool webserver_enabled:1;
+ bool telnet_enabled:1;
+ bool plan9_enabled:1;
+ bool use_dhcp:1;
+ };
+
+
private:
void init();
+ void setup_servers();
uint32_t tick(uint32_t dummy);
void handlePacket();
- static Network *instance;
-
+ CommandQueue *command_q;
LPC17XX_Ethernet *ethernet;
struct timer periodic_timer, arp_timer;
+ char *hostname;
+ volatile uint32_t tickcnt;
uint8_t mac_address[6];
uint8_t ipaddr[4];
uint8_t ipmask[4];
uint8_t ipgw[4];
- char *hostname;
- volatile uint32_t tickcnt;
-
};
#endif

0 comments on commit 54be3ba

Please sign in to comment.
Something went wrong with that request. Please try again.