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 00032 #ifndef _AGENT_H_ 00033 #define _AGENT_H_ 00034 00035 #include "agent_datastate.h" 00036 #include "agent_task.h" 00037 #include "libmc.h" 00038 #include "message.h" 00039 #include "macros.h" 00040 #include "data_structures.h" 00041 #include "agent_mailbox.h" 00042 00043 struct mc_platform_s; 00044 00045 struct agent_s { 00046 00047 /* basic id numbers to determine agent characteristics */ 00048 u_long id; 00049 char* name; 00050 u_long connect_id; 00051 #ifndef _WIN32 00052 time_t arrival_time; 00053 #else 00054 SYSTEMTIME arrival_time; 00055 #endif 00056 00057 char *owner; 00058 char *home; 00059 int home_port; 00060 00061 int orphan; /* If an agent is an 'orphan', it means it is not attached to an 00062 agency. */ 00063 00064 /* primary agent data */ 00065 agent_datastate_p datastate; 00066 enum MC_AgentType_e agent_type; 00067 enum MC_AgentStatus_e agent_status; 00068 00069 int return_data; 00070 00071 /* threading variables */ 00072 ChInterp_t agent_interp; 00073 /* run_lock should be locked whenever the interpreter is running 00074 * to prevent simultaneous runs. */ 00075 MUTEX_T *run_lock; 00076 00077 #ifndef _WIN32 00078 int agent_thread_id; 00079 #else 00080 DWORD agent_thread_id; 00081 #endif 00082 THREAD_T *agent_thread; 00083 00084 /* Agent Mailbox */ 00085 agent_mailbox_p mailbox; 00086 00087 /* Agent Flags */ 00088 int agent_pipe_active; 00089 int agent_ready_to_send; 00090 int agent_pipe_ready_to_read; 00091 int agent_script_ready; 00092 int agent_persistent; 00093 00094 struct mc_platform_s *mc_platform; 00095 00096 MUTEX_T* lock; 00097 }; 00098 #ifndef AGENT_T 00099 #define AGENT_T 00100 typedef struct agent_s agent_t; 00101 typedef agent_t* MCAgent_t; 00102 typedef agent_t* agent_p; 00103 #endif 00104 00105 agent_p 00106 agent_New(void); 00107 00108 agent_p 00109 agent_Copy(const agent_p agent); 00110 00111 agent_p 00112 agent_Initialize( 00113 struct mc_platform_s* mc_platform, 00114 message_p message, 00115 int id); 00116 00117 int 00118 agent_Destroy(agent_p agent); 00119 00120 void agent_RunChScript(MCAgent_t agent, struct mc_platform_s* global); 00121 #ifndef _WIN32 00122 void * agent_RunChScriptThread(void * agent); 00123 #else 00124 DWORD WINAPI agent_RunChScriptThread(void * ChAgent); 00125 #endif 00126 00127 #endif