/home/dko/projects/mobilec/trunk/src/agent_task.c

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

Generated on Mon Jun 23 16:01:09 2008 for Mobile-C by  doxygen 1.5.4