23 #include "FwSmConstants.h"
24 #include "FwSmConfig.h"
26 #include "FwPrConfig.h"
28 #include "FwPrConstants.h"
45 #include <sys/types.h>
46 #include <sys/socket.h>
47 #include <netinet/in.h>
84 struct sockaddr_in serv_addr,
cli_addr;
85 pthread_t acceptThread;
102 sockfd = socket(AF_INET, SOCK_STREAM, 0);
104 perror(
"CrFwServerSocketInitAction, Socket creation");
109 bzero((
char*) &serv_addr,
sizeof(serv_addr));
110 serv_addr.sin_family = AF_INET;
111 serv_addr.sin_addr.s_addr = INADDR_ANY;
112 serv_addr.sin_port = htons(
portno);
113 if (bind(
sockfd, (
struct sockaddr*) &serv_addr,
sizeof(serv_addr)) < 0) {
114 perror(
"CrFwServerSocketInitAction, Bind Socket");
122 pthread_attr_init(&attr);
123 if (pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED) != 0) {
124 perror(
"CrFwServerSocketInitAction, set detached state");
149 perror(
"CrFwServerSocketShutdownAction, Incorrect caller type");
190 printf(
"CrFwServerSocketPoll: ERROR reading from socket\n");
200 printf(
"CrFwServerSocketPoll: invalid packet received from socket\n");
213 for (i=0; i<nofPcktSrc; i++) {
214 if (pcktSrc == pcktSrcs[i]) {
240 printf(
"CrFwServerSocketIsPcktAvail: ERROR reading from socket\n");
245 for (i=0; i<nofPcktSrc; i++) {
246 if (pcktSrc == pcktSrcs[i])
253 printf(
"CrFwServerSocketIsPcktAvail: invalid packet received from socket\n");
272 printf(
"CrFwServerSocketPcktHandover: error writing to socket\n");
287 perror(
"CrFwServerSocketInitAction, Socket Accept");
291 if ((flags = fcntl(
newsockfd, F_GETFL, 0)) < 0) {
292 perror(
"CrFwServerSocketInitAction, Set socket attributes");
295 if (fcntl(
newsockfd, F_SETFL, flags | O_NONBLOCK) < 0) {
296 perror(
"CrFwServerSocketInitAction, Set socket attributes");
Definition of Base Component.
Definition of the Framework Component Data (FCD) Type.
#define CR_FW_OUTSTREAM_TYPE
Type identifier for the OutStream components.
unsigned char * CrFwPckt_t
Type for packets (see CrFwPckt.h).
int CrFwBool_t
Type used for boolean values (1 represent "true" and 0 represents "false").
#define CR_FW_INSTREAM_TYPE
Type identifier for the InStream components.
void CrFwInStreamDefInitAction(FwPrDesc_t prDesc)
Default initialization action for an InStream.
void CrFwInStreamDefConfigAction(FwPrDesc_t prDesc)
Default configuration action for an InStream.
FwSmDesc_t CrFwInStreamGet(CrFwDestSrc_t src)
Getter function for the InStream corresponding to the argument source.
void CrFwInStreamDefShutdownAction(FwSmDesc_t smDesc)
Default shutdown action for an InStream.
void CrFwInStreamPcktAvail(FwSmDesc_t smDesc)
Query the middleware for available packets and collect them if they are available.
Definition of the InStream component.
void CrFwOutStreamDefConfigAction(FwPrDesc_t prDesc)
Default configuration action for an OutStream.
void CrFwOutStreamDefInitAction(FwPrDesc_t prDesc)
Default initialization action for an OutStream.
void CrFwOutStreamDefShutdownAction(FwSmDesc_t smDesc)
Default shutdown action for an OutStream.
static CrFwCmpData_t outStreamData[CR_FW_NOF_OUTSTREAM]
The base data structures for the OutStream State Machines and their Procedures.
Definition of the OutStream component.
User-modifiable parameters for the OutStream components (see CrFwOutStream.h).
Interface for creating and accessing a report or command packet.
CrFwDestSrc_t CrFwPcktGetSrc(CrFwPckt_t pckt)
Return the source of the command or report encapsulated in a packet.
CrFwPcktLength_t CrFwPcktGetMaxLength()
Return the maximum length of a packet in number of bytes.
CrFwPcktLength_t CrFwPcktGetLength(CrFwPckt_t pckt)
Return the length (in number of bytes) of a packet.
CrFwPckt_t CrFwPcktMake(CrFwPcktLength_t pcktLength)
Make function for command or report packets.
Interface for reporting an error detected by a framework component.
The CORDET Framework defines an interface for generating error reports (see CrFwRepErr....
static unsigned int pcktMaxLength
The maximum size of an incoming packet.
CrFwPckt_t CrFwServerSocketPcktCollect(CrFwDestSrc_t nofPcktSrc, CrFwDestSrc_t *pcktSrcs)
Function implementing the Packet Collect Operation for the server socket.
void CrFwServerSocketInitCheck(FwPrDesc_t prDesc)
Initialization check for the server socket.
static socklen_t clilen
Socket variable.
static unsigned char * readBuffer
The Read Buffer.
CrFwBool_t CrFwServerSocketIsPcktAvail(CrFwDestSrc_t nofPcktSrc, CrFwDestSrc_t *pcktSrcs)
Function implementing the Packet Available Check Operation for the server socket.
void CrFwServerSocketConfigCheck(FwPrDesc_t prDesc)
Configuration check for the server socket.
static struct sockaddr_in cli_addr
Socket variable.
static void * acceptThreadEntry(void *ptr)
Entry point for the thread which waits for the incoming connection from the client socket.
void CrFwServerSocketConfigAction(FwPrDesc_t prDesc)
Configuration action for the server socket.
void CrFwServerSocketShutdownAction(FwSmDesc_t smDesc)
Shutdown action for the server socket.
void CrFwServerSocketPoll()
Poll the server socket to check whether a new packet has arrived.
void CrFwServerSocketInitAction(FwPrDesc_t prDesc)
Initialization action for the server socket.
void CrFwServerSocketSetPort(unsigned short n)
Set the port number for the socket.
static int sockfd
The file descriptors for the socket.
static int newsockfd
The file descriptors for the socket.
CrFwBool_t CrFwServerSocketPcktHandover(CrFwPckt_t pckt)
Function implementing the hand-over operation for the server socket.
static unsigned short portno
Set the port number (must be same as the port number specified in CrFwServerSocket....
Interface for a server socket to be used by InStreams and OutStreams.
Interface through which framework components access the current time.
unsigned char CrFwDestSrc_t
Type used for the command or report destination and source.
unsigned short int CrFwPcktLength_t
Type for the packet length.
Definition of the utility functions for the CORDET Framework.
Type for the Framework Component Data (FCD).
CrFwOutcome_t outcome
The outcome of an action or check executed by a state machine or by one of its procedures.
CrFwTypeId_t typeId
The type identifier of the framework component.