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>
53 #define h_addr h_addr_list[0]
73 struct sockaddr_in serv_addr;
74 struct hostent* server;
89 sockfd = socket(AF_INET, SOCK_STREAM, 0);
91 perror(
"CrFwClientSocketInitAction, Socket Creation");
97 if ((flags = fcntl(
sockfd, F_GETFL, 0)) < 0) {
98 perror(
"CrFwClientSocketInitAction, Set socket attributes");
102 if (fcntl(
sockfd, F_SETFL, flags | O_NONBLOCK) < 0) {
103 perror(
"CrFwClientSocketInitAction, Set socket attributes");
109 if (server == NULL) {
110 perror(
"CrFwClientSocketInitAction, Get host name");
115 bzero((
char*) &serv_addr,
sizeof(serv_addr));
116 serv_addr.sin_family = AF_INET;
117 bcopy((
char*)server->h_addr,
118 (
char*)&serv_addr.sin_addr.s_addr,
119 (
long unsigned int)server->h_length);
120 serv_addr.sin_port = (
unsigned short int)htons(
portno);
122 if (connect(
sockfd,(
struct sockaddr*) &serv_addr,
sizeof(serv_addr)) < 0) {
123 if (errno != EINPROGRESS) {
124 perror(
"CrFwClientSocketInitAction, Connect Socket");
146 perror(
"CrFwClientSocketShutdownAction, Incorrect caller type");
192 perror(
"CrFwClientSocketConfigAction, Incorrect caller type");
214 printf(
"CrFwClientSocketPoll: ERROR reading from socket\n");
224 printf(
"CrFwClientSocketPoll: invalid packet received from socket\n");
237 for (i=0; i<nofPcktSrc; i++) {
238 if (pcktSrc == pcktSrcs[i]) {
264 printf(
"CrFwClientSocketIsPcktAvail: ERROR reading from socket\n");
269 for (i=0; i<nofPcktSrc; i++) {
270 if (pcktSrc == pcktSrcs[i])
277 printf(
"CrFwClientSocketIsPcktAvail: invalid packet received from socket\n");
290 n = write(
sockfd, pckt, len);
296 printf(
"CrFwClientSocketPcktHandover: error writing to socket\n");
Definition of Base Component.
CrFwPckt_t CrFwClientSocketPcktCollect(CrFwDestSrc_t nofPcktSrc, CrFwDestSrc_t *pcktSrcs)
Function implementing the Packet Collect Operation for the client socket.
void CrFwClientSocketSetPort(unsigned short n)
Set the port number for the socket.
void CrFwClientSocketSetHost(char *name)
Set the host name of the server.
static unsigned int pcktMaxLength
The maximum size of an incoming packet.
void CrFwClientSocketInitCheck(FwPrDesc_t prDesc)
Initialization check for the client socket.
void CrFwClientSocketPoll()
Poll the client socket to check whether a new packet has arrived.
static unsigned char * readBuffer
The Read Buffer.
static char * hostName
The host name.
void CrFwClientSocketConfigAction(FwPrDesc_t prDesc)
Configuration action for the client socket.
void CrFwClientSocketInitAction(FwPrDesc_t prDesc)
Initialization action for the client socket.
CrFwBool_t CrFwClientSocketIsPcktAvail(CrFwDestSrc_t nofPcktSrc, CrFwDestSrc_t *pcktSrcs)
Function implementing the Packet Available Check Operation for the client socket.
CrFwBool_t CrFwClientSocketPcktHandover(CrFwPckt_t pckt)
Function implementing the hand-over operation for the client socket.
static int sockfd
The file descriptor for the socket.
void CrFwClientSocketShutdownAction(FwSmDesc_t smDesc)
Shutdown action for the client socket.
static unsigned short portno
The port number.
Interface for a client socket to be used by InStreams and OutStreams.
Definition of the Framework Component Data (FCD) Type.
Header file to define all invariant publicly available constants and types for the CORDET Framework.
#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.
User-modifiable parameters for the InStream components (see CrFwInStream.h).
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.
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.
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.