GridLab
Grid Application Toolkit

A simple API for Grid Applications
GAT

Menu



Main Page   Alphabetical List   Compound List   File List   Compound Members   File Members  

file_delete_tests.c

Go to the documentation of this file.
00001 /** @file file_delete.c
00002  * Example of using the GAT to delete a file.
00003  * 
00004  * Uses the GAT to delete a file given one URI on the command line.
00005  * 
00006  * @date Thu Oct 16 2003
00007  * 
00008  * @version $Header: /export/cvs-gridlab/wp-1/Codes/GATEngine/C-reference/test/simple/file_delete_tests.c,v 1.8 2004/04/20 17:04:59 hartmutkaiser Exp $
00009  *
00010  *  Copyright (C) Hartmut Kaiser
00011  *  This file is part of the GAT Engine.
00012  *  Contributed by Hartmut Kaiser <hartmutkaiser [at] t-online [dot] de>.
00013  *
00014  *  Use, modification and distribution is subject to the Gridlab Software
00015  *  License. (See accompanying file GLlicense.txt or copy at
00016  *  http://www.gridlab.org/GLlicense.txt)
00017  */
00018 
00019 static const char *rcsid = "$Header: /export/cvs-gridlab/wp-1/Codes/GATEngine/C-reference/test/simple/file_delete_tests.c,v 1.8 2004/04/20 17:04:59 hartmutkaiser Exp $";
00020 
00021 /* System Header Files */
00022 
00023 #include <stdio.h>
00024 #include <stdlib.h>
00025 #include <string.h>
00026 
00027 /* GAT Header Files */
00028 
00029 #include <GAT.h>
00030 #include <GATTestUtils.h>
00031 
00032 /* Macros */
00033 
00034 /* Structures, unions and enums */
00035 
00036 /* Static function prototypes */
00037 static GATResult 
00038   Listener_FileDeleted(void *data, GATMetricEvent event);
00039 
00040 /* File scope variables */
00041 static GATStaticMetric metric_data = {
00042   /* fileops.file_copied event */
00043   "fileops.file_deleted",         /* name */
00044   GATMeasurementType_EventLike,   /* type */
00045   GATType_String,                 /* data type */
00046   "",                             /* unit */
00047   0,                              /* parameter count */
00048   0                               /* parameters */
00049 };
00050 
00051 /* External functions */
00052 
00053 int main (void)
00054 {
00055   GATResult   retcode = GAT_FAIL;
00056   GATContext  context = NULL;
00057   GATLocation source  = NULL;
00058   GATMetric   metric  = NULL;
00059   GATFile     file    = NULL;
00060   GATuint32   cookie  = 0;
00061   const char* src     = NULL;
00062 
00063   GAT_TEST_INIT  (-1);
00064   GAT_TEST_SUITE ("File")
00065 
00066   context = GATContext_Create ();
00067   GAT_TEST(NULL != context);
00068   
00069   /* the following test makes sure, that there were no errors during the 
00070      creation of the GATContext object */
00071   GAT_TEST_TRACE(GATType_GATContext == GATContext_GetType(context), context);
00072 
00073   GAT_TEST_START ("File Delete Test");
00074 
00075   src = GATTest_CreateTempFile ("gat_src");
00076   GAT_TEST_TRACE (NULL != src, context);
00077 
00078   source = GATLocation_Create(src);
00079   GAT_TEST_TRACE (NULL != source, context);
00080 
00081   file = GATFile_Create(context,source, NULL);
00082   GAT_TEST_TRACE (NULL != file, context);
00083   
00084   /* install the event handler */
00085   retcode = GATMetric_CreateMetric(&metric_data, &metric);
00086   GAT_TEST_TRACE (GAT_SUCCESS == retcode, context)
00087   
00088   retcode = GATMonitorable_AddMetricListener(GATFile_ToGATObject(file), 
00089     Listener_FileDeleted, (char*) src, metric, &cookie);
00090   GAT_TEST_TRACE (GAT_SUCCESS == retcode, context)
00091 
00092   retcode = GATFile_Delete(file);      
00093   GAT_TEST_TRACE (GAT_SUCCESS == retcode, context)
00094           
00095   if (0 != cookie)
00096   {
00097     retcode = GATMonitorable_RemoveRegisteredMetric(GATFile_ToGATObject(file), 
00098       metric, cookie);
00099     GAT_TEST_TRACE (GAT_SUCCESS == retcode, context);
00100   }
00101     
00102   GATFile_Destroy     (&file);
00103   GATMetric_Destroy   (&metric);
00104   GATLocation_Destroy (&source);
00105   GATContext_Destroy  (&context);
00106 
00107   GAT_TEST_STOP ();
00108   GAT_TEST_FINISH();
00109 
00110   return (retcode);
00111 }
00112 
00113 /* Local functions */
00114 
00115 static GATResult 
00116 Listener_FileDeleted (void *data, GATMetricEvent event)
00117 {
00118   char    name[1024] = "";
00119   GATType type       = GATType_NoType;
00120   int     retval     = 0;
00121   
00122   GAT_TEST_START ("Listener_FileDeleted");
00123   type = GATMetricEvent_GetValueType (event);
00124   retval = GATMetricEvent_GetValue (event, name, sizeof(name));
00125   
00126   GAT_TEST (GAT_SUCCESS == retval);
00127   GAT_TEST (GATType_String == type);
00128   GAT_TEST (!strcmp((char const *)data, name));
00129 
00130   GAT_TEST_STOP ();
00131   
00132   return GAT_SUCCESS;
00133 }
00134