Main Page | Namespace List | Class Hierarchy | Compound List | File List | Compound Members | File Members

DCDT_Httpd.cpp

Go to the documentation of this file.
00001 /****************************************************************************
00002 dEVICE cOMMUNITIES dEVELOPMENT tOOLKIT 
00003 
00004 DCDT_Httpd.cpp
00005 
00006 COPYRIGHT (C) 2004  Cristian Giussani
00007 
00008 
00009 This library is free software; you can redistribute it and/or
00010 modify it under the terms of the GNU Lesser General Public
00011 License as published by the Free Software Foundation; either
00012 version 2 of the License, or (at your option) any later version.
00013 
00014 This library is distributed in the hope that it will be useful,
00015 but WITHOUT ANY WARRANTY; without even the implied warranty of
00016 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00017 Lesser General Public License for more details.
00018 
00019 You should have received a copy of the GNU Lesser General Public
00020 License along with this library; if not, write to the Free Software
00021 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA.
00022 
00023 ****************************************************************************/
00024 
00025 #ifdef HAVE_HTTPD
00026 
00027 #ifndef DCDT_HTTPD_CPP
00028 #define DCDT_HTTPD_CPP
00029 
00030 #include <DCDT_Httpd.h>
00031 #include <DCDT_Agora.h>
00032 
00033 void htmlPostOffice ( httpd *server, void *data )
00034 {
00035   DCDT_Httpd *obj;
00036   char buffer[1024];
00037 
00038   obj=(DCDT_Httpd *)data;
00039   httpdPrintf ( server, "<HTML><BODY><PRE>" );
00040   obj->PostOfficeStatus ( (char *)buffer, sizeof(buffer) );
00041   httpdPrintf ( server, "%s", buffer ); 
00042   httpdPrintf ( server, "</PRE></BODY></HTML>" );
00043 
00044   return;
00045 }
00046 
00047 void htmlPostOfficeQueue ( httpd *server, void *data )
00048 {
00049   DCDT_Httpd *obj;
00050   char buffer[1024];
00051 
00052   obj=(DCDT_Httpd *)data;
00053   httpdPrintf ( server, "<HTML><BODY><PRE>" );
00054   obj->PostOfficeQueue ( (char *)buffer, sizeof(buffer) );
00055   httpdPrintf ( server, "%s", buffer ); 
00056   httpdPrintf ( server, "</PRE></BODY></HTML>" );
00057 }
00058 
00059 void htmlAgora ( httpd *server, void *data )
00060 {
00061   DCDT_Httpd *obj;
00062   char buffer[1024];
00063 
00064   obj=(DCDT_Httpd *)data;
00065 
00066   httpdPrintf ( server, "<HTML><BODY>" );
00067   obj->AgoraStatus ( (char *)buffer, sizeof(buffer) );
00068   httpdPrintf ( server, "%s", buffer ); 
00069   httpdPrintf ( server, "</BODY></HTML>" );
00070 
00071   return;
00072 }
00073 
00074 void DCDT_Httpd::PostOfficeStatus ( char *buffer, int len )
00075 {
00076   sprintf ( buffer, "Numero messaggi: %d", myPostOffice->NumOfMsgPresent );
00077   return;
00078 }
00079 
00080 void DCDT_Httpd::PostOfficeQueue ( char *buffer, int len )
00081 {
00082   DCDT_MsgListElem *myelem=myPostOffice->Head;
00083   char cbufdmy[256];
00084   int idmy;
00085 
00086   sprintf ( buffer, "<TABLE><TR><TD>Msg num.</TD><TD>Type</TD><TD>PayloadLen</TD></TR>" );
00087 
00088   idmy=0;
00089   while ( myelem != myPostOffice->Tail ) {
00090     idmy++;
00091     sprintf ( cbufdmy, "<TR><TD>%d</TD>", idmy );
00092     strcat ( buffer, cbufdmy );
00093 
00094     if ( myelem->MsgPtr != NULL ) {
00095       sprintf ( cbufdmy, "<TD>%d</TD><TD>%d</TD></TR>", myelem->MsgPtr->ReadType(),
00096                 myelem->MsgPtr->ReadPayloadLen() );
00097       strcat ( buffer, cbufdmy );
00098     }
00099     else
00100       strcat ( buffer, "</TR>" );
00101 
00102     myelem = myelem->next;
00103   }
00104 
00105   strcat ( buffer, "</TABLE>" );
00106 
00107   return;
00108 }
00109 
00110 void DCDT_Httpd::AgoraStatus ( char *buffer, int len )
00111 {
00112   int idmy;
00113   char cbufdmy[256];
00114 
00115   if ( myAgora->commflag == false )
00116     sprintf ( buffer, "<H2><CENTER>Modalita' STANDALONE</CENTER></H2>" );
00117   else
00118     sprintf ( buffer, "<H2><CENTER>Modalita' NETWORK</CENTER></H2>" );
00119 
00120   strcat ( buffer, "<TABLE><TR><TD>N.</TD><TD>ID</TD></TR>" );
00121   for ( idmy=0; idmy<MAX_MEMBERS; idmy++ ) {
00122     if ( ( myAgora->MemberTable[idmy].MemberPtr != NULL )  ) {
00123       sprintf ( cbufdmy, "<TR><TD>%d</TD><TD>%d</TD><TD>%s</TD></TR>", idmy,
00124                 myAgora->MemberTable[idmy].MemberPtr->myID, 
00125                 typeid(*(myAgora->MemberTable[idmy].MemberPtr)).name() );
00126       strcat ( buffer, cbufdmy );
00127     }
00128   }
00129   
00130   strcat ( buffer, "<TABLE>" );
00131   return;
00132 }
00133 
00134 DCDT_Httpd::DCDT_Httpd(DCDT_Agora* agora)
00135   : DCDT_Member( agora )
00136 {
00137   
00138   server = httpdCreate ( NULL, 2000 );
00139   if ( server == NULL ) {
00140     perror ( "Can't create httpd server" );
00141     return;
00142   }
00143 
00144   httpdSetAccessLog ( server, stdout );
00145   httpdSetErrorLog ( server, stderr );
00146 
00147   httpdAddCContent ( server, "/", "postoffice.html", HTTP_FALSE, NULL,
00148                      htmlPostOffice, this );
00149 
00150   httpdAddCContent ( server, "/", "postoffice_queue.html", HTTP_FALSE, NULL,
00151                      htmlPostOfficeQueue, this );
00152 
00153   httpdAddCContent ( server, "/", "agora.html", HTTP_FALSE, NULL,
00154                     htmlAgora, this );
00155 
00156   httpdAddStaticContent ( server, "/", "index.html", HTTP_TRUE, NULL
00157                           , "<HTML><BODY><PRE>Funziona</PRE></BODY></HTML>");
00158 };
00159 
00160 DCDT_Httpd::~DCDT_Httpd() {
00161   
00162 };
00163 
00166 void DCDT_Httpd::DoYourJob(int par) {
00167   if ( server != NULL ) {
00168     if ( httpdGetConnection( server, NULL ) > 0 ) {
00169       if ( httpdReadRequest( server ) >= 0 ) {
00170         httpdProcessRequest( server );
00171       }
00172     }
00173     
00174     httpdEndRequest( server );
00175   }
00176 }
00177 
00178 void DCDT_Httpd::Init() {
00179   DBG_PRINTF(("Httpd Initializinig\n"));  
00180 };
00181 
00182 void DCDT_Httpd::Close() {
00183   
00184   DBG_PRINTF(("Httpd Closing\n"));  
00185 };
00186 
00187 #endif //define
00188 
00189 #endif // HAVE_HTTPD

Generated on Fri Jul 16 12:29:45 2004 for dcdt by doxygen 1.3.2