/home/dko/projects/mobilec/trunk/src/include/libmc.h

Go to the documentation of this file.
00001 /*[
00002  * Copyright (c) 2007 Integration Engineering Laboratory
00003                       University of California, Davis
00004  *
00005  * Permission to use, copy, and distribute this software and its
00006  * documentation for any purpose with or without fee is hereby granted,
00007  * provided that the above copyright notice appear in all copies and
00008  * that both that copyright notice and this permission notice appear
00009  * in supporting documentation.
00010  *
00011  * Permission to modify the software is granted, but not the right to
00012  * distribute the complete modified source code.  Modifications are to
00013  * be distributed as patches to the released version.  Permission to
00014  * distribute binaries produced by compiling modified sources is granted,
00015  * provided you
00016  *   1. distribute the corresponding source modifications from the
00017  *    released version in the form of a patch file along with the binaries,
00018  *   2. add special version identification to distinguish your version
00019  *    in addition to the base release version number,
00020  *   3. provide your name and address as the primary contact for the
00021  *    support of your modified version, and
00022  *   4. retain our contact information in regard to use of the base
00023  *    software.
00024  * Permission to distribute the released version of the source code along
00025  * with corresponding source modifications in the form of a patch file is
00026  * granted with same provisions 2 through 4 for binary distributions.
00027  *
00028  * This software is provided "as is" without express or implied warranty
00029  * to the extent permitted by applicable law.
00030 ]*/
00031 
00044 /* Filename: libmc.h */
00045 /* Current functions implemented 
00046 MC_AclDestroy
00047 MC_AclNew
00048 MC_AclPost
00049 MC_AclReply
00050 MC_AclRetrieve
00051 MC_AclSend
00052 MC_AclWaitRetrieve
00053 MC_AddAgent 
00054 MC_Barrier 
00055 MC_BarrierInit 
00056 MC_BarrierDelete 
00057 MC_CallAgentFunc
00058 MC_ChInitializeOptions 
00059 MC_ComposeAgent
00060 MC_CondBroadcast 
00061 MC_CondSignal 
00062 MC_CondWait  
00063 MC_CondReset 
00064 MC_CopyAgent 
00065 MC_DeleteAgent 
00066 MC_DeregisterService
00067 MC_End 
00068 MC_FindAgentByName
00069 MC_FindAgentByID
00070 MC_GetAgentArrivalTime 
00071 MC_GetAgentStatus 
00072 MC_GetAgentXMLString 
00073 MC_GetAgentExecEngine 
00074 MC_GetAgentID
00075 MC_GetAgentName
00076 MC_GetAgentReturnData
00077 MC_GetAgentNumTasks 
00078 MC_GetAgentType 
00079 MC_GetAllAgents 
00080 MC_HaltAgency 
00081 MC_Initialize
00082 MC_InitializeAgencyOptions 
00083 MC_MutexLock 
00084 MC_MutexUnlock 
00085 MC_PrintAgentCode 
00086 MC_RegisterService
00087 MC_ResumeAgency 
00088 MC_RetrieveAgent 
00089 MC_RetrieveAgentCode 
00090 MC_ResetSignal 
00091 MC_SearchForService
00092 MC_SemaphorePost 
00093 MC_SemaphoreWait 
00094 MC_SendCh
00095 MC_SendAgentMigrationMessage
00096 MC_SendAgentMigrationMessageFile
00097 MC_SendSteerCommand 
00098 MC_SetAgentStatus 
00099 MC_SetDefaultAgentStatus
00100 MC_SetThreadOn 
00101 MC_SetThreadsAllOn
00102 MC_SetThreadOff 
00103 MC_SetThreadsAllOff
00104 MC_Steer
00105 MC_SteerControl 
00106 MC_SyncDelete 
00107 MC_SyncInit 
00108 MC_TerminateAgent 
00109 MC_MainLoop 
00110 MC_MainLoop
00111 MC_WaitAgent 
00112 MC_WaitRetrieveAgent 
00113 MC_WaitSignal 
00114 
00115    *** */
00116 
00117 #ifndef _MOBILEC_H_
00118 #define _MOBILEC_H_
00119 
00120 #ifdef WIN32
00121         #ifdef _MC_DLL
00122                 // Building a .dll - export functions as marked
00123                 #define EXPORTMC _declspec(dllexport)
00124         #else
00125                 // Not building a .dll - building .lib assumed - no export required
00126                 #define EXPORTMC
00127         #endif
00128 #else
00129         // Not windows
00130         #define EXPORTMC
00131 #endif
00132 
00133 /* The MC_Wait() function is deprecated as of version 1.9.4.
00134  * All calls to MC_Wait() should now be changed to MC_MainLoop() */
00135 #define MC_Wait(arg1) \
00136   MC_MainLoop(arg1)
00137 
00138 #include <embedch.h>
00139 #ifdef __cplusplus
00140 extern "C" {
00141 #endif
00142 
00143 #ifndef _ERROR_CODE_E_
00144 #define _ERROR_CODE_E_
00145 /*
00146  * Error Codes
00147  * NOTE: There is a copy of this enum in mc_error.h
00148  * */
00149 typedef enum error_code_e {
00150     MC_SUCCESS = 0,
00151     MC_ERR,
00152     MC_ERR_CONNECT,
00153     MC_ERR_PARSE,
00154     MC_ERR_EMPTY,
00155     MC_ERR_INVALID,
00156     MC_ERR_INVALID_ARGS,
00157     MC_ERR_NOT_FOUND,
00158     MC_ERR_MEMORY,
00159     MC_ERR_SEND,
00160     MC_WARN_DUPLICATE
00161 } error_code_t;
00162 #endif
00163 
00167 enum MC_ThreadIndex_e{ 
00168     MC_THREAD_DF=0,   
00169     MC_THREAD_AMS,    
00170     MC_THREAD_ACC,    
00171     MC_THREAD_CP,     
00172     MC_THREAD_AGENT,  
00173     MC_THREAD_ALL };
00174 
00175 
00179 typedef enum MC_SteerCommand_e {
00180   MC_RUN = 0,     
00181   MC_SUSPEND,     
00182   MC_RESTART,     
00183   MC_STOP         
00184 } MC_SteerCommand_t;
00185 
00194 enum MC_Signal_e{
00195     MC_NO_SIGNAL      =0x00,
00196     MC_RECV_CONNECTION=0x01,
00197     MC_RECV_MESSAGE   =0x02,
00198     MC_RECV_AGENT     =0x04,
00199     MC_RECV_RETURN    =0x08,
00200     MC_EXEC_AGENT     =0x0F,
00201     MC_ALL_SIGNALS    =0x10
00202 };
00203 
00207 typedef struct agency_s {
00208     int client;
00209     int server;
00210     char *hostName;                     
00211     char *filename;
00212     int portno;                         
00213     int portnoc;
00214     struct mc_platform_s* mc_platform;  
00215     int default_agentstatus;            
00216     int threads;                        
00217     int enable_security;                
00218     int stack_size[MC_THREAD_ALL];
00219     error_code_t last_error;
00220 } agency_t;
00221 typedef agency_t* agency_p;
00222 typedef agency_p MCAgency_t;
00223 
00227 typedef struct MCAgencyOptions_s{
00228     int threads;              
00229     int default_agent_status; 
00230     int modified;             
00231     int enable_security;      
00233     /* Following are some thread stack size options: unix/pthreads only! */
00234     int stack_size[MC_THREAD_ALL]; 
00235 } MCAgencyOptions_t;
00236 
00237 #ifndef AGENT_T
00238 #define AGENT_T
00239 typedef struct agent_s agent_t;
00240 typedef agent_t* MCAgent_t;
00241 typedef agent_t* agent_p;
00242 #endif
00243 
00244 enum MC_AgentType_e{ MC_NONE = -1, MC_REMOTE_AGENT = 0, MC_LOCAL_AGENT, MC_RETURN_AGENT };
00245 
00249 enum MC_AgentStatus_e{ 
00250   MC_WAIT_CH,        
00251     MC_WAIT_MESSGSEND, 
00252     MC_AGENT_ACTIVE,   
00253     MC_AGENT_NEUTRAL,  
00254     MC_AGENT_SUSPENDED,
00255     MC_WAIT_FINISHED   
00256 };
00257 
00258 struct fipa_acl_message_s;
00259 
00267 int 
00268 MC_AclDestroy(struct fipa_acl_message_s* message);
00269 
00275 EXPORTMC extern struct fipa_acl_message_s*
00276 MC_AclNew(void);
00277 
00286 EXPORTMC extern int MC_AclPost(MCAgent_t agent, struct fipa_acl_message_s* message);
00287 
00298 EXPORTMC extern struct fipa_acl_message_s*
00299 MC_AclReply(struct fipa_acl_message_s* acl_message);
00300 
00308 EXPORTMC extern struct fipa_acl_message_s* MC_AclRetrieve(MCAgent_t agent);
00309 
00318 EXPORTMC extern int MC_AclSend(MCAgency_t attr, struct fipa_acl_message_s* acl);
00319 
00327 EXPORTMC extern struct fipa_acl_message_s* MC_AclWaitRetrieve(MCAgent_t agent);
00328 
00337 EXPORTMC extern int MC_AddAgent( 
00338     MCAgency_t attr, 
00339     MCAgent_t agent);
00340 
00350 EXPORTMC extern int MC_BarrierDelete(MCAgency_t attr, int id);
00351 
00367 EXPORTMC extern int MC_BarrierInit(MCAgency_t attr, int id, int num_procs);
00368 
00377 EXPORTMC extern int MC_ChInitializeOptions(MCAgency_t attr, ChOptions_t *options);
00378 
00395 EXPORTMC extern int MC_CallAgentFunc(
00396         MCAgent_t agent,
00397         const char* funcName,
00398         void* returnVal,
00399         void* varg
00400         );
00401 
00402 MCAgent_t
00403 MC_ComposeAgent(
00404     const char* name,
00405     const char* home,
00406     const char* owner, 
00407     const char* code,
00408     const char* return_var_name,
00409     const char* server,
00410     int persistent
00411     );
00412 
00423 EXPORTMC extern int MC_CondBroadcast(MCAgency_t attr, int id);
00424 
00440 EXPORTMC extern int MC_CondSignal(MCAgency_t attr, int id);
00441 
00452 EXPORTMC extern int MC_CondReset(MCAgency_t attr, int id);
00453 
00467 EXPORTMC extern int MC_CondWait(MCAgency_t attr, int id);
00468 
00478 int MC_CopyAgent(MCAgent_t* agent_out, const MCAgent_t agent_in);
00479 
00488 EXPORTMC extern int MC_DeleteAgent(MCAgent_t agent);
00489 
00500 EXPORTMC extern int MC_End(MCAgency_t attr);
00501 
00512 int MC_DestroyServiceSearchResult(
00513     char** agentName,
00514     char** serviceName,
00515     int* agentID,
00516     int numResult);
00517 
00518 
00529 EXPORTMC extern MCAgent_t MC_FindAgentByName(MCAgency_t attr, const char *name);
00530 
00539 EXPORTMC extern MCAgent_t MC_FindAgentByID(MCAgency_t attr, int ID);
00540 
00549 EXPORTMC extern /*ChInterp_t*/ void* MC_GetAgentExecEngine(MCAgent_t agent);
00550 
00554 EXPORTMC extern int MC_GetAgentID(MCAgent_t agent);
00555 
00556 /*
00557  * \brief           Retrieve an agent's name
00558  *
00559  * \return          a malloc'd character string on success, or NULL on failure
00560  */
00561 EXPORTMC extern char* MC_GetAgentName(MCAgent_t agent);
00562 
00568 EXPORTMC extern int MC_GetAgentNumTasks(MCAgent_t agent);
00569 
00586 EXPORTMC extern int MC_GetAgentReturnData(
00587         MCAgent_t agent,
00588         int task_num,
00589         void **data,
00590         int *dim,
00591         int **extent);
00592 
00598 EXPORTMC extern int MC_GetAgentStatus(MCAgent_t agent);
00599 
00605 EXPORTMC extern enum MC_AgentType_e MC_GetAgentType(MCAgent_t agent);
00606 
00612 EXPORTMC extern char* MC_GetAgentXMLString(MCAgent_t agent);
00613 
00621 EXPORTMC extern int MC_HaltAgency(MCAgency_t agency);
00622 
00633 EXPORTMC extern MCAgency_t MC_Initialize(
00634         int port,
00635         MCAgencyOptions_t *options);
00636 
00649 EXPORTMC extern int MC_InitializeAgencyOptions(struct MCAgencyOptions_s* options);
00650 
00656  EXPORTMC extern int MC_MainLoop(MCAgency_t attr);
00657 
00672 EXPORTMC extern int MC_MutexLock(MCAgency_t attr, int id); 
00673 
00674 /*
00675  * \brief           Unlocks a MobileC synchronization variable
00676  *
00677  * \param attr      a MobileC agency handle
00678  * \param id        the synchronization variable id to unlock
00679  *
00680  * \return          0 on success, error_code_t type on failure
00681  *
00682  * \see             MC_MutexLock()
00683  */
00684 EXPORTMC extern int MC_MutexUnlock(MCAgency_t attr, int id); 
00685 
00703 EXPORTMC extern int MC_RegisterService(
00704         MCAgency_t agency,
00705         /* Optional input args: Must input 
00706          * MCAgent_t OR
00707          * agentID AND agentName */
00708         MCAgent_t agent,
00709         int agentID,
00710         const char *agentName,
00711         char **serviceNames,
00712         int numServices);
00713 
00721 EXPORTMC extern int MC_ResumeAgency(MCAgency_t agency);
00722 
00728 EXPORTMC extern MCAgent_t MC_RetrieveAgent(MCAgency_t attr);
00729 
00741 EXPORTMC extern int MC_SemaphorePost(MCAgency_t attr, int id);
00742 
00756 EXPORTMC extern int MC_SemaphoreWait(MCAgency_t attr, int id);
00757 
00769 EXPORTMC extern int MC_SetDefaultAgentStatus(MCAgency_t agency, enum MC_AgentStatus_e status);
00770 
00784 EXPORTMC extern int MC_SetThreadOn(MCAgencyOptions_t *options, enum MC_ThreadIndex_e index);
00785 
00794 EXPORTMC extern int MC_SetThreadsAllOn(MCAgencyOptions_t* options);
00795 
00809 EXPORTMC extern int MC_SetThreadOff(MCAgencyOptions_t *options, enum MC_ThreadIndex_e index );
00810 
00819 EXPORTMC extern int MC_SetThreadsAllOff(MCAgencyOptions_t* options);
00820 
00826 EXPORTMC extern int MC_PrintAgentCode(MCAgent_t agent);
00827 
00833 EXPORTMC extern char * MC_RetrieveAgentCode(MCAgent_t agent);
00834 
00842 EXPORTMC extern int MC_ResetSignal(MCAgency_t attr);
00843 
00859 EXPORTMC extern int MC_SearchForService(
00860         /* Input args */
00861         MCAgency_t attr, 
00862         const char *searchString,
00863         /* Return Args */
00864         char*** agentNames,
00865         char*** serviceNames,
00866         int** agentIDs,
00867         int* numResults);
00868 
00877 EXPORTMC extern int MC_SendAgentMigrationMessage(MCAgency_t attr,
00878         const char *message,
00879         const char *hostname,
00880         int port);
00881 
00890 EXPORTMC extern int MC_SendAgentMigrationMessageFile(MCAgency_t attr, 
00891         const char *filename,
00892         const char *hostname,
00893         int port);
00894 
00903 EXPORTMC extern int MC_SetAgentStatus(MCAgent_t agent, int status);
00904 
00920 EXPORTMC extern int MC_Steer( MCAgency_t attr, int (*funcptr)(void* data), void *arg);
00921 
00930 EXPORTMC extern enum MC_SteerCommand_e MC_SteerControl(void);
00931 
00940 EXPORTMC extern int MC_SyncDelete(MCAgency_t attr, int id);
00941 
00957 EXPORTMC extern int MC_SyncInit(MCAgency_t attr, int id);
00958 
00964 EXPORTMC extern int MC_TerminateAgent(MCAgent_t agent);
00965 
00971 /* EXPORTMC extern int MC_Wait(MCAgency_t attr); */
00972 
00979 EXPORTMC extern int MC_WaitAgent(MCAgency_t attr);
00980 
00989 EXPORTMC extern MCAgent_t MC_WaitRetrieveAgent(MCAgency_t attr);
00990 
01004 EXPORTMC extern int MC_WaitSignal(MCAgency_t attr, int signals);
01005 
01006 #ifdef __cplusplus
01007 }
01008 #endif
01009 #endif /* _MOBILEC_H_ */
01010 

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