resource_unpack.c 3.52 KB
Newer Older
1
2
3
4
5
#ifdef HAVE_CONFIG_H
#  include "config.h"
#endif

#include "cdi.h"
6
#include "dmemory.h"
7
#include "grid.h"
8
9
10
11
12
13
#include "institution.h"
#include "model.h"
#include "cdi_int.h"
#include "vlist.h"
#include "namespace.h"
#include "serialize.h"
14
#include "resource_handle.h"
15
#include "resource_unpack.h"
Thomas Jahns's avatar
Thomas Jahns committed
16
#include "taxis.h"
17
#include "zaxis.h"
18
19
20
21
22
23

/*****************************************************************************/

void reshUnpackResources(char * unpackBuffer, int unpackBufferSize,
                         void *context)
{
24
  int updateType, resH, originNamespace;
25
26
27
  int unpackBufferPos = 0;
  int numAssociations = 0, sizeAssociations = 16;
  struct streamAssoc *associations
28
29
    = (struct streamAssoc *)xmalloc(sizeof (associations[0])
                                    * (size_t)sizeAssociations);
30

31
32
33
34
35
36
37
38
  {
    int msgHdr[2];
    serializeUnpack(unpackBuffer, unpackBufferSize, &unpackBufferPos,
                    &msgHdr, 2, DATATYPE_INT, context);
    if (msgHdr[0] != START)
      xabort("error parsing resource serialization buffer");
    originNamespace = msgHdr[1];
  }
39
40
41
  while ( unpackBufferPos < unpackBufferSize )
    {
      serializeUnpack(unpackBuffer, unpackBufferSize, &unpackBufferPos,
42
43
                      &updateType, 1, DATATYPE_INT, context);
      if (updateType == END)
44
        break;
45
      switch (updateType)
46
47
48
	{
	case GRID:
	  gridUnpack(unpackBuffer, unpackBufferSize, &unpackBufferPos,
49
                     originNamespace, context, 1);
50
51
52
	  break;
	case ZAXIS:
	  zaxisUnpack(unpackBuffer, unpackBufferSize, &unpackBufferPos,
53
                      originNamespace, context, 1);
54
55
56
	  break;
	case TAXIS:
	  taxisUnpack(unpackBuffer, unpackBufferSize, &unpackBufferPos,
57
                      originNamespace, context, 1);
58
59
60
	  break;
	case INSTITUTE:
          instituteUnpack(unpackBuffer, unpackBufferSize, &unpackBufferPos,
61
                          originNamespace, context, 1);
62
63
64
	  break;
	case MODEL:
          modelUnpack(unpackBuffer, unpackBufferSize, &unpackBufferPos,
65
                      originNamespace, context, 1);
66
67
68
69
	  break;
	case STREAM:
          if (sizeAssociations == numAssociations)
            associations
70
              = (struct streamAssoc *)xrealloc(associations,
71
                         sizeof (associations[0]) * (size_t)(sizeAssociations *= 2));
72
73
	  associations[numAssociations]
            = streamUnpack(unpackBuffer, unpackBufferSize, &unpackBufferPos,
74
                           originNamespace, context);
75
76
77
78
          ++numAssociations;
	  break;
	case VLIST:
          vlistUnpack(unpackBuffer, unpackBufferSize, &unpackBufferPos,
79
                      originNamespace, context, 1);
80
	  break;
81
82
        case RESH_DELETE:
          serializeUnpack(unpackBuffer, unpackBufferSize, &unpackBufferPos,
83
84
                          &resH, 1, DATATYPE_INT, context);
          reshDestroy(namespaceAdaptKey(resH, originNamespace));
85
          break;
86
	default:
Thomas Jahns's avatar
Thomas Jahns committed
87
88
	  xabort("Invalid/unexpected serialization type %d or transfer error!",
                 updateType);
89
90
91
92
93
94
	}
    }
  for (int i = 0; i < numAssociations; ++i)
    {
      cdiStreamSetupVlist(stream_to_pointer(associations[i].streamID),
                          namespaceAdaptKey(associations[i].vlistID,
95
                                            originNamespace),
96
                          namespaceAdaptKey(associations[i].vlistIDorig,
97
                                            originNamespace));
98
99
100
101
102
103
104
105
106
107
108
109
110
    }
  free(associations);
}

/*
 * Local Variables:
 * c-file-style: "Java"
 * c-basic-offset: 2
 * indent-tabs-mode: nil
 * show-trailing-whitespace: t
 * require-trailing-newline: t
 * End:
 */