ProcessViewServer Programming Reference
(0) Definitions (Events, Fonts, Colors ...)
#define MAX_PRINTF_LENGTH 1024 /* max length of pvPrintf buffer */
#define MAX_EVENT_LENGTH 1024 /* max length of an event */
/* these are the possible events */
enum PvEvent {
NULL_EVENT=1,
BUTTON_EVENT,
TEXT_EVENT,
SLIDER_EVENT,
CHECKBOX_EVENT,
RADIOBUTTON_EVENT,
GL_IDLE_EVENT,
GL_PAINT_EVENT,
GL_INITIALIZE_EVENT,
GL_RESIZE_EVENT
};
/* these are the linestyles used in line(x,y,n) */
enum Linestyle {
LINESTYLE_NONE=0,
LINESTYLE_CIRCLE,
LINESTYLE_CROSS,
LINESTYLE_RECT
};
/* these are the available fonts */
#define HELVETICA "Helvetica"
#define TIMES "Times"
#define COURIER "Courier"
#define OLDENGLISH "OldEnglish"
#define SYSTEM "System"
#define ANYSTYLE "AnyStyle"
/* font weight */
enum Weight { Light = 25, Normal = 50, DemiBold = 63, Bold = 75, Black = 87 };
/* font alignment */
enum FontAlignment { /* */
ALIGN_LEFT=0, /* example */
ALIGN_CENTER, /* example */
ALIGN_RIGHT, /* example */
ALIGN_VERT_CENTER /* e */
}; /* x */
/* a */
/* m */
/* p */
/* l */
/* e */
/* font italic can be one of this */
#define NORMAL 0
#define ITALIC 1
/* insertion policies for QComboBox */
enum Policy { NoInsertion=0, AtTop, AtCurrent, AtBottom, AfterCurrent, BeforeCurrent };
/* some predefined colors */
#define RED 255,0,0
#define GREEN 0,255,0
#define BLUE 0,0,255
#define WHITE 255,255,255
#define BLACK 0,0,0
#define YELLOW 255,255,0
#define LILA 255,0,255
#define CYAN 0,255,255
#define DARK_GREY 128,128,128
#define LIGHT_GREY 180,180,180
#define WHEAT 213,213,154
#define DARK_RED 128,0,0
#define DARK_GREEN 0,128,0
#define DARK_LILA 128,0,128
#define DARK_CYAN 0,128,128
#define DARK_YELLOW 200,200,0
#define DARK_BLUE 0,0,128
/* definition for LCD numbers */
enum Mode { HEX=0, DEC, OCT, BIN };
enum SegmentStyle { Outline=0, Filled, Flat };
/* definitions for QSlider */
#define HORIZONTAL 0
#define VERTICAL 1
/* definitions for QFrame */
enum Shape {
NoFrame = 0, /* no frame */
Box = 0x0001, /* rectangular box */
Panel = 0x0002, /* rectangular panel */
WinPanel = 0x0003, /* rectangular panel (Windows) */
HLine = 0x0004, /* horizontal line */
VLine = 0x0005, /* vertical line */
StyledPanel = 0x0006, /* rectangular panel depending on the GUI style */
PopupPanel = 0x0007, /* rectangular panel depending on the GUI style */
MShape = 0x000f /* mask for the shape */
};
enum Shadow{
Plain = 0x0010, /* plain line */
Raised = 0x0020, /* raised shadow effect */
Sunken = 0x0030, /* sunken shadow effect */
MShadow = 0x00f0 }; /* mask for the shadow */
/* thread parameters */
typedef struct
{
int s; /* socket */
int os; /* original socket */
int port; /* our port */
FILE *fp; /* filepointer */
int sleep; /* sleep time in milliseconds */
int (*cleanup)(void *); /* cleanup for user code */
void *app_data; /* application data for cleanup */
void *user; /* pointer to user data */
}PARAM;
/* this is for convenience when you want to write files */
#define PARAM_P PARAM p;pvInit(0,NULL,&p);
/* wait with pvWait(INITIALIZE_GL) before you initialize you OpenGL scene */
#define INITIALIZE_GL "initializeGL"
#define RESIZE_GL "resizeGL"
(1) int pvWriteFile(PARAM *p, const char *filename, int width, int height);
write the following to file
during the file is open nothing will be send to tcp
return=0 failure
return=1 success
(2) int pvCloseFile(PARAM *p);
close the open file
(3) int pvInit(int ac, char **av, PARAM *p);
pvInit must be called in main(). It interprets the command line switches that it knows.
Afterwards you can interpret your command line switches. It is possible to set p.user to data
of your choice. This data will be available in the worker threads. (Caution: the worker threads are
only allowed to read the p.user data because it is shared among all clients)
Then there must be a while(1) in which new clients are accepted. For each client a new thread
is created.
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);
}
return 0;
}
(4) int pvAccept(PARAM *p);
see pvInit
(5) int pvCreateThread(PARAM *p, int s);
see pvInit
(6) int pvMain(PARAM *p);
pvMain is your main worker thread. It could look as follows.
The main worker thread is never closed. It will be closed automatically when the client disconnects.
int pvMain(PARAM *p)
{
int ret;
// here you can initialize your worker thread
pvSetCleanup(p,your_exit_handler,your_app_data); // if cleanup is necessary
pvResize(p,0,970,600); // this will resize your working area
ret = showMask1(p);
while(1)
{
switch(ret)
{
case 1:
ret = showMask1(p);
break;
case 2:
ret = showMask2(p);
break;
case 3:
ret = showMask3(p);
break;
default:
return 0;
}
}
}
(7) int pvSetCleanup(PARAM *p, int (*cleanup)(void *), void *app_data);
If it is necessary to cleanup your application when the main worker thread terminates
you can set an exit handler that receives the data in app_data.
Call this function in pvMain. See also pvMain.
(8) int pvPollEvent(PARAM *p, char *event);
This function will return the next event as soon as it is available.
The maximum wait time is p->sleep in milliseconds (default 100).
You can specify a different wait time on the commandline (-sleep=1000)
Example:
int showMask1(PARAM *p)
{
DATA d;
char event[MAX_EVENT_LENGTH];
int i;
char text[MAX_EVENT_LENGTH];
defineMask1(p);
readData1(&d); // from shared memory or out of database
showData1(p,&d);
while(1)
{
pvPollEvent(p,event);
switch(pvParseEvent(event, &i, text))
{
case NULL_EVENT:
readData1(&d); // from shared memory or out of database
showData1(p,&d);
break;
case BUTTON_EVENT:
...
break;
case TEXT_EVENT:
...
break;
default:
printf("UNKNOWN_EVENT id=%d %s\n",i,text);
break;
}
}
}
(9) int pvWait(PARAM *p, const char *pattern);
waits for an event.
(10) int pvGlUpdate(PARAM *p, int id);
update OpenGL widget
(11) int pvSleep(int milliseconds);
Sleep for milliseconds.
(12) int pvWarning(PARAM *p, const char *text);
Output a warning message.
(13) int pvMainFatal(PARAM *p, const char *text);
Output a fatal message and terminate the whole server.
(14) int pvThreadFatal(PARAM *p, const char *text);
Output a fatal message and terminate the worker thread.
(15) int pvStartDefinition(PARAM *p, int num_objects);
Call this function first when you want to define a new mask.
Your enum for the mask should always contain ID_END_OF_WIDGETS as the last element.
Example:
pvStartDefinition(p,ID_END_OF_WIDGETS);
(16) int pvQWidget(PARAM *p, int id, int parent);
Creates a new QWidget. It's id can be used to identify it. It's parent is parent.
QWidget draws nothing, but it is useful to group objects hierarchically.
(17) int pvQLabel(PARAM *p, int id, int parent);
Creates a new QLabel. See also QWidget.
(18) int pvQComboBox(PARAM *p, int id, int parent, int editable, int policy);
editable = 0 not editable
editable = 1 user can edit combo box
for policy see definitions
Creates a new QComboBox. See also QWidget.
(19) int pvQLineEdit(PARAM *p, int id, int parent);
Creates a new QLineEdit. See also QWidget.
(20) int pvQPushButton(PARAM *p, int id, int parent);
Creates a new QPushButton. See also QWidget.
(21) int pvQLCDNumber(PARAM *p, int id, int parent, int numDigits, int segmentStyle, int mode);
Creates a new QLCDNumber.
enum Mode { HEX=0, DEC, OCT, BIN };
enum SegmentStyle { Outline=0, Filled, Flat };
(22) int pvQSlider(PARAM *p, int id, int parent, int minValue, int maxValue, int pageStep, int value, int orientation);
Creates a new QSlider. See also QWidget.
(23) int pvQButtonGroup(PARAM *p, int id, int parent, int columns, int orientation, const char *title);
Creates a new QButtonGroup. See also QWidget.
(24) int pvQRadioButton(PARAM *p, int id, int parent);
Creates a new QRadioButton. See also QWidget.
(25) int pvQCheckBox(PARAM *p, int id, int parent);
Creates a new QCheckBox. See also QWidget.
(26) int pvQFrame(PARAM *p, int id, int parent, int shape, int shadow, int line_width, int margin);
Creates a new QFrame. See also QWidget.
(27) int pvQDraw(PARAM *p, int id, int parent);
Creates a new QDrawWidget. See also QWidget.
This type of widget can be used to draw diagrams and whatever you want.
(28) int pvQImage(PARAM *p, int id, int parent, const char *imagename, int *w, int *h, int *depth);
Creates a new QImage. See also QWidget.
Specify the name of a 8bpp gif or bmp file.
w = width of image will be returned (w must be a multiple of 2)
h = height of image will be returned (h must be a multiple of 2)
depth = number of bits per pixel (currently only 8 is supported)
(29) int pvQGL(PARAM *p, int id, int parent);
Creates a new OpenGL Widget . See also QWidget.
(30) int pvEndDefinition(PARAM *p);
Call this function when you are finished with the definition of your mask.
(31) int pvText(PARAM *p, int id);
Request the text from the widget. The text will arrive in an TEXT_EVENT.
Allowed widgets: QLabel, QPushButton, QLineEdit
(32) int pvSetText(PARAM *p, int id, const char *text);
Set the text of a widget.
Allowed widgets: QLabel, QPushButton, QLineEdit
(33) int pvPrintf(PARAM *p, int id, const char *format, ...);
Set the text of a widget.
The functions works like printf()
Allowed widgets: QLabel, QPushButton, QLineEdit
(34) int pvSetGeometry(PARAM *p, int id, int x, int y, int w, int h);
Set the Geometry of the widget.
(35) int pvSetChecked(PARAM *p, int id, int state);
Set the state (0,1) of a button
Allowed widgets: QRadioButton, QCheckBox
(36) int pvSetBackgroundColor(PARAM *p, int id, int r, int g, int b);
Set the background color of the widget.
Allowed widgets: QLabel, QDraw
(37) int pvMove(PARAM *p, int id, int x, int y);
Move the widget to a new position.
(38) int pvResize(PARAM *p, int id, int w, int h);
Resize the widget.
(39) int pvHide(PARAM *p, int id);
Hide the widget.
(40) int pvShow(PARAM *p, int id);
Show the widget.
(41) int pvPrint(PARAM *p, int id);
Print the contents of the widget on a printer. The user will see the print dialog.
Allowed widgets: QImage, QDraw
(42) int pvGetText(const char *command, char *text);
The function will get the "" surrounded text out of command.
This is useful to retrieve the text from an event.
(43) int pvParseEvent(const char *event, int *id, char *text);
This fuction will parse the event. It returns the event. If there is a text in the event
it will be returned. Otherwise *text will be '\0'.
(44) int pvCopyToClipboard(PARAM *p, int id);
Copy the widget to the clipboard.
(45) int pvPrint(PARAM *p, int id);
Print the widget on a printer. The user will see the print dialog.
(46) int pvSave(PARAM *p, int id, const char *filename);
Save the widget to a file on the client computer. (vector form)
(47) int pvSetZoomX(PARAM *p, int id, float zoom);
Zoom the image in X direction. (default: zoom=1.0)
(48) int pvSetZoomY(PARAM *p, int id, float zoom);
Zoom the image in Y direction. (default: zoom=1.0)
(49) int pvDisplayNum(PARAM *p, int id, int num);
Display num on a QLCDNumber
(50) int pvDisplayFloat(PARAM *p, int id, float val);
Display float on a QLCDNumber
(51) int pvDisplayStr(PARAM *p, int id, const char *str);
Display string on a QLCDNumber
(52) int pvGlBegin(PARAM *p, int id);
Call this function when you want to begin with OpenGL commands
(53) int pvGlEnd(PARAM *p);
Call this function when you are finished with OpenGL commands
(54) int gBeginDraw(PARAM *p, int id);
Call this function before you start drawing the widget.
(55) int gBox(PARAM *p, int x, int y, int w, int h);
Draws a rectangle. Later you can use it's coordinates to draw xAxis, yAxiy and ryAxis.
(56) int gEndDraw(PARAM *p);
Call this function when you are finished with drawing.
(57) int gLineTo(PARAM *p, int x, int y);
Draw a line from the actual position to x,y.
(58) int gLine(PARAM *p, float *x, float *y, int n);
Draw a line in a Axis n=number of values in x,y.
(59) int gMoveTo(PARAM *p, int x, int y);
Move to x,y.
(60) int gRightYAxis(PARAM *p, float start, float delta, float end, int draw);
Draw a Axis on the right side of the diagram.
It starts with start in steps of delta until end is reached.
(61) int gSetColor(PARAM *p, int r, int g, int b);
Set the drawing color.
(62) int gSetWidth(PARAM *p, int w);
Set the line width
(63) int gSetStyle(PARAM *p, int style);
style=0 SolidLine
style=1 DotLine
(64) int gDrawArc(PARAM *p, int x, int y, int w, int h, int start_angle, int angle_length);
Draw an arc. For circle write:
gDrawArc(p,x-radius/2,y-radius/2,radius/2,radius/2,0,360);
(65) int gDrawPie(PARAM *p, int x, int y, int w, int h, int start_angle, int angle_length);
Draw an pie (filled part of a circle) . For filled circle write:
gDrawArc(p,x-radius/2,y-radius/2,radius/2,radius/2,0,360);
(66) int gDrawPolygon(PARAM *p, int *x, int *y, int n);
x,y is an array with the edge points.
n is the number of points
(67) int gSetFont(PARAM *p, const char *family, int size, int weight, int italic);
Set a font. For the availabe fonts see Definitions (Events, Fonts, Colors ...)
(68) int gSetLinestyle(PARAM *p, int style);
Set the linestyle of a line in the Axis. You can draw a simple line or a line with centered symbols.
(69) int gText(PARAM *p, int x, int y, const char *text, int alignment);
Draw a text at x,y.
For alignment see Definitions (Events, Fonts, Colors ...)
(70) int gXAxis(PARAM *p, float start, float delta, float end, int draw);
Draw a Axis on the bottom of the diagram.
It starts with start in steps of delta until end is reached.
(71) int gYAxis(PARAM *p, float start, float delta, float end, int draw);
Draw a Axis on the left side of the diagram.
It starts with start in steps of delta until end is reached.
(72) int gXGrid(PARAM *p);
Draw a grid orthogonal to the x-axis in the diagram.
(73) int gYGrid(PARAM *p);
Draw a grid orthogonal to the y-axis in the diagram.
(74) int gBoxWithText(PARAM *p, int x, int y, int w, int h, int fontsize, const char *xlabel, const char *ylabel, const char *rylabel);
This is a convenience function that draws a box and write the xlabel ylabel and rylabel
in the given font.
If one of the text parameters is NULL no text is drawn for that item.
(75) int gComment(PARAM *p, const char *comment);
Write a comment in the metafile
(76) int pvSendFile(PARAM *p, const char *filename);
send file to browser