Using a library in another library (Webduino)

Okay so I'm new to C and I'm really struggling on how to get my head around this.
I want to keep all my webserver code neat and out of the main script so I've started creating a library, and I realise it has heaps of errors and is allover the place but would
really appreciate some help on how I should be structuring this.

main script (WebPages is my new library, could be named better but trying to work this out first):

#include "WebPages.h"
#include "SPI.h"
#include "Ethernet.h"
#include "WebServer.h"

WebPages server;


void setup()
{
  server.setup();
}

void loop()
{
  server.servProcess();
}

WebPages.h

#ifndef WebPages_h
#define WebPages_h

#include "WebPages.h"
#include "SPI.h"
#include "Ethernet.h"
#include "WebServer.h"
#include "Arduino.h"

class WebPages
{
  public:
    WebPages();
	void setup();
	void servProcess();
	void defaultCmd(WebServer &server, WebServer::ConnectionType type, char *url_tail, bool tail_complete);
  private:
	
};

#endif

WebPages.ccp

#include "WebPages.h"
#include "SPI.h"
#include "Ethernet.h"
#include "WebServer.h"
#include "Arduino.h"

template<class T>
inline Print &operator <<(Print &obj, T arg)
{ obj.print(arg); return obj; }


static uint8_t mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
static uint8_t ip[] = { 192, 168, 1, 210 };
#define PREFIX ""
WebServer webserver(PREFIX, 80);

void defaultCmd(WebServer &server, WebServer::ConnectionType type, char *url_tail, bool tail_complete)
{
  P(htmlHead) =
    "<html>"
    "<head>"
    "<title>Arduino Web Server</title>"
    "<style type=\"text/css\">"
    "BODY { font-family: sans-serif }"
    "H1 { font-size: 14pt; text-decoration: underline }"
    "P  { font-size: 10pt; }"
    "</style>"
    "</head>"
    "<body>"
	"TEST"
	"</body>";
  server.httpSuccess();
  server.printP(htmlHead);
}

WebPages::WebPages()
{
	//created
}
void WebPages::setup()
{
	Ethernet.begin(mac, ip);
	webserver.begin();
	webserver.setDefaultCommand(&defaultCmd);
}

void WebPages::servProcess()
{
	webserver.processConnection();
}

So I'm not sure if I should be reincluding libraries in .h and .ccp.
And why &defaultCmd in webserver.setDefaultCommand(&defaultCmd); is the wrong parameter type.
And just how I should go about using another library in a library and if this is the correct way of going about it.

Any help or reference to a tutorial on this would be great! I've done the arduino creating library tutorial, although it dosnt help much when it comes to refering to other libraries within.

Why does WebPages.h include WebPages.h?

So I'm not sure if I should be reincluding libraries in .h and .ccp.

Except for the above, you are doing fine.

And why &defaultCmd in webserver.setDefaultCommand(&defaultCmd); is the wrong parameter type.

Because defaultCmd is the address of a function. While there are strong similarities between methods (class functions) and functions, they are not identical. The webserver instance has no idea which instance of the class the function you want to call belongs to.

You need to make the defaultCmd method in the class static, so that there is only one instance of the method, so that it then behaves exactly like a function.

Of course, once you do that, no other class data will be available to the method, unless you get creative.

PaulS:
Why does WebPages.h include WebPages.h?

So I'm not sure if I should be reincluding libraries in .h and .ccp.

Ah yeah my bad, fixed that up!

Except for the above, you are doing fine.

Awesome : )

And why &defaultCmd in webserver.setDefaultCommand(&defaultCmd); is the wrong parameter type.

Because defaultCmd is the address of a function. While there are strong similarities between methods (class functions) and functions, they are not identical. The webserver instance has no idea which instance of the class the function you want to call belongs to.

You need to make the defaultCmd method in the class static, so that there is only one instance of the method, so that it then behaves exactly like a function.

Okay, cool that better explains it for me, i'll have to try it out again and see if I can make more sense of it : )!

After reading this thread i try this but Error of multiple defination start occuring why?

I really appreciate your suggestions.

Sketch

#include "WebPages.h"
#include <SPI.h>
#include <Ethernet.h>
#include "WebServer.h"

WebPages Pages;

void setup()
{
  Pages.setup();
}

void loop()
{
  Pages.servProcess();
}

WebPages.h

#ifndef WebPages_h
#define WebPages_h

#include "WebServer.h"
#include "Arduino.h"
#include <SPI.h>
#include <Ethernet.h>


class WebPages
{
  public:
    WebPages();
	void setup();
	void servProcess();
 private:
	static void defaultCmd(WebServer &server, WebServer::ConnectionType type, char *url_tail, bool tail_complete);
};

//extern WebPages Pages;
#endif

WebPages.cpp

#include "WebPages.h"

#include <SPI.h>
#include <Ethernet.h>
#include "Arduino.h"

template<class T>
inline Print &operator <<(Print &obj, T arg)
{ obj.print(arg); return obj; }


static uint8_t mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
static uint8_t ip[] = { 192, 168, 1, 210 };
#define PREFIX ""
WebServer webserver(PREFIX, 80);

WebPages::WebPages()
{
	//created
}
void WebPages::defaultCmd(WebServer &server, WebServer::ConnectionType type, char *url_tail, bool tail_complete)
{
  P(htmlHead) =
    "<html>"
    "<head>"
    "<title>Arduino Web Server</title>"
    "<style type=\"text/css\">"
    "BODY { font-family: sans-serif }"
    "H1 { font-size: 14pt; text-decoration: underline }"
    "P  { font-size: 10pt; }"
    "</style>"
    "</head>"
    "<body>"
	"TEST"
	"</body>";
  server.httpSuccess();
  server.printP(htmlHead);
}
void WebPages::setup()
{
	Ethernet.begin(mac, ip);
	webserver.begin();
	webserver.setDefaultCommand(&WebPages::defaultCmd);
}

void WebPages::servProcess()
{
	webserver.processConnection();
}

//WebPages Pages = WebPages();

WebServer.h file of webduino

ERRORS

WebPages\WebPages.cpp.o: In function WebServer::setDefaultCommand(void (*)(WebServer&, WebServer::ConnectionType, char*, bool))': /WebServer.h:356: multiple definition of WebServer::setDefaultCommand(void ()(WebServer&, WebServer::ConnectionType, char, bool))'
Webpages.cpp.o:D:\arduino-1\libraries\WebPages/WebServer.h:356: first defined here
WebPages\WebPages.cpp.o: In function WebServer::setFailureCommand(void (*)(WebServer&, WebServer::ConnectionType, char*, bool))': /WebServer.h:361: multiple definition of WebServer::setFailureCommand(void ()(WebServer&, WebServer::ConnectionType, char, bool))'
Webpages.cpp.o:D:\arduino-1\libraries\WebPages/WebServer.h:361: first defined here
WebPages\WebPages.cpp.o: In function WebServer::addCommand(char const*, void (*)(WebServer&, WebServer::ConnectionType, char*, bool))': /WebServer.h:364: multiple definition of WebServer::addCommand(char const*, void ()(WebServer&, WebServer::ConnectionType, char, bool))'
Webpages.cpp.o:D:\arduino-1\libraries\WebPages/WebServer.h:364: first defined here
WebPages\WebPages.cpp.o: In function `WebServer::push(int)':

Other in txt attach file

error.txt (11.1 KB)

I downloaded the Webduino library, and was disappointed at what I found. A header file with no source file.

I copied your sketch and header and source files, and got the same errors you did.

I edited the WebServer.h file, and cut the implementation code, and saved the changes. I created a new file, WebServer.cpp, and pasted the implementation code there, added a #include statement, to include the header file, and saved.

Now, your sketch compiles perfectly. I've attached the modified files.

If I were you, I'd fire a nastygram off to the library developer and tell him what I thought of his or her being too lazy to create two files.

WebServer.cpp (20.1 KB)

WebServer.h (12.5 KB)

Thankyou

i got your reply in a bus stand. After reading that now i am so happy while i am too late.

Ignore spelling and grammer because i am not good in using my moblie.