/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 
00049 /* Filename: libmc.h */
00050 /* Current functions implemented 
00051 MC_AclDestroy
00052 MC_AclNew
00053 MC_AclPost
00054 MC_AclReply
00055 MC_AclRetrieve
00056 MC_AclSend
00057 MC_AclWaitRetrieve
00058 MC_AddAgent 
00059 MC_Barrier 
00060 MC_BarrierInit 
00061 MC_BarrierDelete 
00062 MC_CallAgentFunc
00063 MC_ChInitializeOptions 
00064 MC_ComposeAgent
00065 MC_CondBroadcast 
00066 MC_CondSignal 
00067 MC_CondWait  
00068 MC_CondReset 
00069 MC_CopyAgent 
00070 MC_DeleteAgent 
00071 MC_DeregisterService
00072 MC_End 
00073 MC_FindAgentByName
00074 MC_FindAgentByID
00075 MC_GetAgentArrivalTime 
00076 MC_GetAgentStatus 
00077 MC_GetAgentXMLString 
00078 MC_GetAgentExecEngine 
00079 MC_GetAgentID
00080 MC_GetAgentName
00081 MC_GetAgentReturnData
00082 MC_GetAgentNumTasks 
00083 MC_GetAgentType 
00084 MC_GetAllAgents 
00085 MC_HaltAgency 
00086 MC_Initialize
00087 MC_InitializeAgencyOptions 
00088 MC_MutexLock 
00089 MC_MutexUnlock 
00090 MC_PrintAgentCode 
00091 MC_RegisterService
00092 MC_ResumeAgency 
00093 MC_RetrieveAgent 
00094 MC_RetrieveAgentCode 
00095 MC_ResetSignal 
00096 MC_SearchForService
00097 MC_SemaphorePost 
00098 MC_SemaphoreWait 
00099 MC_SendCh
00100 MC_SendAgentMigrationMessage
00101 MC_SendAgentMigrationMessageFile
00102 MC_SendSteerCommand 
00103 MC_SetAgentStatus 
00104 MC_SetDefaultAgentStatus
00105 MC_SetThreadOn 
00106 MC_SetThreadsAllOn
00107 MC_SetThreadOff 
00108 MC_SetThreadsAllOff
00109 MC_Steer
00110 MC_SteerControl 
00111 MC_SyncDelete 
00112 MC_SyncInit 
00113 MC_TerminateAgent 
00114 MC_MainLoop 
00115 MC_MainLoop
00116 MC_WaitAgent 
00117 MC_WaitRetrieveAgent 
00118 MC_WaitSignal 
00119 
00120    *** */
00121 
00122 #ifndef _MOBILEC_H_
00123 #define _MOBILEC_H_
00124 
00125 #ifdef WIN32
00126         #ifdef _MC_DLL
00127                 // Building a .dll - export functions as marked
00128                 #define EXPORTMC _declspec(dllexport)
00129         #else
00130                 // Not building a .dll - building .lib assumed - no export required
00131                 #define EXPORTMC
00132         #endif
00133 #else
00134         // Not windows
00135         #define EXPORTMC
00136 #endif
00137 
00138 /* The MC_Wait() function is deprecated as of version 1.9.4.
00139  * All calls to MC_Wait() should now be changed to MC_MainLoop() */
00140 #define MC_Wait(arg1) \
00141   MC_MainLoop(arg1)
00142 
00143 #include <embedch.h>
00144 #ifdef __cplusplus
00145 extern "C" {
00146 #endif
00147 
00148 #ifndef _ERROR_CODE_E_
00149 #define _ERROR_CODE_E_
00150 /*
00151  * Error Codes
00152  * NOTE: There is a copy of this enum in mc_error.h
00153  * */
00154 typedef enum error_code_e {
00155     MC_SUCCESS = 0,
00156     MC_ERR,
00157     MC_ERR_CONNECT,
00158     MC_ERR_PARSE,
00159     MC_ERR_EMPTY,
00160     MC_ERR_INVALID,
00161     MC_ERR_INVALID_ARGS,
00162     MC_ERR_NOT_FOUND,
00163     MC_ERR_MEMORY,
00164     MC_ERR_SEND,
00165     MC_WARN_DUPLICATE
00166 } error_code_t;
00167 #endif
00168 
00172 enum MC_ThreadIndex_e{ 
00173     MC_THREAD_DF=0,   
00174     MC_THREAD_AMS,    
00175     MC_THREAD_ACC,    
00176     MC_THREAD_CP,     
00177     MC_THREAD_AGENT,  
00178     MC_THREAD_ALL };
00179 
00180 
00184 typedef enum MC_SteerCommand_e {
00185   MC_RUN = 0,     
00186   MC_SUSPEND,     
00187   MC_RESTART,     
00188   MC_STOP         
00189 } MC_SteerCommand_t;
00190 
00199 enum MC_Signal_e{
00200     MC_NO_SIGNAL      =0x00, 
00201     MC_RECV_CONNECTION=0x01, 
00202     MC_RECV_MESSAGE   =0x02, 
00203     MC_RECV_AGENT     =0x04, 
00204     MC_RECV_RETURN    =0x08, 
00205     MC_EXEC_AGENT     =0x0F, 
00206     MC_ALL_SIGNALS    =0x10  
00207 };
00208 
00212 typedef struct agency_s {
00213     int client;
00214     int server;
00215     char *hostName;                     
00216     char *filename;
00217     int portno;                         
00218     int portnoc;
00219     struct mc_platform_s* mc_platform;  
00220     int default_agentstatus;            
00221     int threads;                        
00222     int enable_security;                
00223     int stack_size[MC_THREAD_ALL];
00224     error_code_t last_error;
00225 } agency_t;
00226 typedef agency_t* agency_p;
00227 typedef agency_p MCAgency_t;
00228 
00232 typedef struct MCAgencyOptions_s{
00233     int threads;              
00234     int default_agent_status; 
00235     int modified;             
00236     int enable_security;      
00238     /* Following are some thread stack size options: unix/pthreads only! */
00239     int stack_size[MC_THREAD_ALL]; 
00240 } MCAgencyOptions_t;
00241 
00242 #ifndef AGENT_T
00243 #define AGENT_T
00244 typedef struct agent_s agent_t;
00245 typedef agent_t* MCAgent_t;
00246 typedef agent_t* agent_p;
00247 #endif
00248 
00249 enum MC_AgentType_e{ MC_NONE = -1, MC_REMOTE_AGENT = 0, MC_LOCAL_AGENT, MC_RETURN_AGENT };
00250 
00254 enum MC_AgentStatus_e{ 
00255         MC_NO_STATUS = -1,
00256     MC_WAIT_CH = 0,    
00257     MC_WAIT_MESSGSEND, 
00258     MC_AGENT_ACTIVE,   
00259     MC_AGENT_NEUTRAL,  
00260     MC_AGENT_SUSPENDED,
00261     MC_WAIT_FINISHED   
00262 };
00263 
00264 struct fipa_acl_message_s;
00265 
00273 EXPORTMC int 
00274 MC_AclDestroy(struct fipa_acl_message_s* message);
00275 
00281 EXPORTMC extern struct fipa_acl_message_s*
00282 MC_AclNew(void);
00283 
00292 EXPORTMC extern int MC_AclPost(MCAgent_t agent, struct fipa_acl_message_s* message);
00293 
00304 EXPORTMC extern struct fipa_acl_message_s*
00305 MC_AclReply(struct fipa_acl_message_s* acl_message);
00306 
00314 EXPORTMC extern struct fipa_acl_message_s* MC_AclRetrieve(MCAgent_t agent);
00315 
00324 EXPORTMC extern int MC_AclSend(MCAgency_t attr, struct fipa_acl_message_s* acl);
00325 
00333 EXPORTMC extern struct fipa_acl_message_s* MC_AclWaitRetrieve(MCAgent_t agent);
00334 
00335 /* ACL Helper Functions Here */
00336 enum fipa_performative_e;
00337 
00338 EXPORTMC int MC_AclSetPerformative(
00339     struct fipa_acl_message_s* acl,
00340     enum fipa_performative_e performative );
00341 
00342 EXPORTMC int MC_AclSetSender(
00343     struct fipa_acl_message_s* acl,
00344     const char* name,
00345     const char* address );
00346   
00347 EXPORTMC int MC_AclAddReceiver(
00348     struct fipa_acl_message_s* acl,
00349     const char* name,
00350     const char* address );
00351 
00352 EXPORTMC int MC_AclAddReplyTo(
00353     struct fipa_acl_message_s* acl,
00354     const char* name,
00355     const char* address);
00356 
00357 EXPORTMC int MC_AclSetContent(
00358     struct fipa_acl_message_s* acl,
00359     const char* content );
00360 
00361 /* End ACL Helper Functions */
00362 
00363 
00372 EXPORTMC extern int MC_AddAgent( 
00373     MCAgency_t attr, 
00374     MCAgent_t agent);
00375 
00391 extern const void* 
00392 MC_AgentVariableRetrieve(
00393     MCAgent_t agent,
00394     const char* var_name,
00395     int task_num);
00396 
00414 extern int 
00415 MC_AgentVariableSave(MCAgent_t agent, const char* var_name);
00416 
00426 EXPORTMC extern int MC_BarrierDelete(MCAgency_t attr, int id);
00427 
00443 EXPORTMC extern int MC_BarrierInit(MCAgency_t attr, int id, int num_procs);
00444 
00453 EXPORTMC extern int MC_ChInitializeOptions(MCAgency_t attr, ChOptions_t *options);
00454 
00471 EXPORTMC extern int MC_CallAgentFunc(
00472         MCAgent_t agent,
00473         const char* funcName,
00474         void* returnVal,
00475         void* varg
00476         );
00477 
00478 
00492 MCAgent_t
00493 MC_ComposeAgent(
00494     const char* name,
00495     const char* home,
00496     const char* owner, 
00497     const char* code,
00498     const char* return_var_name,
00499     const char* server,
00500     int persistent
00501     );
00502 
00513 EXPORTMC extern int MC_CondBroadcast(MCAgency_t attr, int id);
00514 
00530 EXPORTMC extern int MC_CondSignal(MCAgency_t attr, int id);
00531 
00542 EXPORTMC extern int MC_CondReset(MCAgency_t attr, int id);
00543 
00557 EXPORTMC extern int MC_CondWait(MCAgency_t attr, int id);
00558 
00568 int MC_CopyAgent(MCAgent_t* agent_out, const MCAgent_t agent_in);
00569 
00578 EXPORTMC extern int MC_DeleteAgent(MCAgent_t agent);
00579 
00590 EXPORTMC extern int MC_End(MCAgency_t attr);
00591 
00602 int MC_DestroyServiceSearchResult(
00603     char** agentName,
00604     char** serviceName,
00605     int* agentID,
00606     int numResult);
00607 
00608 
00619 EXPORTMC extern MCAgent_t MC_FindAgentByName(MCAgency_t attr, const char *name);
00620 
00629 EXPORTMC extern MCAgent_t MC_FindAgentByID(MCAgency_t attr, int ID);
00630 
00639 EXPORTMC extern /*ChInterp_t*/ void* MC_GetAgentExecEngine(MCAgent_t agent);
00640 
00644 EXPORTMC extern int MC_GetAgentID(MCAgent_t agent);
00645 
00646 /*
00647  * \brief           Retrieve an agent's name
00648  *
00649  * \return          a malloc'd character string on success, or NULL on failure
00650  */
00651 EXPORTMC extern char* MC_GetAgentName(MCAgent_t agent);
00652 
00658 EXPORTMC extern int MC_GetAgentNumTasks(MCAgent_t agent);
00659 
00676 EXPORTMC extern int MC_GetAgentReturnData(
00677         MCAgent_t agent,
00678         int task_num,
00679         void **data,
00680         int *dim,
00681         int **extent);
00682 
00688 EXPORTMC extern int MC_GetAgentStatus(MCAgent_t agent);
00689 
00695 EXPORTMC extern enum MC_AgentType_e MC_GetAgentType(MCAgent_t agent);
00696 
00702 EXPORTMC extern char* MC_GetAgentXMLString(MCAgent_t agent);
00703 
00711 EXPORTMC extern int MC_HaltAgency(MCAgency_t agency);
00712 
00723 EXPORTMC extern MCAgency_t MC_Initialize(
00724         int port,
00725         MCAgencyOptions_t *options);
00726 
00739 EXPORTMC extern int MC_InitializeAgencyOptions(struct MCAgencyOptions_s* options);
00740 
00746  EXPORTMC extern int MC_MainLoop(MCAgency_t attr);
00747 
00756 EXPORTMC extern int MC_LoadAgentFromFile(MCAgency_t attr, const char* filename);
00757 
00772 EXPORTMC extern int MC_MutexLock(MCAgency_t attr, int id); 
00773 
00774 /*
00775  * \brief           Unlocks a MobileC synchronization variable
00776  *
00777  * \param attr      a MobileC agency handle
00778  * \param id        the synchronization variable id to unlock
00779  *
00780  * \return          0 on success, error_code_t type on failure
00781  *
00782  * \see             MC_MutexLock()
00783  */
00784 EXPORTMC extern int MC_MutexUnlock(MCAgency_t attr, int id); 
00785 
00803 EXPORTMC extern int MC_RegisterService(
00804         MCAgency_t agency,
00805         /* Optional input args: Must input 
00806          * MCAgent_t OR
00807          * agentID AND agentName */
00808         MCAgent_t agent,
00809         int agentID,
00810         const char *agentName,
00811         char **serviceNames,
00812         int numServices);
00813 
00821 EXPORTMC extern int MC_ResumeAgency(MCAgency_t agency);
00822 
00828 EXPORTMC extern MCAgent_t MC_RetrieveAgent(MCAgency_t attr);
00829 
00841 EXPORTMC extern int MC_SemaphorePost(MCAgency_t attr, int id);
00842 
00856 EXPORTMC extern int MC_SemaphoreWait(MCAgency_t attr, int id);
00857 
00869 EXPORTMC extern int MC_SetDefaultAgentStatus(MCAgency_t agency, enum MC_AgentStatus_e status);
00870 
00884 EXPORTMC extern int MC_SetThreadOn(MCAgencyOptions_t *options, enum MC_ThreadIndex_e index);
00885 
00894 EXPORTMC extern int MC_SetThreadsAllOn(MCAgencyOptions_t* options);
00895 
00909 EXPORTMC extern int MC_SetThreadOff(MCAgencyOptions_t *options, enum MC_ThreadIndex_e index );
00910 
00919 EXPORTMC extern int MC_SetThreadsAllOff(MCAgencyOptions_t* options);
00920 
00926 EXPORTMC extern int MC_PrintAgentCode(MCAgent_t agent);
00927 
00933 EXPORTMC extern char * MC_RetrieveAgentCode(MCAgent_t agent);
00934 
00942 EXPORTMC extern int MC_ResetSignal(MCAgency_t attr);
00943 
00959 EXPORTMC extern int MC_SearchForService(
00960         /* Input args */
00961         MCAgency_t attr, 
00962         const char *searchString,
00963         /* Return Args */
00964         char*** agentNames,
00965         char*** serviceNames,
00966         int** agentIDs,
00967         int* numResults);
00968 
00977 EXPORTMC extern int MC_SendAgentMigrationMessage(MCAgency_t attr,
00978         const char *message,
00979         const char *hostname,
00980         int port);
00981 
00990 EXPORTMC extern int MC_SendAgentMigrationMessageFile(MCAgency_t attr, 
00991         const char *filename,
00992         const char *hostname,
00993         int port);
00994 
01003 EXPORTMC extern int MC_SetAgentStatus(MCAgent_t agent, int status);
01004 
01020 EXPORTMC extern int MC_Steer( MCAgency_t attr, int (*funcptr)(void* data), void *arg);
01021 
01030 EXPORTMC extern enum MC_SteerCommand_e MC_SteerControl(void);
01031 
01040 EXPORTMC extern int MC_SyncDelete(MCAgency_t attr, int id);
01041 
01057 EXPORTMC extern int MC_SyncInit(MCAgency_t attr, int id);
01058 
01064 EXPORTMC extern int MC_TerminateAgent(MCAgent_t agent);
01065 
01071 /* EXPORTMC extern int MC_Wait(MCAgency_t attr); */
01072 
01079 EXPORTMC extern int MC_WaitAgent(MCAgency_t attr);
01080 
01089 EXPORTMC extern MCAgent_t MC_WaitRetrieveAgent(MCAgency_t attr);
01090 
01104 EXPORTMC extern int MC_WaitSignal(MCAgency_t attr, int signals);
01105 
01106 #ifdef __cplusplus
01107 }
01108 #endif
01109 
01110 #endif /* _MOBILEC_H_ */
01111 

Generated on Mon Jun 23 16:01:10 2008 for Mobile-C by  doxygen 1.5.4