aboutsummaryrefslogtreecommitdiff
path: root/src/AdvertisedFiles.c
blob: 0126ceb94470dfa205a505195abb2e957d95dda7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
  /*@@
   @file      AdvertisedFiles.c
   @date      Mon 18 Sep 2000
   @author    Thomas Radke
   @desc
              IOUtil file advertising stuff.
   @enddesc
   @history
   @endhistory
 @@*/

#include <stdlib.h>

#include "cctk.h"
#include "StoreNamedData.h"
#include "ioGH.h"
#include "ioutil_AdvertisedFiles.h"


static const char *rcsid = "$Header$";
CCTK_FILEVERSION(CactusBase_IOUtil_AdvertisedFiles_c)


/********************************************************************
 *********************     Local Data   *****************************
 ********************************************************************/

/* database holding all registered listeners for file advertising */
static pNamedData *listener_DB = NULL;


 /*@@
   @routine    IOUtil_RegisterAdvertisedFileListener
   @date       Wed May 17 2000
   @author     Thomas Radke
   @desc
               Registers a listener with its callbacks for
               advertised file handling
   @enddesc
   @history
   @endhistory
   @var        GH
   @vdesc      pointer to grid hierarchy
   @vtype      const cGH *
   @vio        in
   @endvar
   @var        listener
   @vdesc      identification of the listener to be registered
   @vtype      const char *
   @vio        in
   @endvar
   @var        callbacks
   @vdesc      structure containing the listener's callback routines
   @vtype      const ioAdvertisedFileListenerCallbacks *
   @vio        in
   @endvar
   @returntype int
   @returndesc This routine returns
                  0  on success
                  -1 if memory allocation failed or NULL pointers were passed
   @endreturndesc
@@*/

int IOUtil_RegisterAdvertisedFileListener (const cGH *GH, const char *listener,
                     const ioAdvertisedFileListenerCallbacks *callbacks)
{
  int retval = -1;
  ioAdvertisedFileListenerCallbacks *new_callbacks;


  /* prevent compiler warning about unused parameter */
  GH = GH;

  if (listener && callbacks)
  {
    new_callbacks = (ioAdvertisedFileListenerCallbacks *)
                     malloc (sizeof (ioAdvertisedFileListenerCallbacks));
    if (new_callbacks)
    {
      *new_callbacks = *callbacks;
      retval = StoreNamedData (&listener_DB, listener, new_callbacks);
      if (retval)
        free (new_callbacks);
    }
  }

  return (retval);
}


/*@@
   @routine    IOUtil_AdvertiseFile
   @date       Wed May 17 2000
   @author     Thomas Radke
   @desc
               Adds a filename to the list of advertised files for downloading.
               The routine calls all listeners which are currently registered
               for advertised file handling.
   @enddesc
   @history
   @endhistory
   @var        GH
   @vdesc      pointer to grid hierarchy
   @vtype      const cGH *
   @vio        in
   @endvar
   @var        filename
   @vdesc      name of the file to advertise
   @vtype      const char *
   @vio        in
   @endvar
   @var        description
   @vdesc      structure which describes the file
   @vtype      const ioAdvertisedFileDesc *
   @vio        in
   @endvar
   @returntype int
   @returndesc This routine returns the logically OR'ed return values
               of all listeners' advertise callbacks called.
   @endreturndesc
@@*/

int IOUtil_AdvertiseFile (const cGH *GH, const char *filename,
                          const ioAdvertisedFileDesc *description)
{
  int retval = 0;
  pNamedData *listener;
  ioAdvertisedFileListenerCallbacks *callbacks;


  /* get the listener database from IOUtil's GH extension */
  listener = listener_DB;

  /* loop through all listeners' advertise() callbacks */
  while (listener)
  {
    callbacks = (ioAdvertisedFileListenerCallbacks *) listener->data;
    if (callbacks && callbacks->advertise)
      retval |= (callbacks->advertise) (GH, filename, description);
    listener = listener->next;
  }

  return (retval);
}