summaryrefslogtreecommitdiff
path: root/src/mongo/s/type_lockpings.cpp
diff options
context:
space:
mode:
authorShaun Verch <shaun.verch@10gen.com>2013-01-17 11:50:29 +0000
committerShaun Verch <shaun.verch@10gen.com>2013-01-17 15:56:57 +0000
commit588a5937884a07c72af6e40a98cd592eedebc74e (patch)
tree46846baf1734035594aecf323bb93cc38efcba98 /src/mongo/s/type_lockpings.cpp
parent04296d4f271aacfaaa8fc7c822e07dba76ae4a50 (diff)
downloadmongo-588a5937884a07c72af6e40a98cd592eedebc74e.tar.gz
SERVER-939 Update LockpingsType with new method of recording field presence and handling defaults
Diffstat (limited to 'src/mongo/s/type_lockpings.cpp')
-rw-r--r--src/mongo/s/type_lockpings.cpp42
1 files changed, 31 insertions, 11 deletions
diff --git a/src/mongo/s/type_lockpings.cpp b/src/mongo/s/type_lockpings.cpp
index 97a42af1c29..b43ced50af4 100644
--- a/src/mongo/s/type_lockpings.cpp
+++ b/src/mongo/s/type_lockpings.cpp
@@ -13,7 +13,6 @@
* 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/>.
*/
-
#include "mongo/s/type_lockpings.h"
#include "mongo/s/field_parser.h"
@@ -25,8 +24,8 @@ namespace mongo {
const std::string LockpingsType::ConfigNS = "config.lockpings";
- BSONField<string> LockpingsType::process("_id");
- BSONField<Date_t> LockpingsType::ping("ping");
+ const BSONField<std::string> LockpingsType::process("_id");
+ const BSONField<Date_t> LockpingsType::ping("ping");
LockpingsType::LockpingsType() {
clear();
@@ -41,11 +40,12 @@ namespace mongo {
errMsg = &dummy;
}
- if (_process.empty()) {
+ // All the mandatory fields must be present.
+ if (!_isProcessSet) {
*errMsg = stream() << "missing " << process.name() << " field";
return false;
}
- if (_ping.millis == 0) {
+ if (!_isPingSet) {
*errMsg = stream() << "missing " << ping.name() << " field";
return false;
}
@@ -56,8 +56,8 @@ namespace mongo {
BSONObj LockpingsType::toBSON() const {
BSONObjBuilder builder;
- if (!_process.empty()) builder.append(process(), _process);
- if (_ping.millis > 0ULL) builder.append(ping(), _ping);
+ if (_isProcessSet) builder.append(process(), _process);
+ if (_isPingSet) builder.append(ping(), _ping);
return builder.obj();
}
@@ -65,24 +65,44 @@ namespace mongo {
bool LockpingsType::parseBSON(BSONObj source, string* errMsg) {
clear();
- string dummy;
+ std::string dummy;
if (!errMsg) errMsg = &dummy;
- if (!FieldParser::extract(source, process, "", &_process, errMsg)) return false;
- if (!FieldParser::extract(source, ping, 0ULL, &_ping, errMsg)) return false;
+ FieldParser::FieldState fieldState;
+ fieldState = FieldParser::extract(source, process, "", &_process, errMsg);
+ if (fieldState == FieldParser::FIELD_INVALID) return false;
+ _isProcessSet = fieldState == FieldParser::FIELD_VALID;
+
+ fieldState = FieldParser::extract(source, ping, 0, &_ping, errMsg);
+ if (fieldState == FieldParser::FIELD_INVALID) return false;
+ _isPingSet = fieldState == FieldParser::FIELD_VALID;
return true;
}
void LockpingsType::clear() {
+
_process.clear();
+ _isProcessSet = false;
+
_ping = 0ULL;
+ _isPingSet = false;
+
}
- void LockpingsType::cloneTo(LockpingsType* other) {
+ void LockpingsType::cloneTo(LockpingsType* other) const {
other->clear();
+
other->_process = _process;
+ other->_isProcessSet = _isProcessSet;
+
other->_ping = _ping;
+ other->_isPingSet = _isPingSet;
+
+ }
+
+ std::string LockpingsType::toString() const {
+ return toBSON().toString();
}
} // namespace mongo