activitymanager/activitydatabase/hsactivitydbclient/s60/src/hsactivitydbclient_p.cpp
author hgs
Wed, 24 Mar 2010 03:15:43 +0200
changeset 89 1e87eb3b400f
permissions -rw-r--r--
201011
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
89
hgs
parents:
diff changeset
     1
/*
hgs
parents:
diff changeset
     2
* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
hgs
parents:
diff changeset
     3
* All rights reserved.
hgs
parents:
diff changeset
     4
* This component and the accompanying materials are made available
hgs
parents:
diff changeset
     5
* under the terms of "Eclipse Public License v1.0"
hgs
parents:
diff changeset
     6
* which accompanies this distribution, and is available
hgs
parents:
diff changeset
     7
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
hgs
parents:
diff changeset
     8
*
hgs
parents:
diff changeset
     9
* Initial Contributors:
hgs
parents:
diff changeset
    10
* Nokia Corporation - initial contribution.
hgs
parents:
diff changeset
    11
*
hgs
parents:
diff changeset
    12
* Contributors:
hgs
parents:
diff changeset
    13
*
hgs
parents:
diff changeset
    14
* Description:
hgs
parents:
diff changeset
    15
*
hgs
parents:
diff changeset
    16
*/
hgs
parents:
diff changeset
    17
hgs
parents:
diff changeset
    18
#include "hsactivitydbclient_p.h"
hgs
parents:
diff changeset
    19
#include "hsactivitydbasyncrequest_p.h"
hgs
parents:
diff changeset
    20
#include "hsactivityglobals.h"
hgs
parents:
diff changeset
    21
#include "hsserializer.h"
hgs
parents:
diff changeset
    22
hgs
parents:
diff changeset
    23
// -----------------------------------------------------------------------------
hgs
parents:
diff changeset
    24
//
hgs
parents:
diff changeset
    25
// -----------------------------------------------------------------------------
hgs
parents:
diff changeset
    26
//
hgs
parents:
diff changeset
    27
HsActivityDbClientPrivate::HsActivityDbClientPrivate(HsActivityDbAsyncRequestObserver& observer)
hgs
parents:
diff changeset
    28
{
hgs
parents:
diff changeset
    29
    mAsyncDataHandler = HsActivityDbAsyncRequestPrivate::NewL(observer, *this);
hgs
parents:
diff changeset
    30
}
hgs
parents:
diff changeset
    31
hgs
parents:
diff changeset
    32
// -----------------------------------------------------------------------------
hgs
parents:
diff changeset
    33
//
hgs
parents:
diff changeset
    34
// -----------------------------------------------------------------------------
hgs
parents:
diff changeset
    35
//
hgs
parents:
diff changeset
    36
HsActivityDbClientPrivate::~HsActivityDbClientPrivate()
hgs
parents:
diff changeset
    37
{
hgs
parents:
diff changeset
    38
    delete mAsyncDataHandler;
hgs
parents:
diff changeset
    39
    Close();
hgs
parents:
diff changeset
    40
}
hgs
parents:
diff changeset
    41
hgs
parents:
diff changeset
    42
// -----------------------------------------------------------------------------
hgs
parents:
diff changeset
    43
//
hgs
parents:
diff changeset
    44
// -----------------------------------------------------------------------------
hgs
parents:
diff changeset
    45
//
hgs
parents:
diff changeset
    46
int HsActivityDbClientPrivate::connect()
hgs
parents:
diff changeset
    47
{
hgs
parents:
diff changeset
    48
    TRAPD(errNo, connectL());
hgs
parents:
diff changeset
    49
    return errNo;
hgs
parents:
diff changeset
    50
}
hgs
parents:
diff changeset
    51
hgs
parents:
diff changeset
    52
// -----------------------------------------------------------------------------
hgs
parents:
diff changeset
    53
//
hgs
parents:
diff changeset
    54
// -----------------------------------------------------------------------------
hgs
parents:
diff changeset
    55
//
hgs
parents:
diff changeset
    56
int HsActivityDbClientPrivate::addActivity(const QVariantHash &activity)
hgs
parents:
diff changeset
    57
{
hgs
parents:
diff changeset
    58
    TRAPD( errNo, execSimpleRequestL(AddActivity, activity);)
hgs
parents:
diff changeset
    59
    return errNo; 
hgs
parents:
diff changeset
    60
}
hgs
parents:
diff changeset
    61
hgs
parents:
diff changeset
    62
// -----------------------------------------------------------------------------
hgs
parents:
diff changeset
    63
//
hgs
parents:
diff changeset
    64
// -----------------------------------------------------------------------------
hgs
parents:
diff changeset
    65
//
hgs
parents:
diff changeset
    66
int HsActivityDbClientPrivate::updateActivity(const QVariantHash &activity)
hgs
parents:
diff changeset
    67
{
hgs
parents:
diff changeset
    68
    TRAPD( errNo, execSimpleRequestL(UpdateActivity, activity);)
hgs
parents:
diff changeset
    69
    return errNo; 
hgs
parents:
diff changeset
    70
}
hgs
parents:
diff changeset
    71
hgs
parents:
diff changeset
    72
// -----------------------------------------------------------------------------
hgs
parents:
diff changeset
    73
//
hgs
parents:
diff changeset
    74
// -----------------------------------------------------------------------------
hgs
parents:
diff changeset
    75
//
hgs
parents:
diff changeset
    76
int HsActivityDbClientPrivate::removeActivity(const QVariantHash &activity)
hgs
parents:
diff changeset
    77
{
hgs
parents:
diff changeset
    78
    TRAPD( errNo, execSimpleRequestL(RemoveActivity, activity);)
hgs
parents:
diff changeset
    79
    return errNo; 
hgs
parents:
diff changeset
    80
}
hgs
parents:
diff changeset
    81
hgs
parents:
diff changeset
    82
// -----------------------------------------------------------------------------
hgs
parents:
diff changeset
    83
//
hgs
parents:
diff changeset
    84
// -----------------------------------------------------------------------------
hgs
parents:
diff changeset
    85
//
hgs
parents:
diff changeset
    86
int HsActivityDbClientPrivate::removeApplicationActivities(const QVariantHash &activity)
hgs
parents:
diff changeset
    87
{
hgs
parents:
diff changeset
    88
    TRAPD( errNo, execSimpleRequestL(RemoveApplicationActivities, activity);)
hgs
parents:
diff changeset
    89
    return errNo; 
hgs
parents:
diff changeset
    90
}
hgs
parents:
diff changeset
    91
hgs
parents:
diff changeset
    92
// -----------------------------------------------------------------------------
hgs
parents:
diff changeset
    93
//
hgs
parents:
diff changeset
    94
// -----------------------------------------------------------------------------
hgs
parents:
diff changeset
    95
//
hgs
parents:
diff changeset
    96
int HsActivityDbClientPrivate::activities(QList<QVariantHash>& result)
hgs
parents:
diff changeset
    97
{
hgs
parents:
diff changeset
    98
    TRAPD(errNo, activitiesL(result));
hgs
parents:
diff changeset
    99
    return errNo;
hgs
parents:
diff changeset
   100
}
hgs
parents:
diff changeset
   101
hgs
parents:
diff changeset
   102
// -----------------------------------------------------------------------------
hgs
parents:
diff changeset
   103
//
hgs
parents:
diff changeset
   104
// -----------------------------------------------------------------------------
hgs
parents:
diff changeset
   105
//
hgs
parents:
diff changeset
   106
int HsActivityDbClientPrivate::applicationActivities(QList<QVariantHash>& result, 
hgs
parents:
diff changeset
   107
                                                      const QVariantHash & condition)
hgs
parents:
diff changeset
   108
{
hgs
parents:
diff changeset
   109
    TRAPD(errNo, applicationActivitiesL(result, condition));
hgs
parents:
diff changeset
   110
    return errNo;
hgs
parents:
diff changeset
   111
}
hgs
parents:
diff changeset
   112
hgs
parents:
diff changeset
   113
hgs
parents:
diff changeset
   114
// -----------------------------------------------------------------------------
hgs
parents:
diff changeset
   115
//
hgs
parents:
diff changeset
   116
// -----------------------------------------------------------------------------
hgs
parents:
diff changeset
   117
//
hgs
parents:
diff changeset
   118
int HsActivityDbClientPrivate::waitActivity(const QVariantHash &activity)
hgs
parents:
diff changeset
   119
{
hgs
parents:
diff changeset
   120
    TRAPD( errNo, waitActivityL(activity);)
hgs
parents:
diff changeset
   121
    return errNo;
hgs
parents:
diff changeset
   122
}
hgs
parents:
diff changeset
   123
hgs
parents:
diff changeset
   124
// -----------------------------------------------------------------------------
hgs
parents:
diff changeset
   125
//
hgs
parents:
diff changeset
   126
// -----------------------------------------------------------------------------
hgs
parents:
diff changeset
   127
//
hgs
parents:
diff changeset
   128
int HsActivityDbClientPrivate::launchActivity(const QVariantHash &activity)
hgs
parents:
diff changeset
   129
{
hgs
parents:
diff changeset
   130
    TRAPD( errNo, execSimpleRequestL(LaunchActivity, activity);)
hgs
parents:
diff changeset
   131
    return errNo;
hgs
parents:
diff changeset
   132
}
hgs
parents:
diff changeset
   133
hgs
parents:
diff changeset
   134
// -----------------------------------------------------------------------------
hgs
parents:
diff changeset
   135
//
hgs
parents:
diff changeset
   136
// -----------------------------------------------------------------------------
hgs
parents:
diff changeset
   137
//
hgs
parents:
diff changeset
   138
int HsActivityDbClientPrivate::cancelWaitActivity()
hgs
parents:
diff changeset
   139
{
hgs
parents:
diff changeset
   140
    return SendReceive(CancelWait, TIpcArgs());
hgs
parents:
diff changeset
   141
}
hgs
parents:
diff changeset
   142
hgs
parents:
diff changeset
   143
// -----------------------------------------------------------------------------
hgs
parents:
diff changeset
   144
//
hgs
parents:
diff changeset
   145
// -----------------------------------------------------------------------------
hgs
parents:
diff changeset
   146
//
hgs
parents:
diff changeset
   147
void HsActivityDbClientPrivate::startServerL()
hgs
parents:
diff changeset
   148
{
hgs
parents:
diff changeset
   149
    RProcess server;
hgs
parents:
diff changeset
   150
    const TUidType uid(KNullUid, KNullUid, KActivityServerUid);
hgs
parents:
diff changeset
   151
    User::LeaveIfError(server.Create( KActivityServerName, KNullDesC, uid));
hgs
parents:
diff changeset
   152
    TRequestStatus stat;
hgs
parents:
diff changeset
   153
    server.Rendezvous( stat );
hgs
parents:
diff changeset
   154
    if ( stat != KRequestPending ) {
hgs
parents:
diff changeset
   155
        server.Kill(0);
hgs
parents:
diff changeset
   156
    } else {
hgs
parents:
diff changeset
   157
        server.Resume();
hgs
parents:
diff changeset
   158
    }
hgs
parents:
diff changeset
   159
    User::WaitForRequest(stat);
hgs
parents:
diff changeset
   160
    int errNo = (EExitPanic == server.ExitType()) ? 
hgs
parents:
diff changeset
   161
                KErrGeneral : stat.Int();
hgs
parents:
diff changeset
   162
    if(KErrCancel == errNo) {
hgs
parents:
diff changeset
   163
        errNo = KErrNone;
hgs
parents:
diff changeset
   164
    }
hgs
parents:
diff changeset
   165
    server.Close();
hgs
parents:
diff changeset
   166
    User::LeaveIfError(errNo);
hgs
parents:
diff changeset
   167
}
hgs
parents:
diff changeset
   168
hgs
parents:
diff changeset
   169
// -----------------------------------------------------------------------------
hgs
parents:
diff changeset
   170
//
hgs
parents:
diff changeset
   171
// -----------------------------------------------------------------------------
hgs
parents:
diff changeset
   172
//
hgs
parents:
diff changeset
   173
void HsActivityDbClientPrivate::connectL()
hgs
parents:
diff changeset
   174
{
hgs
parents:
diff changeset
   175
    const int asyncMessageSlots(4);
hgs
parents:
diff changeset
   176
    const int maxRetry(4);
hgs
parents:
diff changeset
   177
    
hgs
parents:
diff changeset
   178
    TInt retry = maxRetry;
hgs
parents:
diff changeset
   179
    TInt errNo(KErrNone);
hgs
parents:
diff changeset
   180
    do {
hgs
parents:
diff changeset
   181
        errNo = CreateSession( KActivityServerName, TVersion( 0, 0, 0 ), asyncMessageSlots );
hgs
parents:
diff changeset
   182
        if( KErrNotFound != errNo && KErrServerTerminated != errNo) {
hgs
parents:
diff changeset
   183
            retry =0;
hgs
parents:
diff changeset
   184
        } else {
hgs
parents:
diff changeset
   185
            TRAP(errNo, startServerL());
hgs
parents:
diff changeset
   186
            if (KErrNone != errNo && KErrAlreadyExists != errNo) {
hgs
parents:
diff changeset
   187
                retry =0;
hgs
parents:
diff changeset
   188
            }
hgs
parents:
diff changeset
   189
        }
hgs
parents:
diff changeset
   190
    } while(--retry > 0);
hgs
parents:
diff changeset
   191
    User::LeaveIfError(errNo);
hgs
parents:
diff changeset
   192
}
hgs
parents:
diff changeset
   193
hgs
parents:
diff changeset
   194
// -----------------------------------------------------------------------------
hgs
parents:
diff changeset
   195
//
hgs
parents:
diff changeset
   196
// -----------------------------------------------------------------------------
hgs
parents:
diff changeset
   197
//
hgs
parents:
diff changeset
   198
void HsActivityDbClientPrivate::execSimpleRequestL(int function, const QVariantHash &activity)
hgs
parents:
diff changeset
   199
{
hgs
parents:
diff changeset
   200
    RBuf8 data;
hgs
parents:
diff changeset
   201
    CleanupClosePushL(data);
hgs
parents:
diff changeset
   202
    data.CreateL(256);
hgs
parents:
diff changeset
   203
    data << activity;
hgs
parents:
diff changeset
   204
    User::LeaveIfError(SendReceive(function, TIpcArgs(&data)));
hgs
parents:
diff changeset
   205
    CleanupStack::PopAndDestroy(&data);
hgs
parents:
diff changeset
   206
}
hgs
parents:
diff changeset
   207
hgs
parents:
diff changeset
   208
// -----------------------------------------------------------------------------
hgs
parents:
diff changeset
   209
//
hgs
parents:
diff changeset
   210
// -----------------------------------------------------------------------------
hgs
parents:
diff changeset
   211
//
hgs
parents:
diff changeset
   212
void HsActivityDbClientPrivate::requestedActivityNameL(QString& result, 
hgs
parents:
diff changeset
   213
                                                const QVariantHash &activity)
hgs
parents:
diff changeset
   214
{
hgs
parents:
diff changeset
   215
    RBuf8 data;
hgs
parents:
diff changeset
   216
    TPckgBuf<int> sizeBuf;
hgs
parents:
diff changeset
   217
    CleanupClosePushL(data);
hgs
parents:
diff changeset
   218
    data.CreateL(256);
hgs
parents:
diff changeset
   219
    data << activity;
hgs
parents:
diff changeset
   220
    User::LeaveIfError(SendReceive(RequestedActivityName, TIpcArgs(&data,&sizeBuf)));
hgs
parents:
diff changeset
   221
    if(sizeBuf() > data.MaxSize()) {
hgs
parents:
diff changeset
   222
       data.ReAlloc(sizeBuf()); 
hgs
parents:
diff changeset
   223
    }
hgs
parents:
diff changeset
   224
    User::LeaveIfError(SendReceive(GetData, TIpcArgs(&data)));
hgs
parents:
diff changeset
   225
    result = QString::fromAscii(reinterpret_cast<const char*>(data.Ptr()), 
hgs
parents:
diff changeset
   226
                                data.Length());
hgs
parents:
diff changeset
   227
    CleanupStack::PopAndDestroy(&data);
hgs
parents:
diff changeset
   228
}
hgs
parents:
diff changeset
   229
hgs
parents:
diff changeset
   230
// -----------------------------------------------------------------------------
hgs
parents:
diff changeset
   231
//
hgs
parents:
diff changeset
   232
// -----------------------------------------------------------------------------
hgs
parents:
diff changeset
   233
//
hgs
parents:
diff changeset
   234
void HsActivityDbClientPrivate::activitiesL(QList<QVariantHash>& result)
hgs
parents:
diff changeset
   235
{
hgs
parents:
diff changeset
   236
    RBuf8 data;
hgs
parents:
diff changeset
   237
    TPckgBuf<int> sizeBuf;
hgs
parents:
diff changeset
   238
    CleanupClosePushL(data);
hgs
parents:
diff changeset
   239
    data.CreateL(256);
hgs
parents:
diff changeset
   240
    User::LeaveIfError(SendReceive(Activities, TIpcArgs(&data, &sizeBuf)));
hgs
parents:
diff changeset
   241
    if(sizeBuf() > data.MaxSize()) {
hgs
parents:
diff changeset
   242
       data.ReAlloc(sizeBuf()); 
hgs
parents:
diff changeset
   243
    }
hgs
parents:
diff changeset
   244
    User::LeaveIfError(SendReceive(GetData, TIpcArgs(&data)));
hgs
parents:
diff changeset
   245
    result << data;
hgs
parents:
diff changeset
   246
    CleanupStack::PopAndDestroy(&data);
hgs
parents:
diff changeset
   247
}
hgs
parents:
diff changeset
   248
hgs
parents:
diff changeset
   249
// -----------------------------------------------------------------------------
hgs
parents:
diff changeset
   250
//
hgs
parents:
diff changeset
   251
// -----------------------------------------------------------------------------
hgs
parents:
diff changeset
   252
//
hgs
parents:
diff changeset
   253
void HsActivityDbClientPrivate::applicationActivitiesL(QList<QVariantHash>& result, 
hgs
parents:
diff changeset
   254
                                                     const QVariantHash & condition)
hgs
parents:
diff changeset
   255
{
hgs
parents:
diff changeset
   256
    RBuf8 data;
hgs
parents:
diff changeset
   257
    TPckgBuf<int> sizeBuf;
hgs
parents:
diff changeset
   258
    CleanupClosePushL(data);
hgs
parents:
diff changeset
   259
    data.CreateL(256);
hgs
parents:
diff changeset
   260
    data << condition;
hgs
parents:
diff changeset
   261
    User::LeaveIfError(SendReceive(ApplicationActivities, TIpcArgs(&data, &sizeBuf)));
hgs
parents:
diff changeset
   262
    if(sizeBuf() > data.MaxSize()) {
hgs
parents:
diff changeset
   263
       data.ReAlloc(sizeBuf()); 
hgs
parents:
diff changeset
   264
    }
hgs
parents:
diff changeset
   265
    User::LeaveIfError(SendReceive(GetData, TIpcArgs(&data)));
hgs
parents:
diff changeset
   266
    result << data;
hgs
parents:
diff changeset
   267
    CleanupStack::PopAndDestroy(&data);
hgs
parents:
diff changeset
   268
}
hgs
parents:
diff changeset
   269
hgs
parents:
diff changeset
   270
// -----------------------------------------------------------------------------
hgs
parents:
diff changeset
   271
//
hgs
parents:
diff changeset
   272
// -----------------------------------------------------------------------------
hgs
parents:
diff changeset
   273
//
hgs
parents:
diff changeset
   274
void HsActivityDbClientPrivate::waitActivityL(const QVariantHash &activity)
hgs
parents:
diff changeset
   275
{
hgs
parents:
diff changeset
   276
    if(mAsyncDataHandler->IsActive()) {
hgs
parents:
diff changeset
   277
        User::Leave(KErrServerBusy);
hgs
parents:
diff changeset
   278
    } else {
hgs
parents:
diff changeset
   279
        mAsyncDataHandler->waitActivity(activity);
hgs
parents:
diff changeset
   280
    }
hgs
parents:
diff changeset
   281
}
hgs
parents:
diff changeset
   282
hgs
parents:
diff changeset
   283
// -----------------------------------------------------------------------------
hgs
parents:
diff changeset
   284
//
hgs
parents:
diff changeset
   285
// -----------------------------------------------------------------------------
hgs
parents:
diff changeset
   286
//
hgs
parents:
diff changeset
   287
void HsActivityDbClientPrivate::getData(RBuf8& data)
hgs
parents:
diff changeset
   288
{
hgs
parents:
diff changeset
   289
    SendReceive(GetData, TIpcArgs(&data));
hgs
parents:
diff changeset
   290
}
hgs
parents:
diff changeset
   291
hgs
parents:
diff changeset
   292
// -----------------------------------------------------------------------------
hgs
parents:
diff changeset
   293
//
hgs
parents:
diff changeset
   294
// -----------------------------------------------------------------------------
hgs
parents:
diff changeset
   295
//
hgs
parents:
diff changeset
   296
void HsActivityDbClientPrivate::sendDataAsync(int func,
hgs
parents:
diff changeset
   297
                                              const TIpcArgs &data, 
hgs
parents:
diff changeset
   298
                                              TRequestStatus& status)
hgs
parents:
diff changeset
   299
{
hgs
parents:
diff changeset
   300
    SendReceive(func, data, status);
hgs
parents:
diff changeset
   301
}