~ubuntu-branches/ubuntu/gutsy/soprano/gutsy

« back to all changes in this revision

Viewing changes to server/dbus/dbusserveradaptor.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jonathan Riddell
  • Date: 2007-10-12 14:43:48 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20071012144348-yajzi51v4k23ahxf
Tags: 1.95.0~beta2-1ubuntu1
* Sync with Debian
* Add versioned build-dep on raptor

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * This file is part of Soprano Project.
 
3
 *
 
4
 * Copyright (C) 2007 Sebastian Trueg <trueg@kde.org>
 
5
 *
 
6
 * This library is free software; you can redistribute it and/or
 
7
 * modify it under the terms of the GNU Library General Public
 
8
 * License as published by the Free Software Foundation; either
 
9
 * version 2 of the License, or (at your option) any later version.
 
10
 *
 
11
 * This library is distributed in the hope that it will be useful,
 
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
14
 * Library General Public License for more details.
 
15
 *
 
16
 * You should have received a copy of the GNU Library General Public License
 
17
 * along with this library; see the file COPYING.LIB.  If not, write to
 
18
 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 
19
 * Boston, MA 02110-1301, USA.
 
20
 */
 
21
 
 
22
#include "dbusserveradaptor.h"
 
23
#include "dbusutil.h"
 
24
#include "../servercore.h"
 
25
#include "dbusmodeladaptor.h"
 
26
#include "modelwrapper.h"
 
27
 
 
28
#include <soprano/model.h>
 
29
 
 
30
#include <QtCore/QHash>
 
31
 
 
32
class Soprano::Server::DBusServerAdaptor::Private
 
33
{
 
34
public:
 
35
    ServerCore* core;
 
36
    QHash<Model*, QString> modelDBusObjectPaths;
 
37
};
 
38
 
 
39
 
 
40
Soprano::Server::DBusServerAdaptor::DBusServerAdaptor( ServerCore* parent )
 
41
    : QDBusAbstractAdaptor( parent ),
 
42
      d( new Private() )
 
43
{
 
44
    d->core = parent;
 
45
}
 
46
 
 
47
Soprano::Server::DBusServerAdaptor::~DBusServerAdaptor()
 
48
{
 
49
    delete d;
 
50
}
 
51
 
 
52
QStringList Soprano::Server::DBusServerAdaptor::allModels( const QDBusMessage& m )
 
53
{
 
54
    // handle method call org.soprano.Server.allModels
 
55
    QStringList names = d->core->allModels();
 
56
    if ( d->core->lastError() ) {
 
57
        DBus::sendErrorReply( m, d->core->lastError() );
 
58
    }
 
59
    return names;
 
60
}
 
61
 
 
62
QString Soprano::Server::DBusServerAdaptor::createModel( const QString& name, const QDBusMessage& m )
 
63
{
 
64
    // handle method call org.soprano.Server.createModel
 
65
    Model* model = d->core->model( name );
 
66
    if ( model ) {
 
67
        QHash<Model*, QString>::const_iterator it = d->modelDBusObjectPaths.find( model );
 
68
        if ( it != d->modelDBusObjectPaths.constEnd() ) {
 
69
            return it.value();
 
70
        }
 
71
        else {
 
72
            // FIXME: memory leak!
 
73
            ModelWrapper* mw = new ModelWrapper( model );
 
74
            ( void )new DBusModelAdaptor( model, mw );
 
75
            QString objectPath = "/Model_" + name;
 
76
            QDBusConnection::sessionBus().registerObject( objectPath, mw );
 
77
            d->modelDBusObjectPaths.insert( model, objectPath );
 
78
            return objectPath;
 
79
        }
 
80
    }
 
81
    else {
 
82
        DBus::sendErrorReply( m, d->core->lastError() );
 
83
        return QString();
 
84
    }
 
85
}
 
86
 
 
87
#include "dbusserveradaptor.moc"