00001 /* SVN FILE INFO 00002 * $Revision: 402 $ : Last Committed Revision 00003 * $Date: 2009-08-23 13:44:39 -0700 (Sun, 23 Aug 2009) $ : Last Committed Date */ 00004 /*[ 00005 * Copyright (c) 2007 Integration Engineering Laboratory 00006 University of California, Davis 00007 * 00008 * Permission to use, copy, and distribute this software and its 00009 * documentation for any purpose with or without fee is hereby granted, 00010 * provided that the above copyright notice appear in all copies and 00011 * that both that copyright notice and this permission notice appear 00012 * in supporting documentation. 00013 * 00014 * Permission to modify the software is granted, but not the right to 00015 * distribute the complete modified source code. Modifications are to 00016 * be distributed as patches to the released version. Permission to 00017 * distribute binaries produced by compiling modified sources is granted, 00018 * provided you 00019 * 1. distribute the corresponding source modifications from the 00020 * released version in the form of a patch file along with the binaries, 00021 * 2. add special version identification to distinguish your version 00022 * in addition to the base release version number, 00023 * 3. provide your name and address as the primary contact for the 00024 * support of your modified version, and 00025 * 4. retain our contact information in regard to use of the base 00026 * software. 00027 * Permission to distribute the released version of the source code along 00028 * with corresponding source modifications in the form of a patch file is 00029 * granted with same provisions 2 through 4 for binary distributions. 00030 * 00031 * This software is provided "as is" without express or implied warranty 00032 * to the extent permitted by applicable law. 00033 ]*/ 00034 00035 #ifndef _AGENT_H_ 00036 #define _AGENT_H_ 00037 00038 #include "agent_datastate.h" 00039 #include "agent_task.h" 00040 #include "libmc.h" 00041 #include "message.h" 00042 #include "macros.h" 00043 #include "data_structures.h" 00044 #include "agent_mailbox.h" 00045 00046 struct mc_platform_s; 00047 00048 struct agent_s { 00049 00050 /* basic id numbers to determine agent characteristics */ 00051 u_long id; 00052 char* name; 00053 u_long connect_id; 00054 #ifndef _WIN32 00055 time_t arrival_time; 00056 #else 00057 SYSTEMTIME arrival_time; 00058 #endif 00059 00060 char *owner; 00061 char *home; 00062 char *sender; 00063 int home_port; 00064 char *wg_code; /* The workgroup code of the agent. Only agents of the same workgroup should 00065 be able to manipulate each other. */ 00066 char *agent_address; 00067 00068 int orphan; /* If an agent is an 'orphan', it means it is not attached to an 00069 agency. */ 00070 00071 /* primary agent data */ 00072 agent_datastate_p datastate; 00073 enum MC_AgentType_e agent_type; 00074 enum MC_AgentStatus_e agent_status; 00075 00076 int return_data; 00077 00078 /* threading variables */ 00079 ChInterp_t* agent_interp; 00080 /* run_lock should be locked whenever the interpreter is running 00081 * to prevent simultaneous runs. */ 00082 MUTEX_T *run_lock; 00083 00084 #ifndef _WIN32 00085 int agent_thread_id; 00086 #else 00087 DWORD agent_thread_id; 00088 #endif 00089 THREAD_T agent_thread; 00090 00091 /* Agent Mailbox */ 00092 agent_mailbox_p mailbox; 00093 00094 /* Agent Flags */ 00095 int agent_pipe_active; 00096 int agent_ready_to_send; 00097 int agent_pipe_ready_to_read; 00098 int agent_script_ready; 00099 int agent_persistent; 00100 00101 struct mc_platform_s *mc_platform; 00102 00103 MUTEX_T* lock; 00104 00105 int binary; /* Indicates whether or not this is a binary space agent */ 00106 }; 00107 #ifndef AGENT_T 00108 #define AGENT_T 00109 typedef struct agent_s agent_t; 00110 typedef agent_t* MCAgent_t; 00111 typedef agent_t* agent_p; 00112 #endif 00113 00114 int 00115 agent_AddPersistentVariable(agent_p agent, int task_num, const char* var_name); 00116 00117 agent_p 00118 agent_New(void); 00119 00120 agent_p 00121 agent_NewBinary( struct mc_platform_s *mc_platform); 00122 00123 agent_p 00124 agent_Copy(const agent_p agent); 00125 00126 int 00127 agent_Destroy(agent_p agent); 00128 00129 agent_p 00130 agent_Initialize( 00131 struct mc_platform_s* mc_platform, 00132 message_p message, 00133 int id); 00134 00135 int 00136 agent_Destroy(agent_p agent); 00137 00138 void agent_RunChScript(MCAgent_t agent, struct mc_platform_s* global); 00139 #ifndef _WIN32 00140 void * agent_RunChScriptThread(void * agent); 00141 #else 00142 DWORD WINAPI agent_RunChScriptThread(void * ChAgent); 00143 #endif 00144 00145 void* 00146 agent_ChScriptInitVar(ChInterp_t* interp); 00147 00148 #endif