/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 
00049   return task;
00050 }
00051 
00052 agent_task_p 
00053 agent_task_Copy(agent_task_p task)
00054 {
00055   agent_task_p cp_task;
00056   cp_task = (agent_task_p)malloc(sizeof(agent_task_t));
00057 
00058   cp_task->task_completed = task->task_completed;
00059   cp_task->number_of_elements = task->number_of_elements;
00060   cp_task->size_of_element_array = task->size_of_element_array;
00061   cp_task->persistent = task->persistent;
00062   cp_task->init_agent_status = task->init_agent_status;
00063 
00064   cp_task->var_name = malloc
00065     (
00066      sizeof(char) * 
00067      (strlen(task->var_name) + 1)
00068     );
00069   strcpy(cp_task->var_name, task->var_name);
00070 
00071   cp_task->server_name = malloc
00072     (
00073      sizeof(char) * 
00074      (strlen(task->server_name) + 1)
00075     );
00076   strcpy(cp_task->server_name, task->server_name);
00077 
00078   if (task->code_id != NULL) {
00079     cp_task->code_id = malloc
00080       (
00081        sizeof(char) * 
00082        (strlen(task->code_id) + 1)
00083       );
00084     strcpy(cp_task->code_id, task->code_id);
00085   } else {
00086     cp_task->code_id = NULL;
00087   }
00088 
00089   cp_task->agent_return_data = NULL;
00090 
00091   return cp_task;
00092 }
00093 
00094 int
00095 agent_task_Destroy( agent_task_p agent_task )
00096 {
00097   if(agent_task == NULL) {
00098     return MC_SUCCESS;
00099   }
00100   if (agent_task->var_name != NULL) {
00101     free(agent_task->var_name);
00102   }
00103   if (agent_task->server_name != NULL) {
00104     free(agent_task->server_name);
00105   }
00106   if (agent_task->code_id != NULL) {
00107     free(agent_task->code_id);
00108   }
00109 
00110   agent_return_data_Destroy(agent_task->agent_return_data);
00111 
00112   free(agent_task);
00113 
00114   return MC_SUCCESS;
00115 }
00116 

Generated on Fri May 16 14:49:54 2008 for Mobile-C by  doxygen 1.5.4