File indexing completed on 2024-04-28 08:54:36
0001 /* 0002 * This file is part of TelepathyLoggerQt 0003 * 0004 * Copyright (C) 2013 Dan Vrátil <dvratil@redhat.com> 0005 * 0006 * This library is free software; you can redistribute it and/or modify 0007 * it under the terms of the GNU Lesser General Public License as published 0008 * by the Free Software Foundation; either version 2.1 of the License, or 0009 * (at your option) any later version. 0010 * 0011 * This program is distributed in the hope that it will be useful, 0012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0014 * GNU General Public License for more details. 0015 * 0016 * You should have received a copy of the GNU Lesser General Public License 0017 * along with this program. If not, see <http://www.gnu.org/licenses/>. 0018 */ 0019 0020 #include "pending-log-walker-operation.h" 0021 #include "log-walker.h" 0022 #include "utils.h" 0023 0024 #include <TelepathyQt/Constants> 0025 0026 #include <telepathy-logger/log-walker.h> 0027 0028 0029 using namespace Tpl; 0030 0031 struct TELEPATHY_LOGGER_QT_NO_EXPORT PendingLogWalkerOperation::Private 0032 { 0033 LogWalkerPtr logWalker; 0034 OperationType operation; 0035 int numEvents; 0036 0037 static void rewindFinished(TplLogWalker *tpLogWalker, void *result, PendingLogWalkerOperation *operation); 0038 }; 0039 0040 PendingLogWalkerOperation::PendingLogWalkerOperation(const LogWalkerPtr& logWalker, 0041 PendingLogWalkerOperation::OperationType operation, 0042 uint numEvents) 0043 : PendingOperation(), 0044 mPriv(new Private()) 0045 { 0046 mPriv->logWalker = logWalker; 0047 mPriv->operation = operation; 0048 mPriv->numEvents = numEvents; 0049 } 0050 0051 PendingLogWalkerOperation::~PendingLogWalkerOperation() 0052 { 0053 delete mPriv; 0054 } 0055 0056 void PendingLogWalkerOperation::start() 0057 { 0058 if (mPriv->operation == Rewind) { 0059 tpl_log_walker_rewind_async( 0060 TPLoggerQtWrapper::unwrap<TplLogWalker, LogWalker>(mPriv->logWalker), 0061 mPriv->numEvents, 0062 (GAsyncReadyCallback) Private::rewindFinished, 0063 this); 0064 } 0065 } 0066 0067 void PendingLogWalkerOperation::Private::rewindFinished(TplLogWalker *tpLogWalker, 0068 void* result, 0069 PendingLogWalkerOperation* operation) 0070 { 0071 if (!TPL_IS_LOG_WALKER(tpLogWalker)) { 0072 operation->setFinishedWithError(TP_QT_ERROR_INVALID_ARGUMENT, "Invalid log walker in callback"); 0073 return; 0074 } 0075 0076 if (!G_IS_ASYNC_RESULT(result)) { 0077 operation->setFinishedWithError(TP_QT_ERROR_INVALID_ARGUMENT, "Invalid async result in callback"); 0078 return; 0079 } 0080 0081 operation->setFinished(); 0082 }