summaryrefslogtreecommitdiff
path: root/cpp/src/Yellow/AdminI.cpp
blob: 3cf4e90b3c1c21f77a31b076b67748b8ef8737b0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
// **********************************************************************
//
// Copyright (c) 2001
// MutableRealms, Inc.
// Huntsville, AL, USA
//
// All Rights Reserved
//
// **********************************************************************

#include <Yellow/AdminI.h>

using namespace std;
using namespace Ice;
using namespace Yellow;
using namespace Freeze;

Yellow::AdminI::AdminI(const DBPtr& db) :
    _dict(db)
{
}

void
Yellow::AdminI::add(const string& intf, const ObjectPrx& offer, const Current&)
{
    IceUtil::Mutex::Lock sync(*this);

    ObjectProxySeq seq;

    StringObjectProxySeqDict::iterator p = _dict.find(intf);
    if(p != _dict.end())
    {
	seq = p->second;
    }

    seq.push_back(offer);
    if(p == _dict.end())
    {
	_dict.insert(make_pair(intf, seq));
    }
    else
    {
	p.set(seq);
    }
}

void
Yellow::AdminI::remove(const string& intf, const ObjectPrx& offer, const Current&)
{
    IceUtil::Mutex::Lock sync(*this);

    ObjectProxySeq seq;

    StringObjectProxySeqDict::iterator p = _dict.find(intf);
    if(p == _dict.end())
    {
	throw NoSuchOfferException();
    }

    seq = p->second;
    Ice::Identity ident = offer->ice_getIdentity();
    ObjectProxySeq::iterator q;
    for(q = seq.begin(); q != seq.end(); ++q)
    {
	ObjectPrx proxy = *q;
	if(proxy->ice_getIdentity() == ident)
	{
	    break;
	}
    }
    if(q == seq.end())
    {
	throw NoSuchOfferException();
    }
    seq.erase(q);
    if(seq.size() == 0)
    {
	_dict.erase(p);
    }
    else
    {
	p.set(seq);
    }
}