1 // -*- Mode: C++; -*-
2 // Package : omniORB
3 // context.h Created on: 9/1998
4 // Author : David Riddoch (djr)
5 //
6 // Copyright (C) 2013 Apasphere Ltd
7 // Copyright (C) 1996-1999 AT&T Laboratories Cambridge
8 //
9 // This file is part of the omniORB library
10 //
11 // The omniORB library is free software; you can redistribute it and/or
12 // modify it under the terms of the GNU Lesser General Public
13 // License as published by the Free Software Foundation; either
14 // version 2.1 of the License, or (at your option) any later version.
15 //
16 // This library is distributed in the hope that it will be useful,
17 // but WITHOUT ANY WARRANTY; without even the implied warranty of
18 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 // Lesser General Public License for more details.
20 //
21 // You should have received a copy of the GNU Lesser General Public
22 // License along with this library. If not, see http://www.gnu.org/licenses/
23 //
24 //
25 // Description:
26 //
27
28 #ifndef __CONTEXT_H__
29 #define __CONTEXT_H__
30
OMNI_NAMESPACE_BEGIN(omni)31 OMNI_NAMESPACE_BEGIN(omni)
32
33 class ContextImpl : public CORBA::Context {
34 public:
35 ContextImpl(const char* name, CORBA::Context_ptr parent);
36 virtual ~ContextImpl();
37
38 virtual const char* context_name() const;
39 virtual CORBA::Context_ptr parent() const;
40 virtual void create_child(const char*, CORBA::Context_out);
41 virtual void set_one_value(const char*, const CORBA::Any&);
42 virtual void set_values(CORBA::NVList_ptr);
43 virtual void delete_values(const char*);
44 virtual void get_values(const char* start_scope,
45 CORBA::Flags op_flags,
46 const char* pattern,
47 CORBA::NVList_out values);
48 virtual CORBA::Boolean NP_is_nil() const;
49 virtual CORBA::Context_ptr NP_duplicate();
50
51 ///////////////////
52 // omni internal //
53 ///////////////////
54 void insert_single_consume(char* name, char* value);
55 // Inserts a single entry, consuming the given name/value pair.
56
57 void decrRefCount();
58 // Decrease the reference count, and delete this context
59 // if there are no more references or children.
60 // Must not hold <pd_lock>.
61
62 static void releaseDefault();
63 // Release the default context, if there is one. Called on ORB destruction.
64
65 private:
66 friend class CORBA::Context;
67
68 ContextImpl(const ContextImpl&); // not implemented
69 ContextImpl& operator=(const ContextImpl&); // not implemented
70
71 int matchPattern(const char* pat, CORBA::ULong& bottom,
72 CORBA::ULong& top) const;
73 // Returns 1 if finds a match, or 0 if no match.
74 // The index of the first match is in <bottom>, and the last
75 // match + 1 in <top>.
76 // Must hold <pd_lock>.
77
78 static void add_values(ContextImpl* c, CORBA::Flags op_flags,
79 const char* pattern, int wildcard,
80 CORBA::NVList_ptr val_list);
81 // If( wildcard ), then pattern has terminating '*', and all matching
82 // name-value pairs are added to val_list. Recurses on parent of context
83 // if allowed by op_flags.
84 // If( !wildcard ), looks for a single match starting at the given
85 // context, looking in parent if it is not found and op_flags allows.
86
87 void check_context_name(const char* n);
88 void check_property_name(const char* n);
89 // These check that the given (non-null) identifier is a valid context
90 // name or property name respectively.
91
92 void addChild(ContextImpl* c) {
93 omni_tracedmutex_lock lock(pd_lock);
94 c->pd_nextSibling = pd_children;
95 pd_children = c;
96 }
97 // Add the given ContextImpl into the list of children.
98
99 void loseChild(ContextImpl* child);
100 // The given child is dying - remove from the list of dependents. This
101 // must only be called by a child of this context from its d'tor.
102
103 struct Entry {
104 char* name;
105 char* value;
106 };
107 typedef _CORBA_PseudoValue_Sequence<Entry> EntrySeq;
108
109 CORBA::String_var pd_name; // set once - never changes
110 CORBA::Context_ptr pd_parent; // set once - never changes
111 EntrySeq pd_entries; // sorted list of entries
112 ContextImpl* pd_children; // list of Ctxts which depend on this
113 ContextImpl* pd_nextSibling; // linked list of siblings
114 unsigned pd_refCount;
115
116 omni_tracedmutex pd_lock;
117
118 // Manages access to <pd_entries>, <pd_children>, <pd_refCount> and the
119 // <pd_nextSibling> pointers in its children.
120 };
121
122 OMNI_NAMESPACE_END(omni)
123
124 #endif // __CONTEXT_H__
125