Buteo Synchronization Framework: StorageBooker.h Source File

Buteo Synchronization Framework

StorageBooker.h
1/*
2 * This file is part of buteo-syncfw package
3 *
4 * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
5 *
6 * Contact: Sateesh Kavuri <sateesh.kavuri@nokia.com>
7 *
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public License
10 * version 2.1 as published by the Free Software Foundation.
11 *
12 * This library is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 * 02110-1301 USA
21 *
22 */
23#ifndef STORAGEBOOKER_H
24#define STORAGEBOOKER_H
25
26#include <QString>
27#include <QStringList>
28#include <QMap>
29#include <QMutex>
30
31namespace Buteo {
32
36 class StorageBooker
37{
38public:
39
41 StorageBooker();
42
44 ~StorageBooker();
45
58 bool reserveStorage(const QString &aStorageName,
59 const QString &aClientId = "");
60
71 bool reserveStorages(const QStringList &aStorageNames,
72 const QString &aClientId = "");
73
80 unsigned releaseStorage(const QString &aStorageName);
81
86 void releaseStorages(const QStringList &aStorageNames);
87
97 bool isStorageAvailable(const QString &aStorageName,
98 const QString &aClientId = "") const;
99
106 bool storagesAvailable(const QStringList &aStorageNames,
107 const QString &aClientId = "") const;
108
109private:
110
111 struct StorageMapItem {
112 QString iClientId;
113 unsigned iRefCount;
114
115 StorageMapItem() : iRefCount(0) { };
116
117 StorageMapItem(const QString &aClientId) :
118 iClientId(aClientId), iRefCount(1) { };
119 };
120
121 QMap<QString, StorageMapItem> iStorageMap;
122
123 mutable QMutex iMutex;
124
125};
126
127}
128
129#endif // STORAGEBOOKER_H
Buteo::StorageBooker
A helper class for managing storage reservations.
Definition: StorageBooker.h:37
Buteo::StorageBooker::releaseStorage
unsigned releaseStorage(const QString &aStorageName)
Releases the given storage.
Definition: StorageBooker.cpp:90
Buteo::StorageBooker::releaseStorages
void releaseStorages(const QStringList &aStorageNames)
Releases the given storages.
Definition: StorageBooker.cpp:113
Buteo::StorageBooker::StorageBooker
StorageBooker()
Constructor.
Definition: StorageBooker.cpp:29
Buteo::StorageBooker::reserveStorages
bool reserveStorages(const QStringList &aStorageNames, const QString &aClientId="")
Tries to reserve multiple storages for the given client.
Definition: StorageBooker.cpp:70
Buteo::StorageBooker::isStorageAvailable
bool isStorageAvailable(const QString &aStorageName, const QString &aClientId="") const
Checks if the given storage is available for the given client.
Definition: StorageBooker.cpp:124
Buteo::StorageBooker::reserveStorage
bool reserveStorage(const QString &aStorageName, const QString &aClientId="")
Tries to reserve one storage for the given client.
Definition: StorageBooker.cpp:40
Buteo::StorageBooker::~StorageBooker
~StorageBooker()
Destructor.
Definition: StorageBooker.cpp:35
Buteo::StorageBooker::storagesAvailable
bool storagesAvailable(const QStringList &aStorageNames, const QString &aClientId="") const
Checks if the given storages are available for the given client.
Definition: StorageBooker.cpp:137
QMap< QString, StorageMapItem >