Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfixes to make it work with VS2010 compiler. #10

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions include/c99_support.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#include <stdio.h>
#include <stdarg.h>

#if defined(_MSC_VER) && _MSC_VER < 1900

#define snprintf c99_snprintf
#define vsnprintf c99_vsnprintf

inline int c99_vsnprintf(char *outBuf, size_t size, const char *format, va_list ap)
{
int count = -1;

if (size != 0)
count = _vsnprintf_s(outBuf, size, _TRUNCATE, format, ap);
if (count == -1)
count = _vscprintf(format, ap);

return count;
}

inline int c99_snprintf(char *outBuf, size_t size, const char *format, ...)
{
int count;
va_list ap;

va_start(ap, format);
count = c99_vsnprintf(outBuf, size, format, ap);
va_end(ap);

return count;
}

#endif
9 changes: 9 additions & 0 deletions include/cros_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@
#include "cros_node.h"
#include "cros_message.h"

#ifdef __cplusplus
extern "C"
{
#endif

typedef enum CrosTransportType
{
CROS_TRANSPORT_TCPROS,
Expand Down Expand Up @@ -372,4 +377,8 @@ int cRosApiSearchParam(CrosNode *node, const char *key, SearchParamCallback call
int cRosApiHasParam(CrosNode *node, const char *key, HasParamCallback callback, void *context);
int cRosApiGetParamNames(CrosNode *node, GetParamNamesCallback callback, void *context);

#ifdef __cplusplus
}
#endif

#endif // _CROS_API_H_
9 changes: 7 additions & 2 deletions include/cros_clock.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
#ifndef _CROS_CLOCK_H_
#define _CROS_CLOCK_H_

#include <sys/time.h>
#ifdef _WIN32 || _WIN64
# include <winsock.h>
#else
# include <sys/time.h>
#endif

#include <stdint.h>

/*! \defgroup cros_clock cROS clock
Expand All @@ -28,4 +33,4 @@ struct timeval cRosClockGetTimeVal( uint64_t msec );

/*! @}*/

#endif
#endif
16 changes: 8 additions & 8 deletions include/cros_message.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ struct cRosMessageField
{
char *name;

union data
union data_t
{
uint8_t opaque[8];
int8_t as_int8;
Expand Down Expand Up @@ -86,18 +86,18 @@ typedef struct t_msgDef cRosMessageDef;
struct cRosMessage
{
cRosMessageField **fields;
cRosMessageDef* msgDef;
char* md5sum;
cRosMessageDef *msgDef;
char *md5sum;
int n_fields;
};

cRosMessage * cRosMessageNew();

void cRosMessageInit(cRosMessage *message);

int cRosMessageBuild(cRosMessage* message, const char* message_path);
int cRosMessageBuild(cRosMessage *message, const char *message_path);

void cRosMessageBuildFromDef(cRosMessage* message, cRosMessageDef* msg_def );
void cRosMessageBuildFromDef(cRosMessage *message, cRosMessageDef *msg_def );

void cRosMessageFree(cRosMessage *message);

Expand All @@ -111,9 +111,9 @@ void cRosMessageFieldRelease(cRosMessageField *field);

void cRosMessageFieldFree(cRosMessageField *field);

cRosMessageField* cRosMessageGetField(cRosMessage *message, char *field);
cRosMessageField* cRosMessageGetField(cRosMessage *message, const char *field);

int cRosMessageSetFieldValueString(cRosMessageField* field, const char* value);
int cRosMessageSetFieldValueString(cRosMessageField *field, const char *value);

int cRosMessageFieldArrayPushBackInt8(cRosMessageField *field, int8_t val);

Expand Down Expand Up @@ -175,7 +175,7 @@ void cRosMessageSerialize(cRosMessage *message, DynBuffer* buffer);

void cRosMessageDeserialize(cRosMessage *message, DynBuffer *buffer);

CrosMessageType getMessageType(const char* type);
CrosMessageType getMessageType(const char *type);

const char * getMessageTypeString(CrosMessageType type);

Expand Down
6 changes: 3 additions & 3 deletions include/cros_node.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#define CN_MAX_SUBSCRIBED_TOPICS 5

/*! Max num service providers */
#define CN_MAX_SERVICE_PROVIDERS 8
#define CN_MAX_SERVICE_PROVIDERS 10

/*! Max num parameter subscriptions */
#define CN_MAX_PARAMETER_SUBSCRIPTIONS 20
Expand Down Expand Up @@ -265,8 +265,8 @@ void cRosGetMsgFilePath(CrosNode *node, char *buffer, size_t bufsize, const char
*
* \return A pointer to the new CrosNode on success, NULL on failure
*/
CrosNode *cRosNodeCreate(char* node_name, char *node_host, char *roscore_host, unsigned short roscore_port,
char *message_root_path, uint64_t const *select_timeout_ms );
CrosNode *cRosNodeCreate(const char *node_name, const char *node_host, const char *roscore_host, unsigned short roscore_port,
const char *message_root_path, uint64_t const *select_timeout_ms );

/*! \brief Release all the internal allocated memory for a CrosNode object previously crated with
* cRosNodeCreate()
Expand Down
8 changes: 6 additions & 2 deletions include/tcpip_socket.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
#ifndef _TCPIP_SOCKET_H_
#define _TCPIP_SOCKET_H_

# include <arpa/inet.h>
#ifdef _WIN32 || _WIN64
# include <winsock2.h>
#else
# include <arpa/inet.h>
#endif

#include "dyn_string.h"
#include "dyn_buffer.h"
Expand Down Expand Up @@ -207,4 +211,4 @@ unsigned short tcpIpSocketGetPort( TcpIpSocket *s );

/*! @}*/

#endif
#endif
15 changes: 15 additions & 0 deletions include/winutils.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#pragma once

#include <string.h>

#ifdef WIN32 || WIN64
static inline void unix2win_filepath(char* filepath)
{
int i;
for(i = 0; i < strlen(filepath); i++)
{
if(filepath[i] == '/')
filepath[i] = '\\';
}
}
#endif
4 changes: 2 additions & 2 deletions src/cros_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ static CallbackResponse cRosNodePublisherCallback(DynBuffer *buffer, void* conte
ProviderContext *context = (ProviderContext *)context_;

// Cast to the appropriate public api callback and invoke it on the user context
PublisherApiCallback publisherApiCallback = (SubscriberApiCallback)context->api_callback;
PublisherApiCallback publisherApiCallback = (PublisherApiCallback)context->api_callback;
CallbackResponse rc = publisherApiCallback(context->outgoing, context->context);

cRosMessageSerialize(context->outgoing, buffer);
Expand Down Expand Up @@ -1513,7 +1513,7 @@ static GetParamNamesResult * fetchGetParamNamesResult(XmlrpcParamVector *respons
int it = 0;
for (; it < param_names->array_n_elem; it++)
{
ret->parameter_names[it] = malloc(strlen(param_names->data.as_array[it].data.as_string) + 1);
ret->parameter_names[it] = (char *)malloc(strlen(param_names->data.as_array[it].data.as_string) + 1);
if (ret->parameter_names[it] == NULL)
goto clean;

Expand Down
2 changes: 1 addition & 1 deletion src/cros_api_call.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ RosApiCall * peekApiCallQueue(ApiCallQueue *queue)

int enqueueApiCall(ApiCallQueue *queue, RosApiCall* apiCall)
{
ApiCallNode* node = malloc(sizeof(ApiCallNode));
ApiCallNode* node = (ApiCallNode *)malloc(sizeof(ApiCallNode));

if(node == NULL)
{
Expand Down
8 changes: 6 additions & 2 deletions src/cros_clock.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,18 @@
uint64_t cRosClockGetTimeMs()
{
PRINT_VDEBUG ( "cRosClockGetTimeMs()\n" );
#ifdef _WIN32 || _WIN64
return (uint64_t)timeGetTime();
#else
struct timeval tv;
gettimeofday( &tv, NULL );
return (uint64_t)tv.tv_sec*1000 + (uint64_t)tv.tv_usec/1000;
#endif
}

struct timeval cRosClockGetTimeVal( uint64_t msec )
{
PRINT_VDEBUG ( "cRosClockGetTimeVal()\n" );
PRINT_VDEBUG ( "cRosClockGetTimeVal() msec: %u\n", msec);
struct timeval tv;
if (msec > ( LONG_MAX * 1000ULL ))
{
Expand All @@ -27,4 +31,4 @@ struct timeval cRosClockGetTimeVal( uint64_t msec )
}

return tv;
}
}
4 changes: 2 additions & 2 deletions src/cros_gentools.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ char* cRosGentoolsMD5(char* filename)
cRosMessage msg;
cRosMessageInit(&msg);
cRosMessageBuild(&msg,filename);
char *md5sum = calloc(strlen(msg.md5sum)+1,sizeof(char));
char *md5sum = (char *)calloc(strlen(msg.md5sum)+1,sizeof(char));
strcpy(md5sum,msg.md5sum);
cRosMessageRelease(&msg);
return md5sum;
Expand All @@ -31,7 +31,7 @@ char* cRosGentoolsMD5(char* filename)
cRosService srv;
cRosServiceInit(&srv);
cRosServiceBuild(&srv,filename);
char *md5sum = calloc(strlen(srv.md5sum)+1,sizeof(char));
char *md5sum = (char *)calloc(strlen(srv.md5sum)+1,sizeof(char));
strcpy(md5sum,srv.md5sum);
cRosServiceRelease(&srv);
return md5sum;
Expand Down
14 changes: 7 additions & 7 deletions src/cros_log.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ void cRosLogFree(CrosLog *log)

CrosLogQueue* cRosLogQueueNew()
{
CrosLogQueue* new_queue = calloc(1,sizeof(CrosLogQueue));
CrosLogQueue* new_queue = (CrosLogQueue *)calloc(1,sizeof(CrosLogQueue));
cRosLogQueueInit(new_queue);
return new_queue;
}
Expand All @@ -60,7 +60,7 @@ CrosLog * cRosLogQueuePeek(CrosLogQueue *queue)

int cRosLogQueueEnqueue(CrosLogQueue *queue, CrosLog* CrosLog)
{
CrosLogNode* node = malloc(sizeof(CrosLogNode));
CrosLogNode* node = (CrosLogNode *)malloc(sizeof(CrosLogNode));

if(node == NULL)
{
Expand Down Expand Up @@ -148,7 +148,7 @@ void cRosLogPrint(CrosNode* node,
printf("\n[%d,%d] ", (int)wall_time, 0);
size_t msg_size = strlen(msg) + 512;

log_msg = calloc(msg_size + 1, sizeof(char));
log_msg = (char *)calloc(msg_size + 1, sizeof(char));
vsprintf(log_msg,msg,args);

switch(level)
Expand Down Expand Up @@ -188,10 +188,10 @@ void cRosLogPrint(CrosNode* node,

log->level = level;

log->file = calloc(strlen(file)+1, sizeof(char));
log->file = (char *)calloc(strlen(file)+1, sizeof(char));
strncpy(log->file, file,strlen(file));

log->function = calloc(strlen(function)+1, sizeof(char));
log->function = (char *)calloc(strlen(function)+1, sizeof(char));
strncpy(log->function, function,strlen(function));

log->line = line;
Expand All @@ -202,15 +202,15 @@ void cRosLogPrint(CrosNode* node,

for(i = 0; i <node->n_pubs; i++)
{
log->pubs[i] = calloc(strlen(node->pubs[i].topic_name) + 1, sizeof(char));
log->pubs[i] = (char *)calloc(strlen(node->pubs[i].topic_name) + 1, sizeof(char));
strncpy(log->pubs[i], node->pubs[i].topic_name,strlen(node->pubs[i].topic_name));
}

printf("\n[%d,%d] ",log->secs, log->nsecs);

size_t msg_size = vprintf(msg,args) + 512;

log_msg = calloc(msg_size + 1, sizeof(char));
log_msg = (char *)calloc(msg_size + 1, sizeof(char));
vsprintf(log_msg,msg,args);
log->msg = log_msg;

Expand Down
Loading