1
// ---------------------------------------------------------------------------
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. -
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
// ---------------------------------------------------------------------------
19
#include "Boolean.hpp"
20
#include "QuarkZone.hpp"
21
#include "Exception.hpp"
25
// -------------------------------------------------------------------------
26
// - private section -
27
// -------------------------------------------------------------------------
30
static const String XAAS_XRID_XDEF = "default@localdomain";
31
// the default active mode
32
static const bool XAAS_MODE_XDEF = true;
34
// the rid property name
35
static const String XAAS_XRID_NAME = "XAAS-RID";
36
static const String XAAS_XRID_INFO = "XAAS REGISTRATION ID";
38
// -------------------------------------------------------------------------
40
// -------------------------------------------------------------------------
42
// create a default service
45
d_mode = XAAS_MODE_XDEF;
46
setrid (XAAS_XRID_XDEF);
49
// create a service by name
51
Xaas::Xaas (const String& name) : Plist (name) {
52
d_mode = XAAS_MODE_XDEF;
53
setrid (XAAS_XRID_XDEF);
56
// create a service by name and info
58
Xaas::Xaas (const String& name, const String& info) : Plist (name, info) {
59
d_mode = XAAS_MODE_XDEF;
60
setrid (XAAS_XRID_XDEF);
63
// create a service by plist
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);
70
// copy construct this account
72
Xaas::Xaas (const Xaas& that) {
76
Plist::operator = (that);
86
// assign a service to this one
88
Xaas& Xaas::operator = (const Xaas& that) {
89
// check for self-assignation
90
if (this == &that) return *this;
96
Plist::operator = (that);
109
// set the registration id
111
void Xaas::setrid (const String& rid) {
114
if (Plist::exists (XAAS_XRID_NAME) == true) {
115
Plist::set (XAAS_XRID_NAME, rid);
117
Plist::add (XAAS_XRID_NAME, XAAS_XRID_INFO, rid);
126
// get the registration id
128
String Xaas::getrid (void) const {
131
String result = Plist::getpval (XAAS_XRID_NAME);
140
// set the service mode
142
void Xaas::setmode (const bool mode) {
153
// get the service port
155
bool Xaas::getmode (void) const {
158
bool result = d_mode;
167
// -------------------------------------------------------------------------
168
// - object section -
169
// -------------------------------------------------------------------------
172
static const long QUARK_ZONE_LENGTH = 4;
173
static QuarkZone zone (QUARK_ZONE_LENGTH);
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");
181
// return true if the given quark is defined
183
bool Xaas::isquark (const long quark, const bool hflg) const {
185
if (zone.exists (quark) == true) {
189
bool result = hflg ? Plist::isquark (quark, hflg) : false;
194
// apply this object with a set of arguments and a quark
196
Object* Xaas::apply (Runnable* robj, Nameset* nset, const long quark,
198
// get the number of arguments
199
long argc = (argv == nilp) ? 0 : argv->length ();
201
// dispatch 0 argument
203
if (quark == QUARK_GETRID) return new String (getrid ());
204
if (quark == QUARK_GETMODE) return new Boolean (getmode ());
207
if (quark == QUARK_SETRID) {
208
String rid = argv->getstring (0);
212
if (quark == QUARK_SETMODE) {
213
long mode = argv->getbool (0);
218
// call the plist methods
219
return Plist::apply (robj, nset, quark, argv);