|
rllib
1
|
#include <rlspawn.h>
Public Member Functions | |
| rlSpawn () | |
| virtual | ~rlSpawn () |
| int | spawn (const char *command) |
| const char * | readLine () |
| int | getchar () |
| int | select (int timeout=50) |
| int | writeString (const char *buf) |
| int | write (const char *buf, int len) |
| int | printf (const char *format,...) |
| void | printAll () |
| FILE * | getFilepointer () |
| int | sigkill () |
| int | readJpegBuffer (unsigned char *buffer, int maxbuffer) |
Public Attributes | |
| int | pid |
Private Attributes | |
| HANDLE | toChildRD |
| HANDLE | toChildWR |
| HANDLE | fromChildRD |
| HANDLE | fromChildWR |
| HANDLE | hThread |
| HANDLE | hProcess |
| char | line [4096] |
Spawn an external program. Redirect <stdin> <stdout> <stderr> of external program to this class
Now you can communicate with this external program over a pipe. Attention: This class is only available on unix like systems.
| rlSpawn::rlSpawn | ( | ) |
Definition at line 137 of file rlspawn.cpp.
|
virtual |
Definition at line 153 of file rlspawn.cpp.
| int rlSpawn::getchar | ( | ) |
Read a char from the spawned command. When the command terminates EOF is returned.
Definition at line 355 of file rlspawn.cpp.
| FILE * rlSpawn::getFilepointer | ( | ) |
Get FILE pointer fromChild
Definition at line 488 of file rlspawn.cpp.
| void rlSpawn::printAll | ( | ) |
| int rlSpawn::printf | ( | const char * | format, |
| ... | |||
| ) |
similar to printf
Return: number of bytes written
-1 error
Definition at line 402 of file rlspawn.cpp.
| int rlSpawn::readJpegBuffer | ( | unsigned char * | buffer, |
| int | maxbuffer | ||
| ) |
Read JPEG buffer fromChild return: length of buffer | -1 as error
Example: A thread continiously reads the mjpeg output of ffmpeg and stores it in jpegBuffer
rlThread mythread; unsigned char jpegBuffer[256*256*16];
void *myThread(void *arg) // define your thread function
{
rlSpawn spawn;restart: if(arg == NULL) return NULL;
THREAD_PARAM *p = (THREAD_PARAM *) arg; //myThreadsData *d = (myThreadsData *) p->user; spawn.spawn("ffmpeg -f video4linux2 -i /dev/v4l/by-id/usb-046d_0825_A867B3D0-video-index0 -vf \"transpose, hflip" -r 10 -f mjpeg pipe:1"); while(p->running) { int ret = spawn.readJpegBuffer(jpegBuffer,sizeof(jpegBuffer)); printf("ret=%d\n",ret); if(ret < 0) goto restart; } return arg; }
Example: The jpegBuffer can now be Send to a Image Widget on the pvbrowser client
extern rlThread mythread; extern unsigned char jpegBuffer[];
static int slotNullEvent(PARAM *p, DATA *d)
{
if(p == NULL || d == NULL) return -1;
pvSendJpegFrame(p,imgWebcam,jpegBuffer);
return 0;
}
Definition at line 526 of file rlspawn.cpp.
| const char * rlSpawn::readLine | ( | ) |
Read a line from the spawned command. When the command terminates NULL is returned.
Definition at line 307 of file rlspawn.cpp.
| int rlSpawn::select | ( | int | timeout = 50 | ) |
Wait for characters. return = 0 // timeout return = 1 // characters available
Definition at line 456 of file rlspawn.cpp.
| int rlSpawn::sigkill | ( | ) |
| int rlSpawn::spawn | ( | const char * | command | ) |
Start an operating system command. The output from the command can be read with readLine() You can write to the program with writeString() or write() Return: 0=success -1=error
Definition at line 168 of file rlspawn.cpp.
| int rlSpawn::write | ( | const char * | buf, |
| int | len | ||
| ) |
Write buf to <stdin> of spawned command
Return: number of bytes written
-1 error
Definition at line 385 of file rlspawn.cpp.
| int rlSpawn::writeString | ( | const char * | buf | ) |
Write buf to <stdin> of spawned command
buf must be 0 terminated
Return: number of bytes written
-1 error
Definition at line 415 of file rlspawn.cpp.
1.8.14