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 #ifndef _WIN32
00036 #include "config.h"
00037 #else
00038 #include "winconfig.h"
00039 #endif
00040
00041 #include <stdio.h>
00042 #include <stdlib.h>
00043 #include <string.h>
00044 #include "include/agent_task.h"
00045 #include "include/mc_error.h"
00046
00047 agent_task_p
00048 agent_task_New(void)
00049 {
00050 agent_task_p task;
00051 task = (agent_task_p)malloc(sizeof(agent_task_t));
00052 if(task == NULL) {
00053 fprintf(stderr, "Memory Error. %s:%d\n", __FILE__, __LINE__);
00054 } else {
00055 memset(task, 0, sizeof(agent_task_t));
00056 }
00057 task->agent_variable_list = agent_variable_list_New();
00058
00059 task->saved_variables = NULL;
00060 task->num_saved_variables = 0;
00061
00062 return task;
00063 }
00064
00065 agent_task_p
00066 agent_task_Copy(agent_task_p task)
00067 {
00068 int i;
00069 interpreter_variable_data_t* interp_data;
00070 agent_task_p cp_task;
00071 cp_task = (agent_task_p)malloc(sizeof(agent_task_t));
00072
00073 cp_task->number_of_elements = task->number_of_elements;
00074 cp_task->size_of_element_array = task->size_of_element_array;
00075 cp_task->persistent = task->persistent;
00076 cp_task->init_agent_status = task->init_agent_status;
00077
00078 cp_task->var_name = (char*)malloc
00079 (
00080 sizeof(char) *
00081 (strlen(task->var_name) + 1)
00082 );
00083 strcpy(cp_task->var_name, task->var_name);
00084
00085 cp_task->server_name = (char*)malloc
00086 (
00087 sizeof(char) *
00088 (strlen(task->server_name) + 1)
00089 );
00090 strcpy(cp_task->server_name, task->server_name);
00091
00092 if (task->code_id != NULL) {
00093 cp_task->code_id = (char*)malloc
00094 (
00095 sizeof(char) *
00096 (strlen(task->code_id) + 1)
00097 );
00098 strcpy(cp_task->code_id, task->code_id);
00099 } else {
00100 cp_task->code_id = NULL;
00101 }
00102
00103 if(task->agent_return_data != NULL) {
00104 cp_task->agent_return_data = interpreter_variable_data_Copy(task->agent_return_data);
00105 }
00106
00107
00108 cp_task->agent_variable_list = agent_variable_list_New();
00109 for(i = 0; i < task->agent_variable_list->size; i++) {
00110 interp_data = (interpreter_variable_data_t*)ListSearch(
00111 (list_p)task->agent_variable_list,
00112 i );
00113 if (interp_data == NULL) { continue; }
00114 interp_data = interpreter_variable_data_Copy(interp_data);
00115 ListAdd(
00116 (list_p)cp_task->agent_variable_list,
00117 interp_data
00118 );
00119 }
00120
00121 cp_task->saved_variables = (char**)malloc(sizeof(char*) * (task->num_saved_variables+1));
00122 for(i = 0; i < task->num_saved_variables; i++) {
00123 cp_task->saved_variables[i] = strdup(task->