1 // -*- Mode: C++; -*-
2 // Package : omniORB
3 // transportRule.h Created on: 21/08/2001
4 // Author : Sai Lai Lo (sll)
5 //
6 // Copyright (C) 2013 Apasphere Ltd
7 // Copyright (C) 2001 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 __TRANSPORTRULES_H__
29 #define __TRANSPORTRULES_H__
30
31 #include <omniORB4/CORBA.h>
32
33
OMNI_NAMESPACE_BEGIN(omni)34 OMNI_NAMESPACE_BEGIN(omni)
35
36 class transportRules {
37 public:
38
39 ////////////////////////////////////////////////////////////////////////
40 static transportRules& serverRules();
41 static transportRules& clientRules();
42
43 ////////////////////////////////////////////////////////////////////////
44 ////////////////////////////////////////////////////////////////////////
45 class Rule {
46 public:
47 Rule(const char* address_mask) : addressMask_(address_mask) {}
48 virtual ~Rule() {}
49
50 virtual CORBA::Boolean match(const char* endpoint) = 0;
51
52 const char* addressMask() { return addressMask_; }
53
54 private:
55 CORBA::String_var addressMask_;
56 Rule();
57 Rule(const Rule&);
58 Rule& operator=(const Rule&);
59 };
60
61 ////////////////////////////////////////////////////////////////////////
62 ////////////////////////////////////////////////////////////////////////
63 class RuleType {
64 public:
65 virtual CORBA::Boolean createRules(const char* address_mask,
66 const CORBA::StringSeq& actions,
67 transportRules& tr) = 0;
68 // If <address_mask> is recognised by this RuleType instance, add
69 // one or more rules to the transportRules and return true; if not
70 // recognised, return false.
71
72 RuleType() {}
73 virtual ~RuleType() {}
74
75 private:
76 RuleType(const RuleType&);
77 RuleType& operator=(const RuleType&);
78 };
79
80 typedef omnivector<RuleType*> RuleTypes;
81
82 static void addRuleType(RuleType*);
83
84
85 ////////////////////////////////////////////////////////////////////////
86 CORBA::Boolean match(const char* endpoint,
87 CORBA::StringSeq& actions/* return arg */,
88 CORBA::ULong& priority/* return arg */);
89 // Return true if <endpoint> matches one of the transport rules.
90 // The action list of the matched rule is returned in <actions>.
91 // The index of the matched rule is returned in <priority>.
92 // Return false if <endpoint> does not match any rule. In that case
93 // <actions and <priority> are not initialised.
94
95 ////////////////////////////////////////////////////////////////////////
96 char* dumpRule(CORBA::ULong index);
97 // Return the string representation of the rule at <index>. Returns 0
98 // if the index is out of range. If the value of <priority> returned
99 // by match() is used as <index> in this function, the string representation
100 // of the rule that match() matches is returned.
101
102
103 ////////////////////////////////////////////////////////////////////////
104 friend class omni_transportRules_initialiser;
105 friend class clientTransportRuleHandler;
106 friend class serverTransportRuleHandler;
107
108 struct RuleActionPair {
109 RuleActionPair(Rule* r, const CORBA::StringSeq& a)
110 : rule_(r), action_(a) {}
111
112 ~RuleActionPair() {
113 if (rule_) delete rule_;
114 }
115 Rule* rule_;
116 CORBA::StringSeq action_;
117 };
118
119 typedef omnivector<RuleActionPair*> RuleActionPairs;
120
121 inline void addRule(Rule* r, const CORBA::StringSeq& a)
122 {
123 pd_rules.push_back(new RuleActionPair(r, a));
124 }
125
126
127 transportRules();
128 ~transportRules();
129
130 void reset();
131
132 private:
133
134 RuleTypes pd_ruletypes;
135 RuleActionPairs pd_rules;
136
137 transportRules(const transportRules&);
138 transportRules& operator=(const transportRules&);
139 };
140
141 OMNI_NAMESPACE_END(omni)
142
143 #endif // __TRANSPORTRULES_H__
144