summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTimo Lotterbach <timo.lotterbach@bmw-carit.de>2013-06-17 10:33:24 +0200
committerTimo Lotterbach <timo.lotterbach@bmw-carit.de>2013-07-05 12:56:48 +0200
commit725c5a0587e9db420b1ffaa3f8bf05c42fb443b4 (patch)
tree85f3ce54a5167ddd0f3fe1dff7432b2b678abb93
parent093514e41360918394a11793fb8a7e15b2351435 (diff)
downloadlayer_management-725c5a0587e9db420b1ffaa3f8bf05c42fb443b4.tar.gz
TcpIpcModule: fixed several C90 compiler warnings
Signed-off-by: Timo Lotterbach <timo.lotterbach@bmw-carit.de>
-rw-r--r--LayerManagerPlugins/IpcModules/TcpIpcModule/include/socketConfiguration.h10
-rw-r--r--LayerManagerPlugins/IpcModules/TcpIpcModule/include/socketShared.h27
-rw-r--r--LayerManagerPlugins/IpcModules/TcpIpcModule/src/append.c38
-rw-r--r--LayerManagerPlugins/IpcModules/TcpIpcModule/src/get.c45
-rw-r--r--LayerManagerPlugins/IpcModules/TcpIpcModule/src/initialization.c48
-rw-r--r--LayerManagerPlugins/IpcModules/TcpIpcModule/src/message.c79
6 files changed, 128 insertions, 119 deletions
diff --git a/LayerManagerPlugins/IpcModules/TcpIpcModule/include/socketConfiguration.h b/LayerManagerPlugins/IpcModules/TcpIpcModule/include/socketConfiguration.h
index cd00331..6b9fb32 100644
--- a/LayerManagerPlugins/IpcModules/TcpIpcModule/include/socketConfiguration.h
+++ b/LayerManagerPlugins/IpcModules/TcpIpcModule/include/socketConfiguration.h
@@ -20,9 +20,11 @@
#ifndef _SOCKETCONFIGURATION_H_
#define _SOCKETCONFIGURATION_H_
-//=============================================================================
-// tcp socket configuration
-//=============================================================================
+/*
+ * =============================================================================
+ * tcp socket configuration
+ * =============================================================================
+ */
#define SOCKET_TCP_HOST "localhost"
#define SOCKET_TCP_PORT 22232
#define SOCKET_MAX_MESSAGE_SIZE 1024
@@ -38,4 +40,4 @@
#define ENV_TCP_HOST "LM_TCP_HOST"
#define ENV_TCP_PORT "LM_TCP_PORT"
-#endif // _SOCKETCONFIGURATION_H_
+#endif /* _SOCKETCONFIGURATION_H_ */
diff --git a/LayerManagerPlugins/IpcModules/TcpIpcModule/include/socketShared.h b/LayerManagerPlugins/IpcModules/TcpIpcModule/include/socketShared.h
index 6681fd2..29a2ee6 100644
--- a/LayerManagerPlugins/IpcModules/TcpIpcModule/include/socketShared.h
+++ b/LayerManagerPlugins/IpcModules/TcpIpcModule/include/socketShared.h
@@ -23,15 +23,18 @@
#include "socketConfiguration.h"
#include <sys/socket.h>
#include <netinet/in.h>
-#include <netdb.h> // struct hostent
+#include <netdb.h> /* struct hostent */
#include <string.h>
#include <stdio.h>
#include <sys/select.h>
-//=============================================================================
-// type definitions
-//=============================================================================
-// this data is transferred via socket
+/*
+ * =============================================================================
+ * type definitions
+ * =============================================================================
+ */
+
+/* this data is transferred via socket */
struct SocketMessagePaket
{
int size;
@@ -39,7 +42,7 @@ struct SocketMessagePaket
char data[SOCKET_MAX_MESSAGE_SIZE];
};
-// wraps socket message with management information
+/* wraps socket message with management information */
struct SocketMessage
{
unsigned int index;
@@ -48,7 +51,7 @@ struct SocketMessage
struct SocketMessagePaket paket;
};
-// contains all state information
+/* contains all state information */
struct State
{
t_ilm_bool isClient;
@@ -60,10 +63,12 @@ struct State
};
-//=============================================================================
-// global variables
-//=============================================================================
+/*
+ * =============================================================================
+ * global variables
+ * =============================================================================
+ */
struct State gState;
-#endif // __SOCKETSHARED_H__
+#endif /* __SOCKETSHARED_H__ */
diff --git a/LayerManagerPlugins/IpcModules/TcpIpcModule/src/append.c b/LayerManagerPlugins/IpcModules/TcpIpcModule/src/append.c
index 055685a..78d1ecf 100644
--- a/LayerManagerPlugins/IpcModules/TcpIpcModule/src/append.c
+++ b/LayerManagerPlugins/IpcModules/TcpIpcModule/src/append.c
@@ -19,30 +19,31 @@
#include "IpcModule.h"
#include "socketShared.h"
-//-----------------------------------------------------------------------------
-// append simple data types
-//-----------------------------------------------------------------------------
+/*-----------------------------------------------------------------------------
+ * append simple data types
+ * -----------------------------------------------------------------------------
+ */
t_ilm_bool appendGenericValue(struct SocketMessage* msg, const char protocolType, const char size, const void* value)
{
- // size check: is message size reached
- if (sizeof(msg->paket) - sizeof(msg->paket.data) // header
- + msg->index + size // + data
+ /* size check: is message size reached */
+ if (sizeof(msg->paket) - sizeof(msg->paket.data) /* header */
+ + msg->index + size /* + data */
> SOCKET_MAX_MESSAGE_SIZE)
{
printf("Error: max message size exceeded.\n");
return ILM_FALSE;
}
- // append protocol type
+ /* append protocol type */
msg->paket.data[msg->index] = protocolType;
msg->index += sizeof(protocolType);
- // append size of data
+ /* append size of data */
msg->paket.data[msg->index] = size;
msg->index += sizeof(size);
- // append data
+ /* append data */
memcpy(&msg->paket.data[msg->index], value, size);
msg->index += size;
@@ -79,26 +80,27 @@ t_ilm_bool appendString(t_ilm_message message, t_ilm_const_string value)
return appendGenericValue(msg, SOCKET_MESSAGE_TYPE_STRING, strlen(value), value);
}
-//-----------------------------------------------------------------------------
-// append array data types
-//-----------------------------------------------------------------------------
+/*-----------------------------------------------------------------------------
+ * append array data types
+ * -----------------------------------------------------------------------------
+ */
t_ilm_bool appendGenericArray(struct SocketMessage* msg, const char arraySize, const char protocolType, const char size, const void* value)
{
t_ilm_bool result = ILM_TRUE;
+ char i = 0;
- // TODO: size check: is message size reached?
+ /* TODO: size check: is message size reached? */
- // append array type
+ /* append array type */
msg->paket.data[msg->index] = SOCKET_MESSAGE_TYPE_ARRAY;
msg->index += sizeof(protocolType);
- // append size of array
+ /* append size of array */
msg->paket.data[msg->index] = arraySize;
msg->index += sizeof(arraySize);
- // append data for each array entry
- char i = 0;
+ /* append data for each array entry */
for (i = 0; i < arraySize; ++i)
{
result &= appendGenericValue(msg, protocolType, size, (void*)((unsigned int)value + i * size));
@@ -131,4 +133,4 @@ t_ilm_bool appendDoubleArray(t_ilm_message message, const t_ilm_float* valueArra
return appendGenericArray(msg, arraySize, SOCKET_MESSAGE_TYPE_DOUBLE, sizeof(t_ilm_float), valueArray);
}
-// TODO appendStringArray()
+/* TODO appendStringArray() */
diff --git a/LayerManagerPlugins/IpcModules/TcpIpcModule/src/get.c b/LayerManagerPlugins/IpcModules/TcpIpcModule/src/get.c
index ef679af..6bf0f09 100644
--- a/LayerManagerPlugins/IpcModules/TcpIpcModule/src/get.c
+++ b/LayerManagerPlugins/IpcModules/TcpIpcModule/src/get.c
@@ -19,19 +19,23 @@
#include "IpcModule.h"
#include "socketShared.h"
#include <stdio.h>
-#include <stdlib.h> // malloc
+#include <stdlib.h> /* malloc */
-//-----------------------------------------------------------------------------
-// get simple data types
-//-----------------------------------------------------------------------------
+/*
+ * -----------------------------------------------------------------------------
+ * get simple data types
+ * -----------------------------------------------------------------------------
+ */
t_ilm_bool getGenericValue(struct SocketMessage* msg, void* value, const char protocolType, const char expectedSize)
{
- // get protocol value from message
+ char size = 0;
+
+ /* get protocol value from message */
char readType = msg->paket.data[msg->index];
msg->index += sizeof(readType);
- // if type mismatch, return to previous state, return with error
+ /* if type mismatch, return to previous state, return with error */
if (readType != protocolType)
{
msg->index -= sizeof(readType);
@@ -40,12 +44,12 @@ t_ilm_bool getGenericValue(struct SocketMessage* msg, void* value, const char pr
return ILM_FALSE;
}
- // get size of value
- char size = msg->paket.data[msg->index];
+ /* get size of value */
+ size = msg->paket.data[msg->index];
msg->index += sizeof(size);
- // if size mismatch, return to previous state, return with error
- // exception: strings have varying length
+ /* if size mismatch, return to previous state, return with error
+ * exception: strings have varying length*/
if (protocolType != SOCKET_MESSAGE_TYPE_STRING
&& size != expectedSize)
{
@@ -57,11 +61,11 @@ t_ilm_bool getGenericValue(struct SocketMessage* msg, void* value, const char pr
return ILM_FALSE;
}
- // copy data to caller
+ /* copy data to caller */
memcpy(value, &msg->paket.data[msg->index], size);
msg->index += size;
- // if value is string, add end of string
+ /* if value is string, add end of string */
if (protocolType == SOCKET_MESSAGE_TYPE_STRING)
{
char* str = (char *)value + size;
@@ -101,19 +105,20 @@ t_ilm_bool getString(t_ilm_message message, char* value)
return getGenericValue(msg, value, SOCKET_MESSAGE_TYPE_STRING, sizeof(t_ilm_const_string));
}
-//-----------------------------------------------------------------------------
-// get array data types
-//-----------------------------------------------------------------------------
+/*-----------------------------------------------------------------------------
+ * get array data types
+ *-----------------------------------------------------------------------------
+ */
t_ilm_bool getGenericArray(struct SocketMessage* msg, t_ilm_int* arraySize, void** value, const char protocolType, const char expectedSize)
{
t_ilm_bool result = ILM_TRUE;
- // get protocol value from message
+ /* get protocol value from message */
char readType = msg->paket.data[msg->index];
msg->index += sizeof(readType);
- // if type mismatch, return to previous state, return with error
+ /* if type mismatch, return to previous state, return with error */
if (readType != SOCKET_MESSAGE_TYPE_ARRAY)
{
msg->index -= sizeof(readType);
@@ -122,14 +127,14 @@ t_ilm_bool getGenericArray(struct SocketMessage* msg, t_ilm_int* arraySize, void
return ILM_FALSE;
}
- // get size of array
+ /* get size of array */
*arraySize = msg->paket.data[msg->index];
msg->index += sizeof(msg->paket.data[msg->index]);
- // create array for result and set callers pointer
+ /* create array for result and set callers pointer */
*value = malloc(*arraySize * expectedSize);
- // get all values from array
+ /* get all values from array */
char i = 0;
for (i = 0; i < *arraySize; ++i)
{
diff --git a/LayerManagerPlugins/IpcModules/TcpIpcModule/src/initialization.c b/LayerManagerPlugins/IpcModules/TcpIpcModule/src/initialization.c
index 26c3e08..4a20138 100644
--- a/LayerManagerPlugins/IpcModules/TcpIpcModule/src/initialization.c
+++ b/LayerManagerPlugins/IpcModules/TcpIpcModule/src/initialization.c
@@ -19,20 +19,21 @@
#include "IpcModule.h"
#include "socketShared.h"
#include <stdio.h>
-#include <stdlib.h> // getenv
-#include <string.h> // memset
+#include <stdlib.h> /* getenv */
+#include <string.h> /* memset */
#include <signal.h>
#include <unistd.h>
t_ilm_bool initServiceMode()
{
- // ignore broken pipe, if clients disconnect, handled in receive()
- signal(SIGPIPE, SIG_IGN);
-
t_ilm_bool isClient = ILM_FALSE;
-
t_ilm_bool result = ILM_TRUE;
+ const char* portString = getenv(ENV_TCP_PORT);
+ int port = portString ? atoi(portString) : SOCKET_TCP_PORT;
+
+ /* ignore broken pipe, if clients disconnect, handled in receive() */
+ signal(SIGPIPE, SIG_IGN);
gState.isClient = isClient;
@@ -44,26 +45,19 @@ t_ilm_bool initServiceMode()
result = ILM_FALSE;
}
- const char* portString = getenv(ENV_TCP_PORT);
- int port = SOCKET_TCP_PORT;
- if (portString)
- {
- port = atoi(portString);
- }
-
gState.serverAddrIn.sin_family = AF_INET;
gState.serverAddrIn.sin_port = htons(port);
memset(&(gState.serverAddrIn.sin_zero), '\0', 8);
- if (gState.isClient) // Client
+ if (gState.isClient) /* Client */
{
+ struct hostent* server;
const char* hostname = getenv(ENV_TCP_HOST);
if (!hostname)
{
hostname = SOCKET_TCP_HOST;
}
- struct hostent* server;
server = gethostbyname(hostname);
if (!server)
{
@@ -89,7 +83,7 @@ t_ilm_bool initServiceMode()
FD_SET(gState.socket, &gState.monitoredSockets);
gState.monitoredSocketMax = gState.socket;
}
- else // LayerManagerService
+ else /* LayerManagerService */
{
int on = 1;
setsockopt(gState.socket, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on));
@@ -121,12 +115,13 @@ t_ilm_bool initServiceMode()
t_ilm_bool initClientMode()
{
- // ignore broken pipe, if clients disconnect, handled in receive()
- signal(SIGPIPE, SIG_IGN);
-
t_ilm_bool isClient = ILM_TRUE;
-
t_ilm_bool result = ILM_TRUE;
+ const char* portString = getenv(ENV_TCP_PORT);
+ int port = portString ? atoi(portString) : SOCKET_TCP_PORT;
+
+ /* ignore broken pipe, if clients disconnect, handled in receive() */
+ signal(SIGPIPE, SIG_IGN);
gState.isClient = isClient;
@@ -138,18 +133,11 @@ t_ilm_bool initClientMode()
result = ILM_FALSE;
}
- const char* portString = getenv(ENV_TCP_PORT);
- int port = SOCKET_TCP_PORT;
- if (portString)
- {
- port = atoi(portString);
- }
-
gState.serverAddrIn.sin_family = AF_INET;
gState.serverAddrIn.sin_port = htons(port);
memset(&(gState.serverAddrIn.sin_zero), '\0', 8);
- if (gState.isClient) // Client
+ if (gState.isClient) /* Client */
{
const char* hostname = getenv(ENV_TCP_HOST);
if (!hostname)
@@ -183,7 +171,7 @@ t_ilm_bool initClientMode()
FD_SET(gState.socket, &gState.monitoredSockets);
gState.monitoredSocketMax = gState.socket;
}
- else // LayerManagerService
+ else /* LayerManagerService */
{
int on = 1;
setsockopt(gState.socket, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on));
@@ -225,7 +213,7 @@ t_ilm_bool destroy()
}
}
- // return to default signal handling
+ /* return to default signal handling */
signal(SIGPIPE, SIG_DFL);
return ILM_TRUE;
diff --git a/LayerManagerPlugins/IpcModules/TcpIpcModule/src/message.c b/LayerManagerPlugins/IpcModules/TcpIpcModule/src/message.c
index ef904e1..4322b64 100644
--- a/LayerManagerPlugins/IpcModules/TcpIpcModule/src/message.c
+++ b/LayerManagerPlugins/IpcModules/TcpIpcModule/src/message.c
@@ -25,19 +25,21 @@
#include <unistd.h>
-//=============================================================================
-// prototypes
-//=============================================================================
+/*=============================================================================
+ * prototypes
+ * =============================================================================
+ */
t_ilm_bool acceptClientConnection();
t_ilm_bool sendToSocket(struct SocketMessage* msg, int socketNumber);
void receiveFromSocket(struct SocketMessage* msg, int socketNumber);
-//=============================================================================
-// incoming queue handling (one select may return more than one active
-// descriptor, but receive must only return one message at a time.
-// all messages are first received and added to this queue, so no
-// messages get lost
-//=============================================================================
+/*=============================================================================
+ * incoming queue handling (one select may return more than one active
+ * descriptor, but receive must only return one message at a time.
+ * all messages are first received and added to this queue, so no
+ * messages get lost
+ * =============================================================================
+ */
struct QueueElement
{
struct SocketMessage* data;
@@ -68,17 +70,18 @@ struct SocketMessage* getFromIncomingQueue()
struct SocketMessage* data = NULL;
if (oldest)
{
- data = oldest->data;
struct QueueElement* delPtr = oldest;
+ data = oldest->data;
oldest = oldest->next;
free(delPtr);
}
return data;
}
-//=============================================================================
-// message handling
-//=============================================================================
+/*=============================================================================
+ * message handling
+ * =============================================================================
+ */
t_ilm_message createMessage(t_ilm_const_string name)
{
struct SocketMessage* newMessage = (struct SocketMessage*)malloc(sizeof(struct SocketMessage));
@@ -127,15 +130,15 @@ t_ilm_bool destroyMessage(t_ilm_message message)
t_ilm_bool sendToClients(t_ilm_message message, t_ilm_client_handle* receiverList, int receiverCount)
{
+ t_ilm_bool result = ILM_TRUE;
+ int i = 0;
+
struct SocketMessage* msg = (struct SocketMessage*)message;
if (gState.isClient)
{
return ILM_FALSE;
}
- t_ilm_bool result = ILM_TRUE;
- int i = 0;
-
for (i = 0; i < receiverCount; ++i)
{
int sock = (int)receiverList[i];
@@ -157,16 +160,15 @@ t_ilm_bool sendToService(t_ilm_message message)
t_ilm_message receive(t_ilm_int timeoutInMs)
{
+ fd_set readFds = gState.monitoredSockets;
+ int numberOfFdsReady = 0;
+
struct SocketMessage* queuedMessage = getFromIncomingQueue();
if (queuedMessage)
{
return queuedMessage;
}
- fd_set readFds = gState.monitoredSockets;
-
- int numberOfFdsReady = 0;
-
if (timeoutInMs < 0)
{
numberOfFdsReady = select(gState.monitoredSocketMax + 1, &readFds, 0, 0, NULL);
@@ -200,39 +202,41 @@ t_ilm_message receive(t_ilm_int timeoutInMs)
{
if (gState.socket == socketNumber)
{
- // New client connected
+ /* New client connected */
msg->paket.type = IpcMessageTypeConnect;
acceptClientConnection();
continue;
}
- // receive data from socket
+ /* receive data from socket */
receiveFromSocket(msg, socketNumber);
if (msg->paket.size > 0)
{
- // new message from client
+ /* new message from client */
getString(msg, msg->name);
continue;
}
if (msg->paket.size == 0)
{
- // client disconnected
+ /* client disconnected */
msg->paket.type = IpcMessageTypeDisconnect;
close(socketNumber);
FD_CLR(socketNumber, &gState.monitoredSockets);
continue;
}
- // error
- msg->paket.type = IpcMessageTypeError;
- const char* errorMsg = (char*)strerror(errno);
- printf("TcpIpcModule: receive error socket %d (%s)\n", msg->sender, errorMsg);
+ /* error */
+ {
+ const char* errorMsg = (char*)strerror(errno);
+ msg->paket.type = IpcMessageTypeError;
+ printf("TcpIpcModule: receive error socket %d (%s)\n", msg->sender, errorMsg);
+ }
}
else
{
- // receive LayerManager response or notification
+ /* receive LayerManager response or notification */
receiveFromSocket(msg, socketNumber);
getString(msg, msg->name);
}
@@ -270,9 +274,10 @@ t_ilm_client_handle getSenderHandle(t_ilm_message message)
}
-//=============================================================================
-//private
-//=============================================================================
+/*=============================================================================
+ * private
+ * =============================================================================
+ */
t_ilm_bool acceptClientConnection()
{
t_ilm_bool result = ILM_TRUE;
@@ -295,12 +300,13 @@ t_ilm_bool acceptClientConnection()
t_ilm_bool sendToSocket(struct SocketMessage* msg, int socketNumber)
{
int sentBytes = 0;
+ int sendSize = 0;
int retVal = 0;
int headerSize = sizeof(msg->paket) - sizeof(msg->paket.data);
msg->paket.size = msg->index + headerSize;
- int sendSize = msg->paket.size;
+ sendSize = msg->paket.size;
do
{
@@ -318,13 +324,14 @@ void receiveFromSocket(struct SocketMessage* msg, int socketNumber)
{
int receivedBytes = 0;
int retVal = 0;
+ char* messageBuffer = 0;
msg->sender = socketNumber;
- // receive header in first run (contains message size)
+ /* receive header in first run (contains message size) */
msg->paket.size = sizeof(msg->paket) - sizeof(msg->paket.data);
- char* messageBuffer = (char*)&msg->paket;
+ messageBuffer = (char*)&msg->paket;
do
{
@@ -337,7 +344,7 @@ void receiveFromSocket(struct SocketMessage* msg, int socketNumber)
if (0 == retVal)
{
- // client disconnect
+ /* client disconnect */
msg->paket.size = 0;
}
}