2009-02-05 17:51:51 +01:00
|
|
|
// lasterror.h
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Copyright (C) 2009 10gen Inc.
|
|
|
|
*
|
2009-01-05 21:30:07 +01:00
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License, version 3,
|
|
|
|
* as published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Affero General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Affero General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
2009-01-14 23:17:24 +01:00
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <boost/thread/tss.hpp>
|
2009-05-15 23:27:31 +02:00
|
|
|
#undef assert
|
|
|
|
#define assert xassert
|
2009-01-14 23:09:51 +01:00
|
|
|
|
|
|
|
namespace mongo {
|
2009-03-26 18:45:29 +01:00
|
|
|
class BSONObjBuilder;
|
|
|
|
|
2009-01-15 16:17:11 +01:00
|
|
|
struct LastError {
|
|
|
|
string msg;
|
2009-04-06 23:57:16 +02:00
|
|
|
enum UpdatedExistingType { NotUpdate, True, False } updatedExisting;
|
2009-03-26 18:45:29 +01:00
|
|
|
int nObjects;
|
2009-01-15 16:17:11 +01:00
|
|
|
int nPrev;
|
2009-03-26 18:45:29 +01:00
|
|
|
bool valid;
|
2009-01-15 16:17:11 +01:00
|
|
|
void raiseError(const char *_msg) {
|
2009-03-26 18:45:29 +01:00
|
|
|
reset( true );
|
2009-01-15 16:17:11 +01:00
|
|
|
msg = _msg;
|
|
|
|
}
|
2009-04-10 16:30:57 +02:00
|
|
|
void recordUpdate( bool _updatedExisting, int nChanged ) {
|
2009-03-26 18:45:29 +01:00
|
|
|
reset( true );
|
2009-04-10 16:30:57 +02:00
|
|
|
nObjects = nChanged;
|
2009-03-26 18:45:29 +01:00
|
|
|
updatedExisting = _updatedExisting ? True : False;
|
2009-01-15 16:17:11 +01:00
|
|
|
}
|
2009-03-26 18:45:29 +01:00
|
|
|
void recordDelete( int nDeleted ) {
|
|
|
|
reset( true );
|
|
|
|
nObjects = nDeleted;
|
2009-01-15 16:17:11 +01:00
|
|
|
}
|
|
|
|
LastError() {
|
2009-03-26 18:45:29 +01:00
|
|
|
reset();
|
|
|
|
}
|
|
|
|
void reset( bool _valid = false ) {
|
|
|
|
msg.clear();
|
|
|
|
updatedExisting = NotUpdate;
|
|
|
|
nObjects = 0;
|
|
|
|
nPrev = 1;
|
|
|
|
valid = _valid;
|
2009-01-15 16:17:11 +01:00
|
|
|
}
|
2009-03-26 18:45:29 +01:00
|
|
|
void appendSelf( BSONObjBuilder &b );
|
|
|
|
static LastError noError;
|
2009-01-15 16:17:11 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
extern boost::thread_specific_ptr<LastError> lastError;
|
|
|
|
|
|
|
|
inline void raiseError(const char *msg) {
|
|
|
|
LastError *le = lastError.get();
|
|
|
|
if ( le == 0 ) {
|
|
|
|
DEV log() << "warning: lastError==0 can't report:" << msg << '\n';
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
le->raiseError(msg);
|
2009-01-14 23:17:24 +01:00
|
|
|
}
|
2009-03-26 18:45:29 +01:00
|
|
|
|
2009-04-10 16:30:57 +02:00
|
|
|
inline void recordUpdate( bool updatedExisting, int nChanged ) {
|
2009-03-26 18:45:29 +01:00
|
|
|
LastError *le = lastError.get();
|
|
|
|
if ( le )
|
2009-04-10 16:30:57 +02:00
|
|
|
le->recordUpdate( updatedExisting, nChanged );
|
2009-03-26 18:45:29 +01:00
|
|
|
}
|
2009-01-15 16:17:11 +01:00
|
|
|
|
2009-03-26 18:45:29 +01:00
|
|
|
inline void recordDelete( int nDeleted ) {
|
|
|
|
LastError *le = lastError.get();
|
|
|
|
if ( le )
|
|
|
|
le->recordDelete( nDeleted );
|
|
|
|
}
|
2009-01-15 16:17:11 +01:00
|
|
|
} // namespace mongo
|