From 54be3babc8e17f39637afc95b5fa798e0d3c9350 Mon Sep 17 00:00:00 2001 From: Jim Morris Date: Sun, 10 Apr 2016 14:24:22 -0700 Subject: [PATCH] make plan9 optional build, not built by default use make PLAN9=1 to build it refactor Network to remove most of the statics --- build/common.mk | 8 ++++++- src/libs/Network/uip/Network.cpp | 36 ++++++++++++++++++-------------- src/libs/Network/uip/Network.h | 22 +++++++++++++------ 3 files changed, 43 insertions(+), 23 deletions(-) diff --git a/build/common.mk b/build/common.mk index c42c94c540..cf9cf0348a 100755 --- a/build/common.mk +++ b/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 diff --git a/src/libs/Network/uip/Network.cpp b/src/libs/Network/uip/Network.cpp index ad6e40e8d6..f56e41c8dc 100644 --- a/src/libs/Network/uip/Network.cpp +++ b/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 @@ -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: diff --git a/src/libs/Network/uip/Network.h b/src/libs/Network/uip/Network.h index 50b35b4a00..9f1c9e7f16 100644 --- a/src/libs/Network/uip/Network.h +++ b/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