blob: 83ee87e0f7181a650cd2c971fb717065ebb13151 [file] [log] [blame]
Andreas Gampec9a01e42018-10-22 12:50:19 -07001/*
2 * Copyright (C) 2018 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef ANDROID_APEXD_STATUS_H_
18#define ANDROID_APEXD_STATUS_H_
19
20#include <string>
21
22#include <android-base/logging.h>
23
24namespace android {
25namespace apex {
26
27class Status {
28 public:
29 Status() : ok_(true) {}
Chih-Hung Hsiehab73a442019-01-02 11:28:05 -080030 explicit Status(const std::string& error_msg)
31 : error_msg_(error_msg), ok_(false) {}
Andreas Gampec9a01e42018-10-22 12:50:19 -070032
33 // For better legible code.
Dario Freni88b859b2018-11-06 17:23:36 +000034 static Status Success() { return Status(); }
35 static Status Fail(const std::string& error_msg) { return Status(error_msg); }
Andreas Gampec9a01e42018-10-22 12:50:19 -070036
Dario Freni88b859b2018-11-06 17:23:36 +000037 bool Ok() const { return ok_; }
Andreas Gampec9a01e42018-10-22 12:50:19 -070038
39 const std::string& ErrorMessage() const {
40 CHECK(!ok_);
41 return error_msg_;
42 }
43
44 private:
45 std::string error_msg_;
46 bool ok_;
47};
48
Dario Freni88b859b2018-11-06 17:23:36 +000049} // namespace apex
50} // namespace android
Andreas Gampec9a01e42018-10-22 12:50:19 -070051
Dario Freni88b859b2018-11-06 17:23:36 +000052#endif // ANDROID_APEXD_STATUS_H_