~ubuntu-branches/ubuntu/wily/afnix/wily

« back to all changes in this revision

Viewing changes to src/srv/csm/shl/Xaas.cpp

  • Committer: Package Import Robot
  • Author(s): Nobuhiro Iwamatsu
  • Date: 2015-07-11 02:00:35 UTC
  • mfrom: (10.1.1 sid)
  • Revision ID: package-import@ubuntu.com-20150711020035-2nhpztq7s15qyc0v
Tags: 2.5.1-1
* New upstream release. (Closes: #789968)
* Update debian/control.
  - Update Standards-Version to 3.9.6.
* Add support mips64(el) and ppc64el. (Closes: #741508, #748146)
* Add patches/support-gcc-5.x.patch. (Closes: #777767)
  - Fix build with gcc-5.x.
* Add patches/Disable-NET0001.als.patch.
  - Disable test of NET0001.als.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// ---------------------------------------------------------------------------
 
2
// - Xaas.cpp                                                                -
 
3
// - afnix:csm service - all as a service class implementation               -
 
4
// ---------------------------------------------------------------------------
 
5
// - This program is free software;  you can redistribute it  and/or  modify -
 
6
// - it provided that this copyright notice is kept intact.                  -
 
7
// -                                                                         -
 
8
// - This program  is  distributed in  the hope  that it will be useful, but -
 
9
// - without  any  warranty;  without  even   the   implied    warranty   of -
 
10
// - merchantability or fitness for a particular purpose.  In no event shall -
 
11
// - the copyright holder be liable for any  direct, indirect, incidental or -
 
12
// - special damages arising in any way out of the use of this software.     -
 
13
// ---------------------------------------------------------------------------
 
14
// - copyright (c) 1999-2015 amaury darsch                                   -
 
15
// ---------------------------------------------------------------------------
 
16
 
 
17
#include "Xaas.hpp"
 
18
#include "Vector.hpp"
 
19
#include "Boolean.hpp"
 
20
#include "QuarkZone.hpp"
 
21
#include "Exception.hpp"
 
22
 
 
23
namespace afnix {
 
24
 
 
25
  // -------------------------------------------------------------------------
 
26
  // - private section                                                       -
 
27
  // -------------------------------------------------------------------------
 
28
 
 
29
  // the default rid
 
30
  static const String XAAS_XRID_XDEF = "default@localdomain";
 
31
  // the default active mode
 
32
  static const bool   XAAS_MODE_XDEF = true;
 
33
 
 
34
  // the rid property name
 
35
  static const String XAAS_XRID_NAME = "XAAS-RID";
 
36
  static const String XAAS_XRID_INFO = "XAAS REGISTRATION ID";
 
37
 
 
38
  // -------------------------------------------------------------------------
 
39
  // - class section                                                         -
 
40
  // -------------------------------------------------------------------------
 
41
 
 
42
  // create a default service
 
43
 
 
44
  Xaas::Xaas (void) {
 
45
    d_mode = XAAS_MODE_XDEF;
 
46
    setrid (XAAS_XRID_XDEF);
 
47
  }
 
48
 
 
49
  // create a service by name
 
50
 
 
51
  Xaas::Xaas (const String& name) : Plist (name) {
 
52
    d_mode = XAAS_MODE_XDEF;
 
53
    setrid (XAAS_XRID_XDEF);
 
54
  }
 
55
 
 
56
  // create a service by name and info
 
57
 
 
58
  Xaas::Xaas (const String& name, const String& info) : Plist (name, info) {
 
59
    d_mode = XAAS_MODE_XDEF;
 
60
    setrid (XAAS_XRID_XDEF);
 
61
  }
 
62
 
 
63
  // create a service by plist
 
64
 
 
65
  Xaas::Xaas (const Plist& plst) : Plist (plst) {
 
66
    d_mode = XAAS_MODE_XDEF;
 
67
    if (plst.exists (XAAS_XRID_NAME) == false) setrid (XAAS_XRID_XDEF);
 
68
  }
 
69
 
 
70
  // copy construct this account
 
71
 
 
72
  Xaas::Xaas (const Xaas& that) {
 
73
    that.rdlock ();
 
74
    try {
 
75
      // copy the base list
 
76
      Plist::operator = (that);
 
77
      // copy locally
 
78
      d_mode = that.d_mode;
 
79
      that.unlock ();
 
80
    } catch (...) {
 
81
      that.unlock ();
 
82
      throw;
 
83
    }
 
84
  }
 
85
 
 
86
  // assign a service to this one
 
87
 
 
88
  Xaas& Xaas::operator = (const Xaas& that) {
 
89
    // check for self-assignation
 
90
    if (this == &that) return *this;
 
91
    // lock and assign
 
92
    wrlock ();
 
93
    that.rdlock ();
 
94
    try {
 
95
      // copy the base list
 
96
      Plist::operator = (that);
 
97
      // copy locally
 
98
      d_mode = that.d_mode;
 
99
      unlock ();
 
100
      that.unlock ();
 
101
      return *this;
 
102
    } catch (...) {
 
103
      unlock ();
 
104
      that.unlock ();
 
105
      throw;
 
106
    }
 
107
  }
 
108
 
 
109
  // set the registration id
 
110
 
 
111
  void Xaas::setrid (const String& rid) {
 
112
    wrlock ();
 
113
    try {
 
114
      if (Plist::exists (XAAS_XRID_NAME) == true) {
 
115
        Plist::set (XAAS_XRID_NAME, rid);
 
116
      } else {
 
117
        Plist::add (XAAS_XRID_NAME, XAAS_XRID_INFO, rid);
 
118
      }
 
119
      unlock ();
 
120
    } catch (...) {
 
121
      unlock ();
 
122
      throw;
 
123
    }
 
124
  }
 
125
 
 
126
  // get the registration id
 
127
 
 
128
  String Xaas::getrid (void) const {
 
129
    rdlock ();
 
130
    try {
 
131
      String result = Plist::getpval (XAAS_XRID_NAME);
 
132
      unlock ();
 
133
      return result;
 
134
    } catch (...) {
 
135
      unlock ();
 
136
      throw;
 
137
    }
 
138
  }
 
139
 
 
140
  // set the service mode
 
141
 
 
142
  void Xaas::setmode (const bool mode) {
 
143
    wrlock ();
 
144
    try {
 
145
      d_mode = mode;
 
146
      unlock ();
 
147
    } catch (...) {
 
148
      unlock ();
 
149
      throw;
 
150
    }
 
151
  }
 
152
 
 
153
  // get the service port
 
154
 
 
155
  bool Xaas::getmode (void) const {
 
156
    rdlock ();
 
157
    try {
 
158
      bool result = d_mode;
 
159
      unlock ();
 
160
      return result;
 
161
    } catch (...) {
 
162
      unlock ();
 
163
      throw;
 
164
    }
 
165
  }
 
166
 
 
167
  // -------------------------------------------------------------------------
 
168
  // - object section                                                        -
 
169
  // -------------------------------------------------------------------------
 
170
  
 
171
  // the quark zone
 
172
  static const long QUARK_ZONE_LENGTH = 4;
 
173
  static QuarkZone  zone (QUARK_ZONE_LENGTH);
 
174
 
 
175
  // the object supported quarks
 
176
  static const long QUARK_SETRID  = zone.intern ("set-rid");
 
177
  static const long QUARK_GETRID  = zone.intern ("get-rid");
 
178
  static const long QUARK_SETMODE = zone.intern ("set-mode");
 
179
  static const long QUARK_GETMODE = zone.intern ("get-mode");
 
180
 
 
181
  // return true if the given quark is defined
 
182
 
 
183
  bool Xaas::isquark (const long quark, const bool hflg) const {
 
184
    rdlock ();
 
185
    if (zone.exists (quark) == true) {
 
186
      unlock ();
 
187
      return true;
 
188
    }
 
189
    bool result = hflg ? Plist::isquark (quark, hflg) : false;
 
190
    unlock ();
 
191
    return result;
 
192
  }
 
193
  
 
194
  // apply this object with a set of arguments and a quark
 
195
  
 
196
  Object* Xaas::apply (Runnable* robj, Nameset* nset, const long quark,
 
197
                       Vector* argv) {
 
198
    // get the number of arguments
 
199
    long argc = (argv == nilp) ? 0 : argv->length ();
 
200
    
 
201
    // dispatch 0 argument
 
202
    if (argc == 0) {
 
203
      if (quark == QUARK_GETRID)  return new String  (getrid  ());
 
204
      if (quark == QUARK_GETMODE) return new Boolean (getmode ());
 
205
    }
 
206
    if (argc == 1) {
 
207
      if (quark == QUARK_SETRID) {
 
208
        String rid = argv->getstring (0);
 
209
        setrid (rid);
 
210
        return nilp;
 
211
      }
 
212
      if (quark == QUARK_SETMODE) {
 
213
        long mode = argv->getbool (0);
 
214
        setmode (mode);
 
215
        return nilp;
 
216
      }
 
217
    }
 
218
    // call the plist methods
 
219
    return Plist::apply (robj, nset, quark, argv);
 
220
  }
 
221
}