00001 /* SVN FILE INFO 00002 * $Revision: 244 $ : Last Committed Revision 00003 * $Date: 2008-11-20 14:17:50 -0800 (Thu, 20 Nov 2008) $ : 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 00065 int orphan; /* If an agent is an 'orphan', it means it is not attached to an 00066 agency. */ 00067 00068 /* primary agent data */ 00069 agent_datastate_p datastate; 00070 enum MC_AgentType_e agent_type; 00071 enum MC_AgentStatus_e agent_status; 00072 00073 int return_data; 00074 00075 /* threading variables */ 00076 ChInterp_t agent_interp; 00077 /* run_lock should be locked whenever the interpreter is running 00078 * to prevent simultaneous runs. */ 00079 MUTEX_T *run_lock; 00080 00081 #ifndef _WIN32 00082 int agent_thread_id; 00083 #else 00084 DWORD agent_thread_id; 00085 #endif 00086 THREAD_T *agent_thread; 00087 00088 /* Agent Mailbox */ 00089 agent_mailbox_p mailbox; 00090 00091 /* Agent Flags */ 00092 int agent_pipe_active; 00093 int agent_ready_to_send; 00094 int agent_pipe_ready_to_read; 00095 int agent_script_ready; 00096 int agent_persistent; 00097 00098 struct mc_platform_s *mc_platform; 00099 00100 MUTEX_T* lock; 00101 }; 00102 #ifndef AGENT_T 00103 #define AGENT_T 00104 typedef struct agent_s agent_t; 00105 typedef agent_t* MCAgent_t; 00106 typedef agent_t* agent_p; 00107 #endif 00108 00109 int 00110 agent_AddPersistentVariable(agent_p agent, int task_num, const char* var_name); 00111 00112 agent_p 00113 agent_New(void); 00114 00115 agent_p 00116 agent_Copy(const agent_p agent); 00117 00118 int 00119 agent_Destroy(agent_p agent); 00120 00121 agent_p 00122 agent_Initialize( 00123 struct mc_platform_s* mc_platform, 00124 message_p message, 00125 int id); 00126 00127 int 00128 agent_Destroy(agent_p agent); 00129 00130 void agent_RunChScript(MCAgent_t agent, struct mc_platform_s* global); 00131 #ifndef _WIN32 00132 void * agent_RunChScriptThread(void * agent); 00133 #else 00134 DWORD WINAPI agent_RunChScriptThread(void * ChAgent); 00135 #endif 00136 00137 #endif