~ubuntu-branches/ubuntu/vivid/akonadi/vivid

« back to all changes in this revision

Viewing changes to server/src/preprocessorinstance.cpp

  • Committer: Package Import Robot
  • Author(s): Rohan Garg
  • Date: 2013-11-11 17:38:58 UTC
  • mfrom: (1.1.46)
  • Revision ID: package-import@ubuntu.com-20131111173858-kltz6s4ebjishfej
Tags: 1.10.80-0ubuntu1
* New upstream release
 - Update install files
 - Update disable_dbus_requiring_tests.diff

Show diffs side-by-side

added added

removed removed

Lines of Context:
42
42
{
43
43
 
44
44
PreprocessorInstance::PreprocessorInstance( const QString &id )
45
 
  : QObject(), mId( id ), mInterface( 0 )
 
45
  : QObject()
 
46
  , mBusy( false )
 
47
  , mId( id )
 
48
  , mInterface( 0 )
46
49
{
47
50
  Q_ASSERT( !id.isEmpty() );
48
 
 
49
 
  mBusy = false;
50
51
}
51
52
 
52
53
PreprocessorInstance::~PreprocessorInstance()
65
66
      this
66
67
    );
67
68
 
68
 
  if( !mInterface || !mInterface->isValid() )
69
 
  {
 
69
  if ( !mInterface || !mInterface->isValid() ) {
70
70
    Tracer::self()->warning(
71
71
        QLatin1String( "PreprocessorInstance" ),
72
72
        QString::fromLatin1( "Could not connect to pre-processor instance '%1': %2" )
73
73
          .arg( mId )
74
 
          .arg( mInterface ? mInterface->lastError().message() : QString() )
75
 
      );
 
74
          .arg( mInterface ? mInterface->lastError().message() : QString() ) );
76
75
    delete mInterface;
77
76
    mInterface = 0;
78
77
    return false;
79
78
  }
80
79
 
81
 
  QObject::connect(
82
 
      mInterface,
83
 
      SIGNAL(itemProcessed(qlonglong)),
84
 
      this,
85
 
      SLOT(itemProcessed(qlonglong))
86
 
    );
 
80
  QObject::connect( mInterface, SIGNAL(itemProcessed(qlonglong)), this, SLOT(itemProcessed(qlonglong)) );
87
81
 
88
82
  return true;
89
83
}
90
84
 
91
85
void PreprocessorInstance::enqueueItem( qint64 itemId )
92
86
{
93
 
  akDebug() << "PreprocessorInstance::enqueueItem(" << itemId << ")";
 
87
  akDebug() << "PreprocessorInstance::enqueueItem("  << itemId <<  ")";
94
88
 
95
89
  mItemQueue.push_back( itemId );
96
90
 
97
91
  // If the preprocessor is already busy processing another item then do nothing.
98
 
  if ( mBusy )
99
 
  {
 
92
  if ( mBusy ) {
100
93
    // The "head" item is the one being processed and we have just added another one.
101
94
    Q_ASSERT( mItemQueue.size() > 1 );
102
95
    return;
120
113
 
121
114
  PimItem actualItem = PimItem::retrieveById( itemId );
122
115
 
123
 
  while ( !actualItem.isValid() )
124
 
  {
 
116
  while ( !actualItem.isValid() ) {
125
117
    // hum... item is gone ?
126
118
    // FIXME: Signal to the manager that the item is no longer valid!
127
119
    PreprocessorManager::instance()->preProcessorFinishedHandlingItem( this, itemId );
128
120
 
129
121
    mItemQueue.pop_front();
130
 
    if( mItemQueue.empty() )
131
 
    {
 
122
    if ( mItemQueue.empty() ) {
132
123
      // nothing more to process for this instance: jump out
133
124
      mBusy = false;
134
125
      return;
151
142
  mInterface->beginProcessItem( itemId, actualItem.collectionId(), actualItem.mimeType().name() );
152
143
 
153
144
  akDebug() << "PreprocessorInstance::processHeadItem(): processing started for item " << itemId;
154
 
 
155
145
}
156
146
 
157
147
int PreprocessorInstance::currentProcessingTime()
158
148
{
159
 
  if( !mBusy )
 
149
  if ( !mBusy ) {
160
150
    return -1; // nothing being processed
 
151
  }
161
152
 
162
153
  return mItemProcessingStartDateTime.secsTo( QDateTime::currentDateTime() );
163
154
}
170
161
      AkDBus::agentServiceName( mId, AkDBus::Agent ),
171
162
      QLatin1String( "/" ),
172
163
      QDBusConnection::sessionBus(),
173
 
      this
174
 
    );
 
164
      this );
175
165
 
176
 
  if( !iface.isValid() )
177
 
  {
 
166
  if ( !iface.isValid() ) {
178
167
    Tracer::self()->warning(
179
168
        QLatin1String( "PreprocessorInstance" ),
180
169
        QString::fromLatin1( "Could not connect to pre-processor instance '%1': %2" )
181
170
          .arg( mId )
182
 
          .arg( iface.lastError().message() )
183
 
      );
 
171
          .arg( iface.lastError().message() ) );
184
172
    return false;
185
173
  }
186
174
 
197
185
  Q_ASSERT_X( mBusy, "PreprocessorInstance::invokeRestart()", "You shouldn't call this method when isBusy() returns false" );
198
186
 
199
187
  OrgFreedesktopAkonadiAgentManagerInterface iface(
200
 
      AkDBus::serviceName(AkDBus::Control),
 
188
      AkDBus::serviceName( AkDBus::Control ),
201
189
      QLatin1String( "/AgentManager" ),
202
190
      QDBusConnection::sessionBus(),
203
 
      this
204
 
    );
 
191
      this );
205
192
 
206
 
  if( !iface.isValid() )
207
 
  {
 
193
  if ( !iface.isValid() ) {
208
194
    Tracer::self()->warning(
209
195
        QLatin1String( "PreprocessorInstance" ),
210
196
        QString::fromLatin1( "Could not connect to the AgentManager in order to restart pre-processor instance '%1': %2" )
211
197
          .arg( mId )
212
 
          .arg( iface.lastError().message() )
213
 
      );
 
198
          .arg( iface.lastError().message() ) );
214
199
    return false;
215
200
  }
216
201
 
219
204
  return true;
220
205
}
221
206
 
222
 
 
223
207
void PreprocessorInstance::itemProcessed( qlonglong id )
224
208
{
225
 
  akDebug() << "PreprocessorInstance::itemProcessed(" << id << ")";
 
209
  akDebug() << "PreprocessorInstance::itemProcessed("  << id <<  ")";
226
210
 
227
211
  // We shouldn't be called if there are no items in the queue
228
 
  if( mItemQueue.empty() )
229
 
  {
 
212
  if ( mItemQueue.empty() ) {
230
213
    Tracer::self()->warning(
231
214
        QLatin1String( "PreprocessorInstance" ),
232
215
        QString::fromLatin1( "Pre-processor instance '%1' emitted itemProcessed(%2) but we actually have no item in the queue" )
233
216
          .arg( mId )
234
 
          .arg( id )
235
 
      );
 
217
          .arg( id ) );
236
218
    mBusy = false;
237
219
    return; // preprocessor is buggy (FIXME: What now ?)
238
220
  }
242
224
 
243
225
  qlonglong itemId = mItemQueue.front();
244
226
 
245
 
  if( itemId != id )
246
 
  {
 
227
  if ( itemId != id ) {
247
228
    Tracer::self()->warning(
248
229
        QLatin1String( "PreprocessorInstance" ),
249
230
        QString::fromLatin1( "Pre-processor instance '%1' emitted itemProcessed(%2) but the head item in the queue has id %3" )
250
231
          .arg( mId )
251
232
          .arg( id )
252
 
          .arg( itemId )
253
 
      );
 
233
          .arg( itemId ) );
254
234
 
255
235
    // FIXME: And what now ?
256
236
  }
259
239
 
260
240
  PreprocessorManager::instance()->preProcessorFinishedHandlingItem( this, itemId );
261
241
 
262
 
  if( mItemQueue.empty() )
263
 
  {
 
242
  if ( mItemQueue.empty() ) {
264
243
    // Nothing more to do
265
244
    mBusy = false;
266
245
    return;
270
249
  processHeadItem();
271
250
}
272
251
 
273
 
 
274
252
} // namespace Akonadi
275