/*
 *	uIP WebServer test
 */

namespace uIP {
/*
 * uIP is very app-centric, supporting only 1 TCP and 1 UDP
 * application. These includes will define the following macros:
 * UIP_APPCALL, UIP_UDP_APPCALL and the following typedefs:
 * typedef struct httpd_state uip_tcp_appstate_t;
 * typedef struct dhcpc_state uip_udp_appstate_t;
 */
#include <uip/apps/webserver/webserver.h>
#include <uip/apps/dhcpc/dhcpc.h>
}

// uip-epos.h will glue uIP with EPOS, defining uIP::main()
#include <uip/uip-epos.h>
#include <utility/ostream.h>

__USING_SYS

namespace uIP {
// We compile everything together
#include <uip/apps/webserver/httpd.c>
#include <uip/apps/webserver/httpd-cgi.c>
#include <uip/apps/webserver/httpd-fs.c>
#include <uip/apps/webserver/http-strings.c>

#include <uip/apps/dhcpc/dhcpc.c>
};

using namespace uIP;

OStream cout;

void init() {
	dhcpc_init(&(uIP::nic->address()), 6);
	httpd_init();
}

void uIP::dhcpc_configured(const struct dhcpc_state *s)
{
	cout << "Received DHCP configuration\n";
	uip_sethostaddr(s->ipaddr);
	uip_setnetmask(s->netmask);
	uip_setdraddr(s->default_router);
}

int main() {
	cout << "Executing APP\n";
	
	// will be configured by dhcp
	char ip[4]   = {0, 0, 0, 0};
	char gw[4]   = {0, 0, 0, 0};
	char mask[4] = {255, 255, 255, 0};
	
	uIP::main(ip,gw,mask,&init);
	return 0;
}
