MacroSpaceManager.hpp
Go to the documentation of this file.
1 /*----------------------------------------------------------------------------*/
2 /* */
3 /* Copyright (c) 1995, 2004 IBM Corporation. All rights reserved. */
4 /* Copyright (c) 2005-2009 Rexx Language Association. All rights reserved. */
5 /* */
6 /* This program and the accompanying materials are made available under */
7 /* the terms of the Common Public License v1.0 which accompanies this */
8 /* distribution. A copy is also available at the following address: */
9 /* http://www.ibm.com/developerworks/oss/CPLv1.0.htm */
10 /* */
11 /* Redistribution and use in source and binary forms, with or */
12 /* without modification, are permitted provided that the following */
13 /* conditions are met: */
14 /* */
15 /* Redistributions of source code must retain the above copyright */
16 /* notice, this list of conditions and the following disclaimer. */
17 /* Redistributions in binary form must reproduce the above copyright */
18 /* notice, this list of conditions and the following disclaimer in */
19 /* the documentation and/or other materials provided with the distribution. */
20 /* */
21 /* Neither the name of Rexx Language Association nor the names */
22 /* of its contributors may be used to endorse or promote products */
23 /* derived from this software without specific prior written permission. */
24 /* */
25 /* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS */
26 /* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT */
27 /* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS */
28 /* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT */
29 /* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, */
30 /* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED */
31 /* TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, */
32 /* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY */
33 /* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING */
34 /* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS */
35 /* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
36 /* */
37 /*----------------------------------------------------------------------------*/
38 
39 #ifndef MacroSpaceManager_HPP_INCLUDED
40 #define MacroSpaceManager_HPP_INCLUDED
41 
42 #include "ServiceMessage.hpp"
43 #include "SysSemaphore.hpp"
44 
45 class MacroItem
46 {
47 public:
48  MacroItem(const char *n, const char *, size_t l, size_t p);
49 
50  void update(const char *, size_t l, size_t p);
52  {
53  delete [] name; // release the name and
55  }
56 
57  MacroItem *next; // next macro in chain
58  const char *name; // the macro space name
59  const char *imageBuffer; // the image data
60  size_t imageSize; // size of the image data
61  size_t searchPosition; // the saved position
62 };
63 
64 
65 // a table of queues
67 {
68 public:
69 
71  {
72  macros = NULL;
73  iterator = NULL;
74  }
75 
76  void clear();
77  // locate a named data queue
78  MacroItem *locate(const char *name);
79  // locate and remove a named data queue
80  MacroItem *remove(const char *name);
81 
82  inline void reorder(MacroItem *current, MacroItem *previous)
83  {
84  if (previous != NULL) // if we have a predecessor
85  {
86  // rearrange to get "most recently used" behavior
87  previous->next = current->next;
88  current->next = macros;
89  macros = current;
90  }
91  }
92 
93  inline void removeMacro(MacroItem *current, MacroItem *previous)
94  {
95  if (previous != NULL) // if we have a predecessor
96  {
97  // rearrange to get "most recently used" behavior
98  previous->next = current->next;
99  }
100  else
101  {
102  macros = current->next;
103  }
104  }
105 
106  inline size_t macroCount()
107  {
108  size_t count = 0;
109  MacroItem *current = macros;
110  while (current != NULL)
111  {
112  count++;
113  current = current->next;
114  }
115  return count;
116  }
117 
118  inline bool iterating() { return iterator != NULL; }
119  inline void startIteration() { iterator = macros; }
120  inline bool hasMore() { return iterator != NULL; }
121  inline MacroItem * getNext()
122  {
123  if (iterator == NULL)
124  {
125  return NULL;
126  }
127  MacroItem *current = iterator;
129  return current;
130  }
131 
132  // locate a named data queue
133  inline void add(MacroItem *macro)
134  {
135  macro->next = macros;
136  macros = macro;
137  iterator = NULL; // this invalidates any iterator we may have
138  }
139 
140  inline bool isEmpty()
141  {
142  return macros == NULL;
143  }
144 
145 protected:
146  MacroItem *macros; // head of the data queue chain
147  MacroItem *iterator; // current iteration position
148 };
149 
151 {
152 public:
153  enum
154  {
157  };
158 
159 
160  ServerMacroSpaceManager() : lock("ServerMacroSpaceManager::lock"), macros() { lock.create(); }
161 
163  void addMacro(ServiceMessage &message);
164  void deleteMacro(ServiceMessage &message);
165  void clear(ServiceMessage &message);
166  void queryMacro(ServiceMessage &message);
167  void reorderMacro(ServiceMessage &message);
168  void iterateMacros(ServiceMessage &message);
169  void nextDescriptor(ServiceMessage &message);
170  void nextImage(ServiceMessage &message);
171  void getDescriptor(ServiceMessage &message);
172  void getImage(ServiceMessage &message);
173  void dispatch(ServiceMessage &message);
174  void cleanupProcessResources(SessionID session);
175 
176  inline bool isStoppable()
177  {
178  return macros.isEmpty();
179  }
180 
181 protected:
182  SysMutex lock; // our subsystem lock
183  MacroTable macros; // all of the manaaged macros.
184 };
185 
186 #endif
uintptr_t SessionID
MacroItem(const char *n, const char *, size_t l, size_t p)
MacroItem * next
const char * imageBuffer
void update(const char *, size_t l, size_t p)
const char * name
size_t searchPosition
MacroItem * remove(const char *name)
void removeMacro(MacroItem *current, MacroItem *previous)
MacroItem * getNext()
MacroItem * macros
MacroItem * iterator
void reorder(MacroItem *current, MacroItem *previous)
void add(MacroItem *macro)
MacroItem * locate(const char *name)
void iterateMacros(ServiceMessage &message)
void clear(ServiceMessage &message)
void getDescriptor(ServiceMessage &message)
void queryMacro(ServiceMessage &message)
void getImage(ServiceMessage &message)
void nextDescriptor(ServiceMessage &message)
void nextImage(ServiceMessage &message)
void cleanupProcessResources(SessionID session)
void reorderMacro(ServiceMessage &message)
void dispatch(ServiceMessage &message)
void addMacro(ServiceMessage &message)
void deleteMacro(ServiceMessage &message)
static void releaseResultMemory(void *mem)