00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036 #ifndef _WIN32
00037 #include "config.h"
00038 #else
00039 #include "winconfig.h"
00040 #endif
00041
00042 #include "include/interpreter_variable_data.h"
00043 #include "include/agent.h"
00044
00045 interpreter_variable_data_p
00046 interpreter_variable_data_New(void)
00047 {
00048 interpreter_variable_data_p agent_variable_data;
00049 agent_variable_data = (interpreter_variable_data_p)malloc(sizeof(interpreter_variable_data_t));
00050 CHECK_NULL(agent_variable_data, exit(0););
00051 agent_variable_data->name = NULL;
00052 agent_variable_data->size = 0;
00053 agent_variable_data->data_type = (ChType_t)0;
00054 agent_variable_data->array_dim = 0;
00055 agent_variable_data->array_extent = NULL;
00056 agent_variable_data->data = NULL;
00057 return agent_variable_data;
00058 }
00059
00060 interpreter_variable_data_p
00061 interpreter_variable_data_InitializeFromAgent(agent_p agent)
00062 {
00063 int i;
00064 int size;
00065 int data_type_size;
00066 int progress;
00067 interpreter_variable_data_t *agent_return;
00068 agent_return = (interpreter_variable_data_t*)malloc(sizeof(interpreter_variable_data_t));
00069 agent_return->name = strdup(
00070 agent->datastate->tasks[agent->datastate->task_progress]
00071 ->var_name );
00072
00073
00074 agent_return->data_type = Ch_DataType(
00075 *agent->agent_interp,
00076 agent->datastate->tasks[agent->datastate->task_progress]
00077 ->var_name );
00078
00079 agent_return->array_dim = Ch_ArrayDim(
00080 *agent->agent_interp,
00081 agent->datastate->tasks[agent->datastate->task_progress]
00082 ->var_name );
00083
00084 agent_return->array_extent = (int*)malloc(
00085 sizeof(int) * agent_return->array_dim );
00086 for (i=0; i<agent_return->array_dim; i++) {
00087 agent_return->array_extent[i] =
00088 Ch_ArrayExtent(
00089 *agent->agent_interp,
00090 agent->datastate
00091 ->tasks[agent->datastate->task_progress]
00092 ->var_name,
00093 i );
00094 }
00095
00096 size = 1;
00097 for (i=0; i < agent_return->array_dim; i++) {
00098 size *= agent_return->array_extent[i];
00099 }
00100
00101
00102 CH_DATATYPE_SIZE(agent_return->data_type, data_type_size);
00103
00104 agent_return->data = (void*)malloc(size * data_type_size);
00105 CHECK_NULL(agent_return->data, exit(0));
00106
00107
00108 progress = agent->datastate->task_progress;
00109 i = 0;
00110
00111 if (agent_return->array_dim == 0) {
00112 memcpy(
00113 agent_return->data,
00114 (void*)Ch_GlobalSymbolAddrByName(
00115 *agent->agent_interp,
00116 agent->datastate->tasks[progress]->var_name),
00117 size*data_type_size
00118 );
00119
00120 } else {
00121 memcpy(
00122 agent_return->data,
00123 (void*)Ch_GlobalSymbolAddrByName(
00124 *agent->agent_interp,
00125 agent->datastate->tasks[progress]->var_name),
00126 size*data_type_size
00127 );
00128 }
00129 agent_return->size = size*data_type_size;
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141 return agent_return;
00142 }
00143
00144 interpreter_variable_data_p
00145 interpreter_variable_data_Initialize(agent_p agent, const char* varname)
00146 {
00147 int i;
00148 int size;
00149 int data_type_size;
00150 interpreter_variable_data_t *interp_variable;
00151
00152
00153 MUTEX_LOCK(agent->run_lock);
00154
00155 interp_variable = (interpreter_variable_data_t*)malloc(sizeof(interpreter_variable_data_t));
00156 interp_variable->name = strdup(varname);
00157
00158
00159 interp_variable->data_type = Ch_DataType(
00160 *agent->agent_interp,
00161 varname );
00162
00163 interp_variable->array_dim = Ch_ArrayDim(
00164 *agent->agent_interp,
00165 varname );
00166
00167 interp_variable->array_extent = (int*)malloc(
00168 sizeof(int) * interp_variable->array_dim );
00169 for (i=0; i<interp_variable->array_dim; i++) {
00170 interp_variable->array_extent[i] =
00171 Ch_ArrayExtent(
00172 *agent->agent_interp,
00173 varname,
00174 i );
00175 }
00176
00177 size = 1;
00178 for (i=0; i < interp_variable->array_dim; i++) {
00179 size *= interp_variable->array_extent[i];
00180 }
00181
00182
00183 CH_DATATYPE_SIZE(interp_variable->data_type, data_type_size);
00184
00185 interp_variable->data = (void*)malloc(size * data_type_size);
00186 CHECK_NULL(interp_variable->data, exit(0));
00187
00188
00189 i = 0;
00190
00191 if (interp_variable->array_dim == 0) {
00192 memcpy(
00193 interp_variable->data,
00194 (void*)Ch_GlobalSymbolAddrByName(
00195 *agent->agent_interp,
00196 varname),
00197 size*data_type_size
00198 );
00199
00200 } else {
00201 memcpy(
00202 interp_variable->data,
00203 (void*)Ch_GlobalSymbolAddrByName(
00204 *agent->agent_interp,
00205 varname),
00206 size*data_type_size
00207 );
00208 }
00209 interp_variable->size = size*data_type_size;
00210
00211 MUTEX_UNLOCK(agent->run_lock);
00212 return interp_variable;
00213 }
00214
00215 int
00216 interpreter_variable_data_Destroy(interpreter_variable_data_p agent_variable_data)
00217 {
00218 if (agent_variable_data == NULL) {
00219 return MC_SUCCESS;
00220 }
00221 if (agent_variable_data->name != NULL) {
00222 free(agent_variable_data->name);
00223 }
00224 if (agent_variable_data->array_extent != NULL) {
00225 free(agent_variable_data->array_extent);
00226 }
00227 if (agent_variable_data->data != NULL) {
00228 free(agent_variable_data->data);
00229 }
00230 free(agent_variable_data);
00231 return MC_SUCCESS;
00232 }
00233
00234 interpreter_variable_data_p
00235 interpreter_variable_data_Copy(interpreter_variable_data_p src)
00236 {
00237 struct interpreter_variable_data_s* tmp;
00238 tmp = interpreter_variable_data_New();
00239 if(src->name != NULL)
00240 tmp->name = strdup(src->name);
00241 tmp->size = src->size;
00242 tmp->data_type = src->data_type;
00243 tmp->array_dim = src->array_dim;
00244 if(src->array_extent != NULL) {
00245 tmp->array_extent = (int*)malloc(sizeof(int)*src->array_dim);
00246 memcpy(tmp->array_extent, src->array_extent, sizeof(int)*src->array_dim);
00247 }
00248 if(src->data != NULL) {
00249 tmp->data = memcpy(tmp->array_extent, src->array_extent, src->size);
00250 }
00251
00252 return tmp;
00253 }