25 #include "FwSmConstants.h" 26 #include "FwSmConfig.h" 28 #include "FwPrConfig.h" 30 #include "FwPrConstants.h" 32 #include "CrFwOutStreamUserPar.h" 33 #include "CrFwCmpData.h" 46 #include <sys/types.h> 47 #include <sys/socket.h> 48 #include <netinet/in.h> 108 struct sockaddr_in serv_addr, cli_addr;
109 pthread_t acceptThread;
127 sockfd = socket(AF_INET, SOCK_STREAM, 0);
129 perror(
"CrDaServerSocketInitAction, Socket creation");
134 bzero((
char*) &serv_addr,
sizeof(serv_addr));
135 serv_addr.sin_family = AF_INET;
136 serv_addr.sin_addr.s_addr = INADDR_ANY;
137 serv_addr.sin_port = htons(
portno);
138 if (bind(
sockfd, (
struct sockaddr*) &serv_addr,
sizeof(serv_addr)) < 0) {
139 perror(
"CrDaServerSocketInitAction, Bind Socket");
147 pthread_attr_init(&attr);
148 if (pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED) != 0) {
149 perror(
"CrDaServerSocketInitAction, set detached state");
210 if (buffer[0] != 0) {
221 printf(
"CrDaServerSocketPoll: Error reading from socket\n");
224 if (n == buffer[0]) {
230 if (n != buffer[0]) {
231 printf(
"CrDaServerSocketPoll: invalid packet received from socket\n");
256 if (buffer[0] != 0) {
258 if (src == pcktSrc) {
260 memcpy(pckt, buffer, buffer[0]);
285 if (buffer[0] != 0) {
293 printf(
"CrDaServerSocketPoll: Error reading from socket\n");
297 if (n == buffer[0]) {
305 if (n != buffer[0]) {
306 printf(
"CrDaServerSocketIsPcktAvail: invalid packet received from socket");
330 printf(
"CrDaServerSocketPcktHandover: error writing to socket\n");
341 printf(
"S1: Waiting for client socket in Master Application to connect ...\n");
344 perror(
"CrDaServerSocketInitAction, Socket Accept");
348 if ((flags = fcntl(
newsockfd[0], F_GETFL, 0)) < 0) {
349 perror(
"CrDaServerSocketInitAction, Set socket attributes");
352 if (fcntl(
newsockfd[0], F_SETFL, flags | O_NONBLOCK) < 0) {
353 perror(
"CrDaServerSocketInitAction, Set socket attributes");
356 printf(
"S1: Client socket in Master Application successfully connected.\n");
358 printf(
"S1: Waiting for client socket in Slave 2 Application to connect ...\n");
361 perror(
"CrDaServerSocketInitAction, Socket Accept");
365 if ((flags = fcntl(
newsockfd[1], F_GETFL, 0)) < 0) {
366 perror(
"CrDaServerSocketInitAction, Set socket attributes");
369 if (fcntl(
newsockfd[1], F_SETFL, flags | O_NONBLOCK) < 0) {
370 perror(
"CrDaServerSocketInitAction, Set socket attributes");
373 printf(
"S1: Client socket in Slave 2 Application successfully connected.\n");
void CrFwOutStreamDefConfigAction(FwPrDesc_t prDesc)
Default configuration action for an OutStream.
#define CR_DA_MASTER
The identifier of the Master Application of the CORDET Demo.
void CrDaServerSocketInitCheck(FwPrDesc_t prDesc)
Initialization check for the server socket.
Type for the Framework Component Data (FCD).
Interface through which framework components access the current time.
CrFwOutcome_t outcome
The outcome of an action or check executed by a state machine or by one of its procedures.
CrFwDestSrc_t CrFwPcktGetSrc(CrFwPckt_t pckt)
Return the source of the command or report encapsulated in a packet.
static void * acceptThreadEntry(void *ptr)
Entry point for the thread which waits for the incoming connection from the client socket...
unsigned char * CrFwPckt_t
Type for packets (see CrFwPckt.h).
static struct sockaddr_in cli_addr
Socket variable.
Definition of the OutStream component.
unsigned char CrFwDestSrc_t
Type used for the command or report destination and source.
static int newsockfd[2]
The file descriptors for the client sockets.
CrFwPckt_t CrFwPcktMake(CrFwPcktLength_t pcktLength)
Make function for command or report packets.
#define CR_FW_INSTREAM_TYPE
Type identifier for the InStream components.
Interface for creating and accessing a report or command packet.
int CrFwBool_t
Type used for boolean values (1 represent "true" and 0 represents "false").
static CrFwBool_t serverSocketIsPcktAvail(CrFwDestSrc_t src, int nsockfd, unsigned char *buffer)
Check whether a packet from the argument source is available.
CrFwDestSrc_t CrFwPcktGetDest(CrFwPckt_t pckt)
Return the destination of the command or report encapsulated in a packet.
Interface for reporting an error detected by a framework component.
void CrFwInStreamDefInitAction(FwPrDesc_t prDesc)
Default initialization action for an InStream.
void CrDaServerSocketInitAction(FwPrDesc_t prDesc)
Initialization action for the server socket.
CrFwPcktLength_t CrFwPcktGetLength(CrFwPckt_t pckt)
Return the length (in number of bytes) of a packet.
CrFwPckt_t CrDaServerSocketPcktCollect(CrFwDestSrc_t src)
Function implementing the Packet Collect Operation for the server socket.
CrFwBool_t CrDaServerSocketIsPcktAvail(CrFwDestSrc_t src)
Function implementing the Packet Available Check Operation for the server socket. ...
unsigned short int CrFwPcktLength_t
Type for the packet length.
void CrDaServerSocketPoll()
Poll the server socket to check whether a new packet has arrived from either client.
CrFwPcktLength_t CrFwPcktGetMaxLength()
Return the maximum length of a packet in number of bytes.
void CrDaServerSocketConfigAction(FwPrDesc_t prDesc)
Configuration action for the server socket.
Definition of the utility functions for the CORDET Framework.
void CrFwOutStreamDefShutdownAction(FwSmDesc_t smDesc)
Default shutdown action for an OutStream.
void CrFwOutStreamDefInitAction(FwPrDesc_t prDesc)
Default initialization action for an OutStream.
void CrDaServerSocketSetPort(int n)
Set the port number for the socket.
static int portno
Set the port number (must be same as the port number specified in CrDaServerSocket.c
CrFwBool_t CrDaServerSocketPcktHandover(CrFwPckt_t pckt)
Function implementing the hand-over operation for the server socket.
void CrFwInStreamDefShutdownAction(FwSmDesc_t smDesc)
Default shutdown action for an InStream.
FwSmDesc_t CrFwInStreamGet(CrFwDestSrc_t src)
Getter function for the InStream corresponding to the argument source.
Definition of Base Component.
static CrFwDestSrc_t dest
Destination.
static CrFwCmpData_t outStreamData[CR_FW_NOF_OUTSTREAM]
The base data structures for the OutStream State Machines and their Procedures.
void CrDaServerSocketConfigCheck(FwPrDesc_t prDesc)
Configuration check for the server socket.
Interface for the server socket used in the CORDET Demo.
Header file to define constants and types for the CORDET Demo.
CrFwTypeId_t typeId
The type identifier of the framework component.
void CrFwInStreamDefConfigAction(FwPrDesc_t prDesc)
Default configuration action for an InStream.
void CrFwInStreamPcktAvail(FwSmDesc_t smDesc)
Query the middleware for available packets and collect them if they are available.
void CrDaServerSocketShutdownAction(FwSmDesc_t smDesc)
Shutdown action for the server socket.
static unsigned char * readBuffer[2]
The Read Buffers.
static void serverSocketPoll(int nsockfd, unsigned char *buffer)
Poll the socket for data from one of the two clients.
static int pcktMaxLength
The maximum size of an incoming packet.
static int sockfd
The file descriptors for the socket.
static CrFwPckt_t serverSocketPcktCollect(CrFwDestSrc_t src, unsigned char *buffer)
Collect a packet from the argument source.
static socklen_t clilen
Socket variable.