00001 /* SVN FILE INFO 00002 * $Revision: 316 $ : Last Committed Revision 00003 * $Date: 2009-04-29 16:40:54 -0700 (Wed, 29 Apr 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 _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 agent_task_p cp_task; 00069 cp_task = (agent_task_p)malloc(sizeof(agent_task_t)); 00070 00071 cp_task->number_of_elements = task->number_of_elements; 00072 cp_task->size_of_element_array = task->size_of_element_array; 00073 cp_task->persistent = task->persistent; 00074 cp_task->init_agent_status = task->init_agent_status; 00075 00076 cp_task->var_name = malloc 00077 ( 00078 sizeof(char) * 00079 (strlen(task->var_name) + 1) 00080 ); 00081 strcpy(cp_task->var_name, task->var_name); 00082 00083 cp_task->server_name = malloc 00084 ( 00085 sizeof(char) * 00086 (strlen(task->server_name) + 1) 00087 ); 00088 strcpy(cp_task->server_name, task->server_name); 00089 00090 if (task->code_id != NULL) { 00091 cp_task->code_id = malloc 00092 ( 00093 sizeof(char) * 00094 (strlen(task->code_id) + 1) 00095 ); 00096 strcpy(cp_task->code_id, task->code_id); 00097 } else { 00098 cp_task->code_id = NULL; 00099 } 00100 00101 cp_task->agent_return_data = NULL; 00102 00103 return cp_task; 00104 } 00105 00106 int 00107 agent_task_Destroy( agent_task_p agent_task ) 00108 { 00109 int i; 00110 if(agent_task == NULL) { 00111 return MC_SUCCESS; 00112 } 00113 if (agent_task->var_name != NULL) { 00114 free(agent_task->var_name); 00115 } 00116 if (agent_task->server_name != NULL) { 00117 free(agent_task->server_name); 00118 } 00119 if (agent_task->code_id != NULL) { 00120 free(agent_task->code_id); 00121 } 00122 00123 agent_variable_list_Destroy(agent_task->agent_variable_list); 00124 00125 if(agent_task->saved_variables != NULL) { 00126 for(i = 0; agent_task->saved_variables[i] != NULL; i++) { 00127 free(agent_task->saved_variables[i]); 00128 } 00129 free(agent_task->saved_variables); 00130 } 00131 00132 interpreter_variable_data_Destroy(agent_task->agent_return_data); 00133 00134 free(agent_task); 00135 00136 return MC_SUCCESS; 00137 } 00138