~renatofilho/buteo-syncfw/more-verbose

« back to all changes in this revision

Viewing changes to msyncd/SyncQueue.cpp

  • Committer: Sergey Gerasimenko
  • Date: 2010-06-29 12:51:21 UTC
  • Revision ID: git-v1:cd8dab07b102ac96752ece4f3cde5fc62697d717
Initial commit

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 
 
24
 
 
25
#include "SyncQueue.h"
 
26
#include "SyncSession.h"
 
27
#include "SyncProfile.h"
 
28
#include "LogMacros.h"
 
29
 
 
30
using namespace Buteo;
 
31
 
 
32
void SyncQueue::enqueue(SyncSession *aSession)
 
33
{
 
34
    FUNCTION_CALL_TRACE;
 
35
 
 
36
    iItems.enqueue(aSession);
 
37
    sort();
 
38
}
 
39
 
 
40
SyncSession *SyncQueue::dequeue()
 
41
{
 
42
    FUNCTION_CALL_TRACE;
 
43
 
 
44
    SyncSession *p = NULL;
 
45
 
 
46
    if (!iItems.isEmpty())
 
47
    {
 
48
        p = iItems.dequeue();
 
49
    } // no else
 
50
 
 
51
    return p;
 
52
}
 
53
 
 
54
SyncSession *SyncQueue::head()
 
55
{
 
56
    FUNCTION_CALL_TRACE;
 
57
 
 
58
    SyncSession *p = NULL;
 
59
    if (!iItems.isEmpty())
 
60
    {
 
61
        p = iItems.head();
 
62
    } // no else
 
63
 
 
64
    return p;
 
65
}
 
66
 
 
67
bool SyncQueue::isEmpty() const
 
68
{
 
69
    FUNCTION_CALL_TRACE;
 
70
 
 
71
    return iItems.isEmpty();
 
72
}
 
73
 
 
74
bool SyncQueue::contains(const QString &aProfileName) const
 
75
{
 
76
    FUNCTION_CALL_TRACE;
 
77
 
 
78
    QQueue<SyncSession*>::const_iterator i;
 
79
    for (i = iItems.begin(); i != iItems.end(); ++i)
 
80
    {
 
81
        if ((*i)->profileName() == aProfileName)
 
82
            return true;
 
83
    }
 
84
 
 
85
    return false;
 
86
}
 
87
 
 
88
bool syncSessionPointerLessThan(SyncSession *&aLhs, SyncSession *&aRhs)
 
89
{
 
90
    if (aLhs && aRhs) {
 
91
        // Manual sync has higher priority than scheduled sync.
 
92
        if (aLhs->isScheduled() != aRhs->isScheduled())
 
93
            return !aLhs->isScheduled();
 
94
 
 
95
        SyncProfile *lhsProfile = aLhs->profile();
 
96
        SyncProfile *rhsProfile = aRhs->profile();
 
97
        if (lhsProfile == 0 || rhsProfile == 0)
 
98
            return false;
 
99
 
 
100
        // Device sync has higher priority than online sync.
 
101
        SyncProfile::DestinationType lhsDestType = lhsProfile->destinationType();
 
102
        SyncProfile::DestinationType rhsDestType = rhsProfile->destinationType();
 
103
        if (lhsDestType != rhsDestType)
 
104
            return (lhsDestType == SyncProfile::DESTINATION_TYPE_DEVICE);
 
105
    }
 
106
 
 
107
    return false;
 
108
}
 
109
 
 
110
void SyncQueue::sort()
 
111
{
 
112
    FUNCTION_CALL_TRACE;
 
113
 
 
114
    // @todo: Sort queued profiles using some criteria.
 
115
}