/home/dko/projects/mobilec/trunk/src/include/macros.h File Reference

#include <pthread.h>
#include <semaphore.h>
#include "config.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 PTHREAD_STACK_SIZE   131072
#define THREAD_T   pthread_t
#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 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 430 of file macros.h.

Referenced by agent_return_data_InitializeFromAgent(), agent_xml_compose__create_row_nodes(), agent_xml_parse__data(), agent_xml_parse__fill_row_data(), agent_xml_parse__row(), 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 539 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 461 of file macros.h.

Referenced by agent_xml_compose__data().

#define CH_DATATYPE_VALUE_STRING ( type,
string,
 ) 

Value:

switch(type) {                                      \
    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 493 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 {                                            \
    fprintf(stderr,                                 \
        "Unsupported data type: %d %s:%d\n",    \
        type, __FILE__, __LINE__ );             \
  }

Definition at line 519 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 413 of file macros.h.

Referenced by agent_datastate_New(), agent_return_data_InitializeFromAgent(), agent_return_data_New(), agent_xml_parse__data(), agent_xml_parse__home(), agent_xml_parse__name(), agent_xml_parse__owner(), 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(), listen_Thread(), 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_DeregisterService_chdl(), MC_End_chdl(), MC_FindAgentByID_chdl(), MC_FindAgentByName_chdl(), MC_HaltAgency_chdl(), MC_Initialize(), mc_platform_Initialize(), MC_RegisterService(), mc_rwlock_init(), MC_SearchForService(), message_InitializeFromAgent(), message_InitializeFromConnection(), message_InitializeFromString(), message_New(), message_queue_SendOutgoing(), 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 )

Definition at line 202 of file macros.h.

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

#define COND_DESTROY ( cond   )     pthread_cond_destroy(cond)

Definition at line 178 of file macros.h.

Referenced by ams_Destroy(), barrier_node_Destroy(), df_Destroy(), df_request_list_node_Destroy(), df_request_search_Destroy(), mc_platform_Destroy(), mc_rwlock_destroy(), and syncListNodeDestroy().

#define COND_INIT ( cond   )     pthread_cond_init(cond, NULL)

Definition at line 175 of file macros.h.

Referenced by acc_Initialize(), ams_Initialize(), barrier_node_Initialize(), df_Initialize(), df_request_list_New(), df_request_list_node_New(), df_request_search_New(), mc_platform_Initialize(), mc_rwlock_init(), syncListNodeInit(), and syncListNodeNew().

#define COND_RESET ( cond,
mutex   )     pthread_mutex_unlock( mutex );

Definition at line 190 of file macros.h.

#define COND_SIGNAL ( cond   )     pthread_cond_signal( cond )

Definition at line 204 of file macros.h.

Referenced by acc_MessageHandlerThread(), agent_RunChScriptThread(), MC_AddAgent(), MC_CondSignal(), MC_End(), MC_ResetSignal(), mc_rwlock_rdunlock(), mc_rwlock_wrunlock(), and MC_SetAgentStatus().

#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 184 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 192 of file macros.h.

Referenced by MC_SearchForService().

#define COND_T   pthread_cond_t

Definition at line 173 of file macros.h.

Referenced by acc_Initialize(), ams_Initialize(), barrier_node_Initialize(), df_Initialize(), df_request_list_New(), df_request_list_node_New(), df_request_search_New(), mc_platform_Initialize(), mc_rwlock_init(), syncListNodeInit(), and syncListNodeNew().

#define COND_WAIT ( cond,
mutex   )     pthread_cond_wait(cond, mutex )

Definition at line 181 of file macros.h.

Referenced by acc_MessageHandlerThread(), acc_Thread(), agent_mailbox_WaitRetrieve(), ams_Thread(), df_Thread(), MC_Barrier(), MC_CondWait(), mc_platform_Initialize(), mc_rwlock_rdlock(), mc_rwlock_wrlock(), MC_SteerControl(), MC_WaitAgent(), and MC_WaitSignal().

#define GET_THREAD_MODE ( a,
 )     ( (a & (1<<b)) / (1<<b) )

Definition at line 107 of file macros.h.

Referenced by MC_End(), and mc_platform_Initialize().

#define MUTEX_DESTROY ( mutex   )     pthread_mutex_destroy(mutex)

Definition at line 156 of file macros.h.

Referenced by agent_Destroy(), agent_Initialize(), ams_Destroy(), barrier_node_Destroy(), df_Destroy(), df_request_list_node_Destroy(), df_request_search_Destroy(), mc_platform_Destroy(), mc_rwlock_destroy(), and syncListNodeDestroy().

#define MUTEX_INIT ( mutex   )     pthread_mutex_init(mutex, NULL)

Definition at line 153 of file macros.h.

Referenced by acc_Initialize(), agent_Copy(), agent_Initialize(), agent_New(), ams_Initialize(), barrier_node_Initialize(), df_Initialize(), df_request_list_New(), df_request_list_node_New(), df_request_search_New(), mc_platform_Initialize(), MC_RegisterService(), mc_rwlock_init(), syncListInit(), syncListNodeInit(), and syncListNodeNew().

#define MUTEX_LOCK ( mutex   ) 

Value:

if (pthread_mutex_lock( mutex ))                                        \
fprintf(stderr, "pthread lock error: %s:%d\n", __FILE__, __LINE__)

Definition at line 159 of file macros.h.

Referenced by acc_MessageHandlerThread(), acc_Thread(), agent_Copy(), agent_Destroy(), agent_mailbox_WaitRetrieve(), agent_RunChScriptThread(), ams_ManageAgentList(), ams_Print(), ams_Thread(), AP_QUEUE_SEARCH_TEMPLATE(), AP_QUEUE_STD_DEFN_TEMPLATE(), df_Destroy(), df_node_Destroy(), df_request_list_Pop(), df_SearchForService(), df_Thread(), listen_Thread(), MC_AddAgent(), MC_Barrier(), MC_CallAgentFunc(), MC_CondBroadcast(), MC_CondReset(), MC_CondSignal(), MC_CondWait(), MC_End(), MC_GetAgentName(), MC_GetAgentStatus(), MC_GetAllAgents(), MC_HaltAgency(), MC_MutexLock(), mc_platform_Initialize(), MC_PrintAgentCode(), MC_ResetSignal(), MC_ResumeAgency(), MC_RetrieveAgent(), MC_RetrieveAgentCode(), mc_rwlock_rdlock(), mc_rwlock_rdunlock(), mc_rwlock_wrlock(), mc_rwlock_wrunlock(), MC_SendSteerCommand(), MC_SetAgentStatus(), MC_Steer(), MC_SteerControl(), MC_SyncDelete(), MC_SyncInit(), MC_WaitAgent(), MC_WaitRetrieveAgent(), MC_WaitSignal(), and message_queue_SendOutgoing().

#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 164 of file macros.h.

Referenced by agent_New().

#define MUTEX_T   pthread_mutex_t

Definition at line 151 of file macros.h.

Referenced by acc_Initialize(), agent_Copy(), agent_Initialize(), ams_Initialize(), barrier_node_Initialize(), df_Initialize(), df_request_list_New(), df_request_list_node_New(), df_request_search_New(), mc_platform_Initialize(), MC_RegisterService(), mc_rwlock_init(), syncListInit(), syncListNodeInit(), and syncListNodeNew().

#define MUTEX_UNLOCK ( mutex   )     pthread_mutex_unlock( mutex )

Definition at line 162 of file macros.h.

Referenced by acc_MessageHandlerThread(), acc_Thread(), agent_mailbox_WaitRetrieve(), agent_RunChScriptThread(), ams_ManageAgentList(), ams_Print(), ams_Thread(), AP_QUEUE_SEARCH_TEMPLATE(), AP_QUEUE_STD_DEFN_TEMPLATE(), df_request_list_Pop(), df_SearchForService(), df_Thread(), listen_Thread(), MC_AddAgent(), MC_Barrier(), MC_CallAgentFunc(), MC_CondBroadcast(), MC_CondReset(), MC_CondSignal(), MC_CondWait(), MC_End(), MC_GetAgentName(), MC_GetAgentStatus(), MC_GetAllAgents(), MC_HaltAgency(), MC_MutexUnlock(), mc_platform_Initialize(), MC_PrintAgentCode(), MC_ResetSignal(), MC_ResumeAgency(), MC_RetrieveAgent(), MC_RetrieveAgentCode(), mc_rwlock_rdlock(), mc_rwlock_rdunlock(), mc_rwlock_wrlock(), mc_rwlock_wrunlock(), MC_SendSteerCommand(), MC_SetAgentStatus(), MC_Steer(), MC_SteerControl(), MC_SyncDelete(), MC_SyncInit(), MC_WaitAgent(), MC_WaitRetrieveAgent(), MC_WaitSignal(), and message_queue_SendOutgoing().

#define PTHREAD_STACK_SIZE   131072

Definition at line 130 of file macros.h.

#define RWLOCK_DESTROY ( rwlock   )     mc_rwlock_destroy(rwlock)

Definition at line 246 of file macros.h.

Referenced by barrier_queue_Destroy().

#define RWLOCK_INIT ( rwlock   )     mc_rwlock_init(rwlock)

Definition at line 238 of file macros.h.

Referenced by barrier_queue_New(), and syncListInit().

#define RWLOCK_RDLOCK ( rwlock   )     mc_rwlock_rdlock(rwlock)

Definition at line 264 of file macros.h.

Referenced by barrier_queue_Get(), and syncListFind().

#define RWLOCK_RDUNLOCK ( rwlock   )     mc_rwlock_rdunlock(rwlock)

Definition at line 266 of file macros.h.

Referenced by barrier_queue_Get(), and syncListFind().

#define RWLOCK_T   mc_rwlock_t

Definition at line 231 of file macros.h.

Referenced by barrier_queue_New(), and syncListInit().

#define RWLOCK_WRLOCK ( rwlock   )     mc_rwlock_wrlock(rwlock)

Definition at line 268 of file macros.h.

Referenced by barrier_queue_Add(), barrier_queue_Delete(), syncListAddNode(), syncListDelete(), and syncListRemove().

#define RWLOCK_WRUNLOCK ( rwlock   )     mc_rwlock_wrunlock(rwlock)

Definition at line 270 of file macros.h.

Referenced by barrier_queue_Add(), barrier_queue_Delete(), syncListAddNode(), syncListDelete(), and syncListRemove().

#define SEMAPHORE_DESTROY ( sem   )     sem_destroy(sem)

Definition at line 216 of file macros.h.

Referenced by syncListNodeDestroy().

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

Definition at line 213 of file macros.h.

Referenced by syncListNodeInit(), and syncListNodeNew().

#define SEMAPHORE_POST ( sem   )     sem_post(sem)

Definition at line 221 of file macros.h.

Referenced by MC_SemaphorePost().

#define SEMAPHORE_T   sem_t

Definition at line 211 of file macros.h.

Referenced by syncListNodeInit(), and syncListNodeNew().

#define SEMAPHORE_WAIT ( sem   )     sem_wait(sem)

Definition at line 219 of file macros.h.

Referenced by MC_SemaphoreWait().

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

Definition at line 111 of file macros.h.

Referenced by MC_SetThreadOff(), and MC_SetThreadsAllOff().

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

Definition at line 110 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 197 of file macros.h.

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

#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 284 of file macros.h.

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

Definition at line 288 of file macros.h.

#define STRUCT ( name,
members   ) 

Value:

typedef struct name##_s { \
    members \
  } name##_t; \
typedef name##_t* name##_p;

Definition at line 115 of file macros.h.

#define THREAD_CANCEL ( thread_handle   )     pthread_cancel( thread_handle )

Definition at line 140 of file macros.h.

Referenced by MC_End().

#define THREAD_CREATE ( thread_handle,
function,
arg   ) 

Value:

pthread_create( \
      thread_handle, \
      &attr, \
      function, \
      (void*) arg \
      )

Definition at line 132 of file macros.h.

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

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

Definition at line 143 of file macros.h.

Referenced by MC_End().

#define THREAD_T   pthread_t

Definition at line 131 of file macros.h.

Referenced by agent_RunChScript().

#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 278 of file macros.h.

#define WARN ( message   ) 

Value:

fprintf(stderr, "WARNING: "); \
  fprintf(stderr, message ); \
  fprintf(stderr, " %s:%d\n", __FILE__, __LINE__ )

Definition at line 420 of file macros.h.

Referenced by acc_MessageHandlerThread(), acc_Thread(), and message_InitializeFromAgent().


Generated on Fri May 16 14:49:55 2008 for Mobile-C by  doxygen 1.5.4