RegistrationTable.hpp
Go to the documentation of this file.
1 
2 /*----------------------------------------------------------------------------*/
3 /* */
4 /* Copyright (c) 1995, 2004 IBM Corporation. All rights reserved. */
5 /* Copyright (c) 2005-2009 Rexx Language Association. All rights reserved. */
6 /* */
7 /* This program and the accompanying materials are made available under */
8 /* the terms of the Common Public License v1.0 which accompanies this */
9 /* distribution. A copy is also available at the following address: */
10 /* http://www.ibm.com/developerworks/oss/CPLv1.0.htm */
11 /* */
12 /* Redistribution and use in source and binary forms, with or */
13 /* without modification, are permitted provided that the following */
14 /* conditions are met: */
15 /* */
16 /* Redistributions of source code must retain the above copyright */
17 /* notice, this list of conditions and the following disclaimer. */
18 /* Redistributions in binary form must reproduce the above copyright */
19 /* notice, this list of conditions and the following disclaimer in */
20 /* the documentation and/or other materials provided with the distribution. */
21 /* */
22 /* Neither the name of Rexx Language Association nor the names */
23 /* of its contributors may be used to endorse or promote products */
24 /* derived from this software without specific prior written permission. */
25 /* */
26 /* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS */
27 /* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT */
28 /* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS */
29 /* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT */
30 /* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, */
31 /* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED */
32 /* TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, */
33 /* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY */
34 /* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING */
35 /* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS */
36 /* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
37 /* */
38 /*----------------------------------------------------------------------------*/
39 
40 #ifndef RegistrationTable_HPP_INCLUDED
41 #define RegistrationTable_HPP_INCLUDED
42 
43 #include "rexx.h"
44 #include "ServiceMessage.hpp"
45 #include "Utilities.hpp"
46 
48 {
49 public:
51  {
52  next = NULL;
53  session = s;
54  references = 1;
55  }
56 
57  inline void addReference() { references++; }
58  inline size_t removeReference() { return --references; }
59 
60  SessionCookie *next; // the next in the chain
61  SessionID session; // the session id for the registering process
62  size_t references; // number of nested references from this session
63 };
64 
65 
67 {
68 public:
69  RegistrationData(const char * n, const char * m, SessionID s, ServiceRegistrationData *regData);
70  RegistrationData(const char * n, SessionID s, ServiceRegistrationData *regData);
72 
73  inline bool matches(const char *n, const char *m) { return Utilities::strCaselessCompare(name, n) == 0 && Utilities::strCaselessCompare(moduleName, m) == 0; }
74  inline bool matches(const char *n, SessionID s) { return s == owner && Utilities::strCaselessCompare(name, n) == 0; }
75  inline bool matches(const char *n) { return Utilities::strCaselessCompare(name, n) == 0; }
76  inline bool hasReferences() { return references != 0; }
77  inline bool isLibrary() { return moduleName != NULL; }
78  inline bool isEntryPoint() { return moduleName == NULL; }
79 
85 
86  RegistrationData *next; // next block in the chaing
87  const char *name; // the registered name
88  const char *moduleName; // module name for object (optional)
89  const char *procedureName; // procedure name (optional)
90  uintptr_t userData[2]; // user area information
91  uintptr_t entryPoint; // target entry point
92  size_t dropAuthority; // Permission to drop
93  SessionID owner; // Pid of Registrant
94  SessionCookie *references; // references to this registration from other processes
95 };
96 
97 
99 {
100 public:
102  {
103  firstEntryPoint = NULL;
104  firstLibrary = NULL;
105  }
106 
108  void registerCallback(ServiceMessage &message);
109  void queryCallback(ServiceMessage &message);
110  void queryLibraryCallback(ServiceMessage &message);
111  void dropCallback(ServiceMessage &message);
112  void dropLibraryCallback(ServiceMessage &message);
113  void updateCallback(ServiceMessage &message);
114  RegistrationData *locate(RegistrationData *anchor, const char *name);
115  RegistrationData *locate(const char *name, const char *module);
116  RegistrationData *locate(const char *name);
117  RegistrationData *locate(const char *name, SessionID session);
118  void remove(RegistrationData **anchor, RegistrationData *block);
119  void reorderBlocks(RegistrationData *& anchor, RegistrationData *current, RegistrationData *previous);
120  void freeProcessEntries(SessionID session);
121  inline bool hasEntries()
122  {
123  return firstEntryPoint != NULL || firstLibrary != NULL;
124  }
125  inline bool isEmpty()
126  {
127  return !hasEntries();
128  }
129 
130 protected:
131  RegistrationData *firstEntryPoint; // first reference in the entrypoint registration chain
132  RegistrationData *firstLibrary; // first reference in the library chain
133 };
134 #endif
uintptr_t SessionID
RegistrationData * next
bool matches(const char *n)
bool matches(const char *n, const char *m)
void getRegistrationData(ServiceRegistrationData &regData)
SessionCookie * findSessionReference(SessionID s)
RegistrationData(const char *n, const char *m, SessionID s, ServiceRegistrationData *regData)
bool matches(const char *n, SessionID s)
void addSessionReference(SessionID s)
const char * moduleName
void removeSessionReference(SessionID s)
SessionCookie * references
const char * procedureName
RegistrationData * firstEntryPoint
RegistrationData * firstLibrary
void queryLibraryCallback(ServiceMessage &message)
void updateCallback(ServiceMessage &message)
void queryCallback(ServiceMessage &message)
void freeProcessEntries(SessionID session)
RegistrationData * locate(RegistrationData *anchor, const char *name)
void registerLibraryCallback(ServiceMessage &message)
void registerCallback(ServiceMessage &message)
void remove(RegistrationData **anchor, RegistrationData *block)
void dropLibraryCallback(ServiceMessage &message)
void reorderBlocks(RegistrationData *&anchor, RegistrationData *current, RegistrationData *previous)
void dropCallback(ServiceMessage &message)
static int strCaselessCompare(const char *opt1, const char *opt2)
Definition: Utilities.cpp:102
UINT_PTR uintptr_t