My Project
 All Classes Files Functions Variables Macros
Macros | Functions | Variables
mainReceiver.cpp File Reference
#include "sls_receiver_defs.h"
#include "slsReceiverUsers.h"
#include <iostream>
#include <string.h>
#include <signal.h>
#include <cstdlib>
#include <sys/types.h>
#include <sys/wait.h>
#include <string>
#include <unistd.h>
#include <errno.h>
#include <syscall.h>

Go to the source code of this file.

Macros

#define PRINT_IN_COLOR(c, f,...)   printf ("\033[%dm" f RESET, 30 + c+1, ##__VA_ARGS__)
 

Functions

void sigInterruptHandler (int p)
 
void printHelp ()
 
int StartAcq (char *filepath, char *filename, uint64_t fileindex, uint32_t datasize, void *p)
 
void AcquisitionFinished (uint64_t frames, void *p)
 
void GetData (char *metadata, char *datapointer, uint32_t datasize, void *p)
 
void GetData (char *metadata, char *datapointer, uint32_t &revDatasize, void *p)
 
int main (int argc, char *argv[])
 

Variables

bool keeprunning
 

Detailed Description

This file is an example of how to implement the slsReceiverUsers class You can compile it linking it to the slsReceiver library

g++ mainReceiver.cpp -L lib -lSlsReceiver -L/usr/lib64/ -L lib2 -lzmq -pthread -lrt -lm -lstdc++

where,

lib is the location of lSlsReceiver.so

lib2 is the location of the libzmq.a. [ libzmq.a is required only when using data call backs and enabling data streaming from receiver to client. It is linked in manual/manual-api from slsReceiverSoftware/include ]

Definition in file mainReceiver.cpp.

Macro Definition Documentation

#define PRINT_IN_COLOR (   c,
  f,
  ... 
)    printf ("\033[%dm" f RESET, 30 + c+1, ##__VA_ARGS__)

Define Colors to print data call back in different colors for different recievers

Definition at line 38 of file mainReceiver.cpp.

Function Documentation

void AcquisitionFinished ( uint64_t  frames,
void *  p 
)

Acquisition Finished Call back

Parameters
framesNumber of frames caught
ppointer to object

Definition at line 85 of file mainReceiver.cpp.

void GetData ( char *  metadata,
char *  datapointer,
uint32_t  datasize,
void *  p 
)

Get Receiver Data Call back Prints in different colors(for each receiver process) the different headers for each image call back.

Parameters
metadatasls_receiver_header metadata
datapointerpointer to data
datasizedata size in bytes.
ppointer to object

Definition at line 98 of file mainReceiver.cpp.

void GetData ( char *  metadata,
char *  datapointer,
uint32_t &  revDatasize,
void *  p 
)

Get Receiver Data Call back (modified) Prints in different colors(for each receiver process) the different headers for each image call back.

Parameters
metadatasls_receiver_header metadata
datapointerpointer to data
datasizedata size in bytes.
revDatasizenew data size in bytes after the callback. This will be the size written/streamed. (only smaller value is allowed).
ppointer to object

Definition at line 132 of file mainReceiver.cpp.

int main ( int  argc,
char *  argv[] 
)

Example of main program using the slsReceiverUsers class

  • Defines in file for:
    • Default Number of receivers is 1
    • Default Start TCP port is 1954
  • set default values
  • get number of receivers and start tcp port from command line arguments
  • Catch signal SIGINT to close files and call destructors properly
    • Ignore SIG_PIPE, prevents global signal handler, handle locally, instead of a server crashing due to client crash when writing, it just gives error
  • loop over number of receivers
  • fork process to create child process
  • if fork failed, raise SIGINT and properly destroy all child processes
  • if child process
  • create slsReceiverUsers object with appropriate arguments
     - register callbacks. remember to set file write enable to 0 (using the client)
    
    if we should not write files and you will write data using the callbacks
  • Call back for start acquisition
  • Call back for acquisition finished
  • start tcp server thread
  • as long as keeprunning is true (changes with Ctrl+C)
  • interrupt caught, delete slsReceiverUsers object and exit
  • Parent process ignores SIGINT (exits only when all child process exits)
  • Print Ready and Instructions how to exit
  • Parent process waits for all child processes to exit

Definition at line 167 of file mainReceiver.cpp.

void printHelp ( )

prints usage of this example program

Definition at line 55 of file mainReceiver.cpp.

void sigInterruptHandler ( int  p)

Control+C Interrupt Handler Sets the variable keeprunning to false, to let all the processes know to exit properly

Definition at line 48 of file mainReceiver.cpp.

int StartAcq ( char *  filepath,
char *  filename,
uint64_t  fileindex,
uint32_t  datasize,
void *  p 
)

Start Acquisition Call back slsReceiver writes data if file write enabled. Users get data to write using call back if registerCallBackRawDataReady is registered.

Parameters
filepathfile path
filenamefile name
fileindexfile index
datasizedata size in bytes
ppointer to object
Returns
ignored

Definition at line 72 of file mainReceiver.cpp.

Variable Documentation

bool keeprunning

Variable is true to continue running, set to false upon interrupt

Definition at line 42 of file mainReceiver.cpp.