summaryrefslogtreecommitdiff
path: root/src/dbus/server/client.cpp
blob: 3c100f2075c17eeea9e9d02142d70893df5df34f (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

/*
 * Copyright (C) 2011 Intel Corporation
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) version 3.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
 * 02110-1301  USA
 */

#include "client.h"
#include "session.h"
#include "server.h"

SE_BEGIN_CXX

Client::~Client()
{
    SE_LOG_DEBUG(NULL, "D-Bus client %s is destructing", m_ID.c_str());

    // explicitly detach all resources instead of just freeing the
    // list, so that the special behavior for sessions in detach() is
    // triggered
    while (!m_resources.empty()) {
        detach(m_resources.front().get());
    }
}

void Client::detach(Resource *resource)
{
    for (Resources_t::iterator it = m_resources.begin();
         it != m_resources.end();
         ++it) {
        if (it->get() == resource) {
            if (it->unique()) {
                // client was the last owner, and thus the session must be idle (otherwise
                // it would also be referenced as active session)
                boost::shared_ptr<Session> session = boost::dynamic_pointer_cast<Session>(*it);
                if (session) {
                    // give clients a chance to query the session
                    m_server.delaySessionDestruction(session);
                    // allow other sessions to start
                    session->done();
                }
            }
            // this will trigger removal of the resource if
            // the client was the last remaining owner
            m_resources.erase(it);
            return;
        }
    }

    SE_THROW_EXCEPTION(InvalidCall, "cannot detach from resource that client is not attached to");
}

SE_END_CXX