Next: Simple Server in Python
Up: Server
Previous: Server
Contents
Index
In order to develop your first server you can copy the files from pvsdemo
to your directory and adjust them to your needs.
Figure 3.3:
Template files
cp /usr/share/doc/packages/ProcessView/pvsdemo/pvapp.h .
cp /usr/share/doc/packages/ProcessView/pvsdemo/main.cpp .
cp /usr/share/doc/packages/ProcessView/pvsdemo/pvsdemo.pro pvs.pro
|
|
The skeleton for any pvserver look very similar.
Under linux you can simply do that by using the command pvsnew.
Figure 3.4:
Create a new project
mkdir newdir
cd newdir
pvsnew
|
|
pvsnew will edit the 3 files so that you can adjust them to your needs and save the files.
A makefile will be created automatically from pvs.pro .
If you want to extend your project later on you can edit pvs.pro and call make again.
Everything will be updated. If you change from multithreaded server to inetd
call "make clean && make".
Assume you want 2 masks "mask1" and "mask2". Then these files should look like shown.
Figure 3.5:
pvapp.h with 2 masks
// pvapp.h
#ifndef _PVAPP_H_
#define _PVAPP_H_
#include "processviewserver.h"
int show_mask1(PARAM *p);
int show_mask2(PARAM *p);
#endif
|
|
All you have to do in pvapp.h is to define the masknames you want to use.
Of course you can define anything else your pvserver will need at this place.
Figure 3.6:
main.cpp
// main.cpp
#include "pvapp.h"
int pvMain(PARAM *p)
{
int ret;
pvSetCaption(p,"pvsdemo");
pvResize(p,0,1280,1024);
ret = 1;
while(1)
{
switch(ret)
{
case 1:
ret = show_mask1(p);
break;
case 2:
ret = show_mask2(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
|
|
In pvMain there is a while loop. Within this loop you call the masks you have defined.
The return code of a mask tells the program which mask to call next.
Normally you will never leave pvMain. This will be done automatically when the user
of pvbrowser disconnects.
There are 2 versions of the main() function. They are selected by USE_INETD which can
be defined in the pvs.pro file. If USE_INETD is not defined the server will be
multithreaded and can be started at boot time. If USE_INETD is defined
pvserver may be started from inetd or xinetd. Which means that your server is singlethreaded.
Figure 3.7:
qmake pvs.pro file
# pvs.pro
TEMPLATE = app
CONFIG = warn_on release
# Input
HEADERS += pvapp.h
SOURCES += main.cpp \
mask1.cpp \
mask2.cpp
LIBS += /usr/lib/libpvsmt.so /usr/lib/libpthread.so
# LIBS += /usr/lib/libpvsid.so /usr/lib/libpthread.so
# DEFINES += USE_INETD
# TARGET = targetname
|
|
In the pvs.pro file you specify all your sourcefiles and the libraries used.
You can select between multithreaded and siglethreaded (USE_INETD).
Now you have to edit your masks. Start designer and choose new dialog.
Insert some widgets and store your dialogs as "mask1.ui"
and "mask2.ui" respectively. Then type "make". Your server is ready
you can start it with "./pvs". It should be possible to see everything
that was designed in Qt Designer. Now you are ready to implement your
own logic. Remember there are 2 comments in each mask which define
the begin of generated area and the end of generated area. Outside
this area you can insert your code. Example:
Figure 3.8:
Event handling
// within mask1.cpp
<snip>
case BUTTON_EVENT:
//printf("BUTTON_EVENT id=%d\n",i);
if(i == pushButton1) return 2;
if(i == pushButtonHide) pvHide(p,frame3);
if(i == pushButtonShow) pvShow(p,frame3);
break;
<snip>
|
|
Next: Simple Server in Python
Up: Server
Previous: Server
Contents
Index
Rainer Lehrig
2004-02-17