/home/dko/Projects/mobilec/src/include/macros.h File Reference

#include <pthread.h>
#include <semaphore.h>
#include "config.h"
#include <errno.h>

Go to the source code of this file.

Defines

#define GET_THREAD_MODE(a, b)   ( (a & (1<<b)) / (1<<b) )
#define SET_THREAD_ON(a, b)   a = (a | (1<<b))
#define SET_THREAD_OFF(a, b)   a = (a & (~(1<<b)))
#define STRUCT(name, members)
#define SOCKET_ERROR()
#define PTHREAD_STACK_SIZE   131072
#define THREAD_CREATE(thread_handle, function, arg)
#define THREAD_CANCEL(thread_handle)   pthread_cancel( thread_handle )
#define THREAD_JOIN(thread_handle)   pthread_join( thread_handle, NULL )
#define THREAD_DETACH(thread_handle)
#define THREAD_EXIT()   pthread_exit(NULL)
#define MUTEX_T   pthread_mutex_t
#define MUTEX_INIT(mutex)   pthread_mutex_init(mutex, NULL)
#define MUTEX_DESTROY(mutex)   pthread_mutex_destroy(mutex)
#define MUTEX_LOCK(mutex)
#define MUTEX_UNLOCK(mutex)   pthread_mutex_unlock( mutex )
#define MUTEX_NEW(mutex)
#define COND_T   pthread_cond_t
#define COND_INIT(cond)   pthread_cond_init(cond, NULL)
#define COND_DESTROY(cond)   pthread_cond_destroy(cond)
#define COND_WAIT(cond, mutex)   pthread_cond_wait(cond, mutex )
#define COND_SLEEP(cond, mutex, test)
#define COND_RESET(cond, mutex)   pthread_mutex_unlock( mutex );
#define COND_SLEEP_ACTION(cond, mutex, action)
#define SIGNAL(cond, mutex, action)
#define COND_BROADCAST(cond)   pthread_cond_broadcast( cond )
#define COND_SIGNAL(cond)   pthread_cond_signal( cond )
#define SEMAPHORE_T   sem_t
#define SEMAPHORE_INIT(sem)   sem_init(sem, 0, 0)
#define SEMAPHORE_DESTROY(sem)   sem_destroy(sem)
#define SEMAPHORE_WAIT(sem)   sem_wait(sem)
#define SEMAPHORE_POST(sem)   sem_post(sem)
#define RWLOCK_T   mc_rwlock_t
#define RWLOCK_INIT(rwlock)   mc_rwlock_init(rwlock)
#define RWLOCK_DESTROY(rwlock)   mc_rwlock_destroy(rwlock)
#define RWLOCK_RDLOCK(rwlock)   mc_rwlock_rdlock(rwlock)
#define RWLOCK_RDUNLOCK(rwlock)   mc_rwlock_rdunlock(rwlock)
#define RWLOCK_WRLOCK(rwlock)   mc_rwlock_wrlock(rwlock)
#define RWLOCK_WRUNLOCK(rwlock)   mc_rwlock_wrunlock(rwlock)
#define WAKE_QUEUE(queue, action)
#define SLEEP_QUEUE(queue)
#define SLEEP_RESET(queue)   pthread_mutex_unlock( queue->thread_mutex )
#define CHECK_NULL(var, action)
#define WARN(message)
#define CH_DATATYPE_SIZE(type, size)
#define CH_DATATYPE_STRING(type, string)
#define CH_DATATYPE_VALUE_STRING(type, string, p)
#define CH_STRING_DATATYPE(string, type)
#define CH_DATATYPE_STR_TO_VAL(type, string, val)

Define Documentation

#define CH_DATATYPE_SIZE ( type,
size   ) 
Value:
switch(type) {                                              \
    case CH_CHARTYPE:                                       \
      size = sizeof(char);                                \
    break;                                              \
    case CH_INTTYPE:                                        \
      size = sizeof(int);                                 \
    break;                                              \
    case CH_UINTTYPE:                                       \
      size = sizeof(unsigned int);                        \
    break;                                              \
    case CH_SHORTTYPE:                                      \
      size = sizeof(short);                               \
    break;                                              \
    case CH_USHORTTYPE:                                     \
      size = sizeof(unsigned short);                      \
    break;                                              \
    case CH_FLOATTYPE:                                      \
      size = sizeof(float);                               \
    break;                                              \
    case CH_DOUBLETYPE:                                     \
      size = sizeof(double);                              \
    break;                                              \
    default:                                                \
      fprintf(stderr, "Unknown data type: %d at %s:%d",   \
        type, __FILE__, __LINE__);                  \
      size=0;                                             \
  }

Definition at line 490 of file macros.h.

Referenced by agent_AddPersistentVariable(), agent_xml_compose__create_row_nodes(), agent_xml_parse__data(), agent_xml_parse__fill_row_data(), agent_xml_parse__row(), interpreter_variable_data_Initialize(), interpreter_variable_data_InitializeFromAgent(), MC_AgentReturnDataSize(), and MC_GetAgentReturnData().

#define CH_DATATYPE_STR_TO_VAL ( type,
string,
val   ) 
Value:
switch (type) { \
    case CH_INTTYPE: \
                     *(int*)val = atoi(string); \
    break; \
    case CH_UINTTYPE: \
                      *(unsigned int*)val = atoi(string); \
    break; \
    case CH_SHORTTYPE: \
                       *(short*)val = (short)atoi(string); /*FIXME*/ \
    break; \
    case CH_USHORTTYPE: \
                        *(unsigned short*)val = (unsigned short)atoi(string); /*FIXME*/ \
    break; \
    case CH_FLOATTYPE: \
                       *(float*)val = strtof(string, NULL); \
    break; \
    case CH_DOUBLETYPE: \
                        *(double*)val = strtod(string, NULL); \
    break; \
    default: \
             fprintf(stderr, \
                 "Unsupported data type: %d %s:%d\n", \
                 type, __FILE__, __LINE__ ); \
  }

Definition at line 604 of file macros.h.

Referenced by agent_xml_parse__data().

#define CH_DATATYPE_STRING ( type,
string   ) 
Value:
switch(type) {                                          \
    case CH_CHARTYPE:                                   \
      strcpy(string, "char");                         \
    break;                                          \
    case CH_INTTYPE:                                    \
      strcpy(string, "int");                          \
    break;                                          \
    case CH_UINTTYPE:                                   \
      strcpy(string, "unsigned int");                 \
    break;                                          \
    case CH_SHORTTYPE:                                  \
      strcpy(string, "short");                        \
    break;                                          \
    case CH_USHORTTYPE:                                 \
      strcpy(string, "unsigned short");               \
    break;                                          \
    case CH_FLOATTYPE:                                  \
      strcpy(string, "float");                        \
    break;                                          \
    case CH_DOUBLETYPE:                                 \
      strcpy(string, "double");                       \
    break;                                          \
    default:                                            \
      fprintf(stderr,                                 \
      "Unsupported data type: %d %s:%d\n",    \
      type, __FILE__, __LINE__ );             \
  }

Definition at line 521 of file macros.h.

Referenced by agent_xml_compose__data().

#define CH_DATATYPE_VALUE_STRING ( type,
string,
 ) 
Value:
switch(type) {                                      \
    case CH_CHARTYPE:                                 \
      sprintf(string, "%c", *((char*)p));             \
      break;                                          \
    case CH_INTTYPE:                                \
      sprintf(string, "%d", *((int*)p));          \
    break;                                      \
    case CH_UINTTYPE:                               \
      sprintf(string, "%d", *((unsigned int*)p)); \
    break;                                      \
    case CH_SHORTTYPE:                              \
      sprintf(string, "%d", *((short*)p));         \
    break;                                      \
    case CH_USHORTTYPE:                             \
      sprintf(string, "%d", *((unsigned short*)p)); \
    break;                                      \
    case CH_FLOATTYPE:                              \
      sprintf(string, "%f", *((float*)p));        \
    break;                                      \
    case CH_DOUBLETYPE:                             \
      sprintf(string, "%f", *((double*)p));       \
    break;                                      \
    default:                                        \
      fprintf(stderr,                             \
      "Unsupported data type: %d %s:%d\n",    \
      type, __FILE__, __LINE__);          \
  }

Definition at line 553 of file macros.h.

Referenced by agent_xml_compose__create_row_nodes(), and agent_xml_compose__data().

#define CH_STRING_DATATYPE ( string,
type   ) 
Value:
if (!strcmp(string, "int")) {                       \
    type = CH_INTTYPE;                              \
  } else if (!strcmp(string, "float")) {              \
    type = CH_FLOATTYPE;                            \
  } else if (!strcmp(string, "double")) {             \
    type = CH_DOUBLETYPE;                           \
  } else if (!strcmp(string, "unsigned int")) {       \
    type = CH_UINTTYPE;                             \
  } else if (!strcmp(string, "short")) {              \
    type = CH_SHORTTYPE;                            \
  } else if (!strcmp(string, "unsigned short")) {     \
    type = CH_USHORTTYPE;                           \
  } else if (!strcmp(string, "char")) {             \
    type = CH_CHARTYPE;                             \
  } else {                                            \
    fprintf(stderr,                                 \
        "Unsupported data type: %d %s:%d\n",    \
        type, __FILE__, __LINE__ );             \
  }

Definition at line 582 of file macros.h.

Referenced by agent_xml_parse__data().

#define CHECK_NULL ( var,
action   ) 
Value:
if ( var == NULL ) {                                        \
    fprintf(stderr, "Pointer var is null: expected otherwise.\n");    \
    fprintf(stderr, "Error occured at %s:%d", __FILE__, __LINE__);    \
    action; \
  }

Definition at line 473 of file macros.h.

Referenced by agent_AddPersistentVariable(), agent_datastate_New(), agent_xml_parse__home(), agent_xml_parse__name(), agent_xml_parse__owner(), agent_xml_parse__sender(), agent_xml_parse__task(), ams_Initialize(), barrier_node_Initialize(), barrier_queue_New(), df_request_list_New(), df_request_list_node_New(), df_request_search_New(), fipa_agent_identifier_Parse(), fipa_word_Parse(), http_ParseExpression(), interpreter_variable_data_Initialize(), interpreter_variable_data_InitializeFromAgent(), interpreter_variable_data_New(), MC_AclSend_chdl(), MC_AddAgent_chdl(), MC_Barrier_chdl(), MC_BarrierDelete_chdl(), MC_BarrierInit_chdl(), MC_CondBroadcast_chdl(), MC_CondReset_chdl(), MC_CondSignal_chdl(), MC_CondWait_chdl(), MC_DeleteAgent(), MC_DeleteAgentWG(), MC_DeregisterService_chdl(), MC_End_chdl(), MC_FindAgentByID_chdl(), MC_FindAgentByName_chdl(), MC_HaltAgency_chdl(), MC_MutexLock_chdl(), MC_MutexUnlock_chdl(), mc_platform_Initialize(), MC_RegisterService(), MC_RegisterService_chdl(), MC_ResumeAgency_chdl(), MC_RetrieveAgent_chdl(), mc_rwlock_init(), MC_SearchForService(), MC_SearchForService_chdl(), MC_SemaphorePost_chdl(), MC_SemaphoreWait_chdl(), MC_SendAgentMigrationMessage_chdl(), MC_SendSteerCommand_chdl(), MC_SetDefaultAgentStatus_chdl(), MC_SyncDelete_chdl(), MC_SyncInit_chdl(), message_InitializeFromAgent(), message_InitializeFromConnection(), message_InitializeFromString(), message_New(), message_queue_SendOutgoing(), message_send_Thread(), message_xml_parse__message(), mtp_http_InitializeFromConnection(), mtp_http_New(), syncListNodeInit(), syncListNodeNew(), xml_get_cdata(), xml_get_text(), and xml_new_cdata().

#define COND_BROADCAST ( cond   )     pthread_cond_broadcast( cond )
#define COND_DESTROY ( cond   )     pthread_cond_destroy(cond)
#define COND_INIT ( cond   )     pthread_cond_init(cond, NULL)
#define COND_RESET ( cond,
mutex   )     pthread_mutex_unlock( mutex );

Definition at line 213 of file macros.h.

#define COND_SIGNAL ( cond   )     pthread_cond_signal( cond )
#define COND_SLEEP ( cond,
mutex,
test   ) 
Value:
if (pthread_mutex_lock( mutex ))    \
printf("pthread lock error: %s:%d\n", __FILE__, __LINE__); \
if (!test) { \
  pthread_cond_wait( cond, mutex ); \
}

Definition at line 207 of file macros.h.

#define COND_SLEEP_ACTION ( cond,
mutex,
action   ) 
Value:
if (pthread_mutex_lock( mutex )) \
printf("pthread lock error: %s:%d\n", __FILE__, __LINE__); \
action; \
pthread_cond_wait( cond, mutex );

Definition at line 215 of file macros.h.

Referenced by MC_SearchForService().

#define COND_T   pthread_cond_t
#define COND_WAIT ( cond,
mutex   )     pthread_cond_wait(cond, mutex )
#define GET_THREAD_MODE ( a,
 )     ( (a & (1<<b)) / (1<<b) )

Definition at line 112 of file macros.h.

Referenced by MC_End(), and mc_platform_Initialize().

#define MUTEX_DESTROY ( mutex   )     pthread_mutex_destroy(mutex)
#define MUTEX_INIT ( mutex   )     pthread_mutex_init(mutex, NULL)
#define MUTEX_LOCK ( mutex   ) 
#define MUTEX_NEW ( mutex   ) 
Value:
mutex = (pthread_mutex_t*)malloc(sizeof(pthread_mutex_t)); \
  if (mutex == NULL)  \
    fprintf(stderr, "Memory Error. %s:%d\n", __FILE__,__LINE__); \

Definition at line 187 of file macros.h.

Referenced by agent_New().

#define MUTEX_T   pthread_mutex_t
#define MUTEX_UNLOCK ( mutex   )     pthread_mutex_unlock( mutex )
#define PTHREAD_STACK_SIZE   131072

Definition at line 139 of file macros.h.

#define RWLOCK_DESTROY ( rwlock   )     mc_rwlock_destroy(rwlock)

Definition at line 269 of file macros.h.

Referenced by barrier_queue_Destroy(), and syncListDestroy().

#define RWLOCK_INIT ( rwlock   )     mc_rwlock_init(rwlock)

Definition at line 261 of file macros.h.

Referenced by barrier_queue_New(), and syncListInit().

#define RWLOCK_RDLOCK ( rwlock   )     mc_rwlock_rdlock(rwlock)

Definition at line 287 of file macros.h.

Referenced by barrier_queue_Get(), and syncListFind().

#define RWLOCK_RDUNLOCK ( rwlock   )     mc_rwlock_rdunlock(rwlock)

Definition at line 289 of file macros.h.

Referenced by barrier_queue_Get(), and syncListFind().

#define RWLOCK_T   mc_rwlock_t

Definition at line 254 of file macros.h.

Referenced by barrier_queue_New(), and syncListInit().

#define RWLOCK_WRLOCK ( rwlock   )     mc_rwlock_wrlock(rwlock)
#define RWLOCK_WRUNLOCK ( rwlock   )     mc_rwlock_wrunlock(rwlock)
#define SEMAPHORE_DESTROY ( sem   )     sem_destroy(sem)

Definition at line 239 of file macros.h.

Referenced by syncListNodeDestroy().

#define SEMAPHORE_INIT ( sem   )     sem_init(sem, 0, 0)

Definition at line 236 of file macros.h.

Referenced by syncListNodeInit(), and syncListNodeNew().

#define SEMAPHORE_POST ( sem   )     sem_post(sem)

Definition at line 244 of file macros.h.

Referenced by MC_SemaphorePost().

#define SEMAPHORE_T   sem_t

Definition at line 234 of file macros.h.

Referenced by syncListNodeInit(), and syncListNodeNew().

#define SEMAPHORE_WAIT ( sem   )     sem_wait(sem)

Definition at line 242 of file macros.h.

Referenced by MC_SemaphoreWait().

#define SET_THREAD_OFF ( a,
 )     a = (a & (~(1<<b)))

Definition at line 116 of file macros.h.

Referenced by MC_SetThreadOff(), and MC_SetThreadsAllOff().

#define SET_THREAD_ON ( a,
 )     a = (a | (1<<b))

Definition at line 115 of file macros.h.

Referenced by MC_SetThreadOn(), and MC_SetThreadsAllOn().

#define SIGNAL ( cond,
mutex,
action   ) 
Value:
pthread_mutex_lock( mutex ); \
action; \
pthread_cond_signal( cond ); \
pthread_mutex_unlock( mutex )

Definition at line 220 of file macros.h.

Referenced by agent_RunChScriptThread(), df_Add(), df_AddRequest(), and request_handler_SEARCH().

#define SLEEP_QUEUE ( queue   ) 
Value:
if (pthread_mutex_lock( queue->thread_mutex ))                  \
printf("pthread lock error: %s:%d\n", __FILE__, __LINE__);  \
pthread_cond_wait( queue->touched_signal, queue->thread_mutex )

Definition at line 307 of file macros.h.

#define SLEEP_RESET ( queue   )     pthread_mutex_unlock( queue->thread_mutex )

Definition at line 311 of file macros.h.

 
#define SOCKET_ERROR (  ) 
Value:
printf("Socket error. %s:%d\nerrno:%d", __FILE__, __LINE__, errno); \
        sleep(500)

Definition at line 132 of file macros.h.

Referenced by listen_Thread(), mc_platform_Destroy(), message_InitializeFromConnection(), message_send_Thread(), mtp_http_InitializeFromConnection(), net_bind(), and net_connect().

#define STRUCT ( name,
members   ) 
Value:
typedef struct name##_s { \
    members \
  } name##_t; \
typedef name##_t* name##_p;

Definition at line 120 of file macros.h.

#define THREAD_CANCEL ( thread_handle   )     pthread_cancel( thread_handle )

Definition at line 155 of file macros.h.

Referenced by MC_End().

#define THREAD_CREATE ( thread_handle,
function,
arg   ) 
Value:
while(pthread_create( \
      thread_handle, \
      &attr, \
      function, \
      (void*) arg \
      ) < 0) { \
                        printf("pthread_create failed. Trying again...\n"); \
        }

Definition at line 145 of file macros.h.

Referenced by acc_Start(), acc_Thread(), agent_RunChScript(), ams_Start(), cmd_prompt_Start(), df_Start(), MC_AddStationaryAgent(), and message_Send().

#define THREAD_DETACH ( thread_handle   ) 
Value:
if(pthread_detach(thread_handle) < 0) { \
                printf("pthread_detach failed. %s:%d\n", __FILE__, __LINE__); \
        }

Definition at line 161 of file macros.h.

Referenced by acc_Thread(), and message_Send().

 
#define THREAD_EXIT (  )     pthread_exit(NULL)

Definition at line 166 of file macros.h.

Referenced by acc_MessageHandlerThread(), acc_Thread(), ams_Thread(), df_Thread(), and listen_Thread().

#define THREAD_JOIN ( thread_handle   )     pthread_join( thread_handle, NULL )

Definition at line 158 of file macros.h.

Referenced by MC_End().

#define WAKE_QUEUE ( queue,
action   ) 
Value:
if (pthread_mutex_trylock( queue->lock ) == 0) {    \
    action;                                                 \
    pthread_cond_signal( queue->cond);           \
    pthread_mutex_unlock( queue->lock);            \
  }

Definition at line 301 of file macros.h.

#define WARN ( message   ) 
Value:
fprintf(stderr, "\nWARNING: "); \
  fprintf(stderr, message ); \
  fprintf(stderr, " %s:%d\n", __FILE__, __LINE__ )

Definition at line 480 of file macros.h.

Referenced by agent_RunChScriptThread(), and message_InitializeFromAgent().

Generated on Tue Dec 28 15:15:27 2010 for Mobile-C by  doxygen 1.6.3