23 #include "FwSmConstants.h" 24 #include "FwSmConfig.h" 26 #include "FwPrConfig.h" 28 #include "FwPrConstants.h" 44 #include <sys/types.h> 45 #include <sys/socket.h> 46 #include <netinet/in.h> 83 struct sockaddr_in serv_addr, cli_addr;
84 pthread_t acceptThread;
101 sockfd = socket(AF_INET, SOCK_STREAM, 0);
103 perror(
"CrFwServerSocketInitAction, Socket creation");
108 bzero((
char*) &serv_addr,
sizeof(serv_addr));
109 serv_addr.sin_family = AF_INET;
110 serv_addr.sin_addr.s_addr = INADDR_ANY;
111 serv_addr.sin_port = htons(
portno);
112 if (bind(
sockfd, (
struct sockaddr*) &serv_addr,
sizeof(serv_addr)) < 0) {
113 perror(
"CrFwServerSocketInitAction, Bind Socket");
121 pthread_attr_init(&attr);
122 if (pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED) != 0) {
123 perror(
"CrFwServerSocketInitAction, set detached state");
148 perror(
"CrFwServerSocketShutdownAction, Incorrect caller type");
189 printf(
"CrFwServerSocketPoll: ERROR reading from socket\n");
200 printf(
"CrFwServerSocketPoll: invalid packet received from socket\n");
213 if (src == pcktSrc) {
215 memcpy(pckt, readBuffer, readBuffer[0]);
238 printf(
"CrFwServerSocketIsPcktAvail: ERROR reading from socket\n");
250 printf(
"CrFwServerSocketIsPcktAvail: invalid packet received from socket\n");
269 printf(
"CrFwServerSocketPcktHandover: error writing to socket\n");
284 perror(
"CrFwServerSocketInitAction, Socket Accept");
288 if ((flags = fcntl(
newsockfd, F_GETFL, 0)) < 0) {
289 perror(
"CrFwServerSocketInitAction, Set socket attributes");
292 if (fcntl(
newsockfd, F_SETFL, flags | O_NONBLOCK) < 0) {
293 perror(
"CrFwServerSocketInitAction, Set socket attributes");
void CrFwOutStreamDefConfigAction(FwPrDesc_t prDesc)
Default configuration action for an OutStream.
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.
Definition of the Framework Component Data (FCD) Type.
Interface for a server socket to be used by InStreams and OutStreams.
unsigned char * CrFwPckt_t
Type for packets (see CrFwPckt.h).
CrFwPckt_t CrFwPcktMake(CrFwPcktLength_t pcktLength)
Make function for command or report packets.
CrFwDestSrc_t CrFwPcktGetSrc(CrFwPckt_t pckt)
Return the source of the command or report encapsulated in a packet.
static socklen_t clilen
Socket variable.
Definition of the OutStream component.
void CrFwServerSocketConfigAction(FwPrDesc_t prDesc)
Configuration action for the server socket.
#define CR_FW_INSTREAM_TYPE
Type identifier for the InStream components.
CrFwBool_t CrFwServerSocketPcktHandover(CrFwPckt_t pckt)
Function implementing the hand-over operation for the server socket.
Interface for creating and accessing a report or command packet.
void CrFwServerSocketInitAction(FwPrDesc_t prDesc)
Initialization action for the server socket.
int CrFwBool_t
Type used for boolean values (1 represent "true" and 0 represents "false").
static int sockfd
The file descriptors for the socket.
static struct sockaddr_in cli_addr
Socket variable.
void CrFwServerSocketPoll()
Poll the server socket to check whether a new packet has arrived.
CrFwBool_t CrFwServerSocketIsPcktAvail(CrFwDestSrc_t src)
Function implementing the Packet Available Check Operation for the server socket. ...
static unsigned short portno
Set the port number (must be same as the port number specified in CrFwServerSocket.c
unsigned char CrFwDestSrc_t
Type used for the command or report destination and source.
Interface for reporting an error detected by a framework component.
void CrFwInStreamDefInitAction(FwPrDesc_t prDesc)
Default initialization action for an InStream.
void CrFwServerSocketConfigCheck(FwPrDesc_t prDesc)
Configuration check for the server socket.
static unsigned char * readBuffer
The Read Buffer.
CrFwPckt_t CrFwServerSocketPcktCollect(CrFwDestSrc_t src)
Function implementing the Packet Collect Operation for the server socket.
Definition of the utility functions for the CORDET Framework.
CrFwPcktLength_t CrFwPcktGetMaxLength()
Return the maximum length of a packet in number of bytes.
void CrFwOutStreamDefShutdownAction(FwSmDesc_t smDesc)
Default shutdown action for an OutStream.
void CrFwOutStreamDefInitAction(FwPrDesc_t prDesc)
Default initialization action for an OutStream.
void CrFwInStreamDefShutdownAction(FwSmDesc_t smDesc)
Default shutdown action for an InStream.
static int newsockfd
The file descriptors for the socket.
Definition of Base Component.
CrFwPcktLength_t CrFwPcktGetLength(CrFwPckt_t pckt)
Return the length (in number of bytes) of a packet.
static CrFwCmpData_t outStreamData[CR_FW_NOF_OUTSTREAM]
The base data structures for the OutStream State Machines and their Procedures.
The CORDET Framework defines an interface for generating error reports (see CrFwRepErr.h).
unsigned short int CrFwPcktLength_t
Type for the packet length.
static void * acceptThreadEntry(void *ptr)
Entry point for the thread which waits for the incoming connection from the client socket...
FwSmDesc_t CrFwInStreamMake(CrFwInstanceId_t i)
Factory function to retrieve the i-th InStream State Machine instance.
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.
static unsigned int pcktMaxLength
The maximum size of an incoming packet.
#define CR_FW_OUTSTREAM_TYPE
Type identifier for the OutStream components.
void CrFwServerSocketSetPort(unsigned short n)
Set the port number for the socket.
User-modifiable parameters for the OutStream components (see CrFwOutStream.h).
void CrFwServerSocketInitCheck(FwPrDesc_t prDesc)
Initialization check for the server socket.
void CrFwServerSocketShutdownAction(FwSmDesc_t smDesc)
Shutdown action for the server socket.