passing Webserver instance to sub-routine

62 views
Skip to first unread message

Thomas Matthis

unread,
Oct 19, 2012, 7:43:38 AM10/19/12
to webd...@googlegroups.com
I trying to serve a list of files and associated data from an SD card.  I'd like to pass the WebServer instance from my webduino command to a subroutine, but I'm having trouble figuring out how to do this.  Notional code for what I'm trying to do...
 
void helloCmd(WebServer &server, WebServer::ConnectionType type, char *, bool)  // This command is registered with webserver
{
  server.print("some html here");
  listfiles(server, [other parms]);  //<- call to listfiles routine where I want to pass the server insance of WebServer
  server.print("more html here");
}
 
void listfiles(WebServer &server, [other parms]);
{
  various SD commands and html writes;
  server.print(filename);
  server.print(filedate);
  server.print(filesize);
}
 
I've tried what little I know and even the things I could make up to either create a new instance of WebServer or a pointer to the existing instance when I pass it.  Can't get anything to work.  I've thought about making m_client public in webserver.h and trying to pass it, but I want to edit webser.h as little as possible.
 
Anybody know how to do this.  It would make my code much simpler and more effieicent if I coud create subroutines and call them from each webduino web page command.
 
Thanks,

Ben Combee

unread,
Oct 19, 2012, 8:20:36 AM10/19/12
to webd...@googlegroups.com
That form should work fine.  Are you getting compilation errors or runtime errors?

Thomas Matthis

unread,
Oct 19, 2012, 8:56:06 AM10/19/12
to webd...@googlegroups.com
Compilation errors. Complains that list files variable is declared void.

Thomas Matthis

unread,
Oct 19, 2012, 10:15:05 AM10/19/12
to webd...@googlegroups.com
On Friday, October 19, 2012 8:20:36 AM UTC-4, Ben Combee wrote:
> That form should work fine.  Are you getting compilation errors or runtime errors?
>

I'm getting compile errors. 3 error messages are:
"variable or field 'ListFiles' declared void"
"'WebServer' was not declared in this scope"
"'server' was not declared in this scope"

WebServer.h is included long before any of these functions. webserver is declared "WebServer webserver(PREFIX, 80);" The listfiles function is defined before the calls to webserver.setDefaultCommand, .addCommand, & .begin.
Reply all
Reply to author
Forward
0 new messages