2014-07-31 00:35:19 +00:00
|
|
|
// Copyright 2004-present Facebook. All Rights Reserved.
|
|
|
|
|
2014-08-05 23:13:55 +00:00
|
|
|
#ifndef OSQUERY_STATUS_H
|
|
|
|
#define OSQUERY_STATUS_H
|
2014-07-31 00:35:19 +00:00
|
|
|
|
|
|
|
#include <string>
|
|
|
|
|
2014-08-05 23:13:55 +00:00
|
|
|
namespace osquery {
|
2014-07-31 00:35:19 +00:00
|
|
|
|
2014-09-09 18:02:17 +00:00
|
|
|
// osquery::Status is a utility class which is used all over osquery to
|
|
|
|
// express the state of operations.
|
2014-07-31 00:35:19 +00:00
|
|
|
class Status {
|
2014-08-15 07:25:30 +00:00
|
|
|
public:
|
2014-09-09 18:02:17 +00:00
|
|
|
// default constructor
|
2014-09-06 10:41:10 +00:00
|
|
|
Status() : code_(0), message_("OK") {}
|
2014-09-09 18:02:17 +00:00
|
|
|
|
2014-09-09 18:03:23 +00:00
|
|
|
// constructor which allows you to do something like:
|
2014-09-09 18:02:17 +00:00
|
|
|
// auto s = Status(0, "OK);
|
2014-07-31 00:35:19 +00:00
|
|
|
Status(int c, std::string m) : code_(c), message_(m) {}
|
2014-08-15 07:25:30 +00:00
|
|
|
|
|
|
|
public:
|
2014-09-09 18:02:17 +00:00
|
|
|
// a getter for the code property
|
|
|
|
int getCode() const { return code_; }
|
|
|
|
|
|
|
|
// a getter for the message property
|
|
|
|
std::string getMessage() const { return message_; }
|
|
|
|
|
|
|
|
// a convenience method to check if the return code of the status is 0
|
|
|
|
bool ok() const { return getCode() == 0; }
|
|
|
|
|
|
|
|
// a synonym for getMessage().
|
|
|
|
std::string toString() const { return getMessage(); }
|
2014-07-31 00:35:19 +00:00
|
|
|
|
2014-08-15 07:25:30 +00:00
|
|
|
private:
|
|
|
|
int code_;
|
|
|
|
std::string message_;
|
|
|
|
};
|
2014-08-05 23:13:55 +00:00
|
|
|
}
|
2014-07-31 00:35:19 +00:00
|
|
|
|
2014-08-05 23:13:55 +00:00
|
|
|
#endif /* OSQUERY_STATUS_H */
|