pvbrowser manual
Back Content Forward

Main function

The main function is different for USE_INETD and a MULTI_THREADED pvserver. This is distinguished by an #ifdef statement. For USE_INETD see also the project file.

In case of a MULTI_THREADED server, which is the default, pvserver runs in a loop waiting for clients. When a client connects a separate thread is opened which will call pvMain in order to handle the client.

In case of USE_INETD the superserver (x)inetd will call pvserver. pvserver will then use stdin and stdout for communication with pvbrowser. In this case pvserver consists only of 1 process per client whereas in case of a MULTI_THREADED pvserver there is 1 thread per client + 1 thread for accepting clients.

In pvMain there is also a loop in which all available masks are called. The return value of a mask defines which mask to call next.

//***************************************************************************
//                          main.cpp  -  description
//                             -------------------
//  begin            : Di Okt 6 11:25:46 2009
//  generated by     : pvdevelop (C) Lehrig Software Engineering
//  email            : lehrig@t-online.de
//***************************************************************************
#include "pvapp.h"
// todo: comment me out. you can insert these objects as extern in your masks.
//rlModbusClient     modbus(modbusdaemon_MAILBOX,modbusdaemon_SHARED_MEMORY,modbusdaemon_SHARED_MEMORY_SIZE);
//rlSiemensTCPClient siemensTCP(siemensdaemon_MAILBOX,siemensdaemon_SHARED_MEMORY,siemensdaemon_SHARED_MEMORY_SIZE);
//rlPPIClient        ppi(ppidaemon_MAILBOX,ppidaemon_SHARED_MEMORY,ppidaemon_SHARED_MEMORY_SIZE);

int pvMain(PARAM *p)
{
int ret;

  pvSetCaption(p,"pvs");
  pvResize(p,0,1280,1024);
  //pvScreenHint(p,1024,768); // this may be used to automatically set the zoomfactor
  ret = 1;
  pvGetInitialMask(p);
  if(strcmp(p->initial_mask,"mask1") == 0) ret = 1;

  while(1)
  {
    if(trace) printf("show_mask%d\n", ret);
    switch(ret)
    {
      case 1:
        pvStatusMessage(p,-1,-1,-1,"mask1");
        ret = show_mask1(p);
        break;
      default:
        return 0;
    }
  }
}

#ifdef USE_INETD
int main(int ac, char **av)
{
PARAM p;

  pvInit(ac,av,&p);
  /* here you may interpret ac,av and set p->user to your data */
  pvMain(&p);
  return 0;
}
#else  // multi threaded server
int main(int ac, char **av)
{
PARAM p;
int   s;

  pvInit(ac,av,&p);
  /* here you may interpret ac,av and set p->user to your data */
  while(1)
  {
    s = pvAccept(&p);
    if(s != -1) pvCreateThread(&p,s);
    else        break;
  }
  return 0;
}
#endif

Back Content Forward