blob: d612f2083bf68eae70fac6956a57262c0993df48 [file] [log] [blame]
Alex Deymo0d11c602014-04-23 20:12:20 -07001// Copyright (c) 2014 The Chromium OS Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
Gilad Arnold48415f12014-06-27 07:10:58 -07005#ifndef UPDATE_ENGINE_UPDATE_MANAGER_POLICY_UTILS_H_
6#define UPDATE_ENGINE_UPDATE_MANAGER_POLICY_UTILS_H_
Alex Deymo0d11c602014-04-23 20:12:20 -07007
Alex Deymo63784a52014-05-28 10:46:14 -07008#include "update_engine/update_manager/policy.h"
Alex Deymo0d11c602014-04-23 20:12:20 -07009
10// Checks that the passed pointer value is not null, returning kFailed on the
11// current context and setting the *error description when it is null. The
12// intended use is to validate variable failures while using
13// EvaluationContext::GetValue, for example:
14//
15// const int* my_value = ec->GetValue(state->my_provider()->var_my_value());
16// POLICY_CHECK_VALUE_AND_FAIL(my_value, error);
17//
18#define POLICY_CHECK_VALUE_AND_FAIL(ptr, error) \
19 do { \
20 if ((ptr) == nullptr) { \
21 *(error) = #ptr " is required but is null."; \
22 return EvalStatus::kFailed; \
23 } \
24 } while (false)
25
Gilad Arnold48415f12014-06-27 07:10:58 -070026#endif // UPDATE_ENGINE_UPDATE_MANAGER_POLICY_UTILS_H_