1 /*
2 * This file is part of TelepathyLoggerQt
3 *
4 * Copyright (C) 2013 Dan Vrátil <dvratil@redhat.com>
5 *
6 * This library is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU Lesser General Public License as published
8 * by the Free Software Foundation; either version 2.1 of the License, or
9 * (at your option) any later version.
10 *
11 * This program 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
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20 #include "pending-log-walker-operation.h"
21 #include "log-walker.h"
22 #include "utils.h"
23
24 #include <TelepathyQt/Constants>
25
26 #include <telepathy-logger/log-walker.h>
27
28
29 using namespace Tpl;
30
31 struct TELEPATHY_LOGGER_QT_NO_EXPORT PendingLogWalkerOperation::Private
32 {
33 LogWalkerPtr logWalker;
34 OperationType operation;
35 int numEvents;
36
37 static void rewindFinished(TplLogWalker *tpLogWalker, void *result, PendingLogWalkerOperation *operation);
38 };
39
PendingLogWalkerOperation(const LogWalkerPtr & logWalker,PendingLogWalkerOperation::OperationType operation,uint numEvents)40 PendingLogWalkerOperation::PendingLogWalkerOperation(const LogWalkerPtr& logWalker,
41 PendingLogWalkerOperation::OperationType operation,
42 uint numEvents)
43 : PendingOperation(),
44 mPriv(new Private())
45 {
46 mPriv->logWalker = logWalker;
47 mPriv->operation = operation;
48 mPriv->numEvents = numEvents;
49 }
50
~PendingLogWalkerOperation()51 PendingLogWalkerOperation::~PendingLogWalkerOperation()
52 {
53 delete mPriv;
54 }
55
start()56 void PendingLogWalkerOperation::start()
57 {
58 if (mPriv->operation == Rewind) {
59 tpl_log_walker_rewind_async(
60 TPLoggerQtWrapper::unwrap<TplLogWalker, LogWalker>(mPriv->logWalker),
61 mPriv->numEvents,
62 (GAsyncReadyCallback) Private::rewindFinished,
63 this);
64 }
65 }
66
rewindFinished(TplLogWalker * tpLogWalker,void * result,PendingLogWalkerOperation * operation)67 void PendingLogWalkerOperation::Private::rewindFinished(TplLogWalker *tpLogWalker,
68 void* result,
69 PendingLogWalkerOperation* operation)
70 {
71 if (!TPL_IS_LOG_WALKER(tpLogWalker)) {
72 operation->setFinishedWithError(TP_QT_ERROR_INVALID_ARGUMENT, "Invalid log walker in callback");
73 return;
74 }
75
76 if (!G_IS_ASYNC_RESULT(result)) {
77 operation->setFinishedWithError(TP_QT_ERROR_INVALID_ARGUMENT, "Invalid async result in callback");
78 return;
79 }
80
81 operation->setFinished();
82 }
83