| Alex Deymo | 0d11c60 | 2014-04-23 20:12:20 -0700 | [diff] [blame] | 1 | // 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 Arnold | 48415f1 | 2014-06-27 07:10:58 -0700 | [diff] [blame] | 5 | #ifndef UPDATE_ENGINE_UPDATE_MANAGER_POLICY_UTILS_H_ | 
|  | 6 | #define UPDATE_ENGINE_UPDATE_MANAGER_POLICY_UTILS_H_ | 
| Alex Deymo | 0d11c60 | 2014-04-23 20:12:20 -0700 | [diff] [blame] | 7 |  | 
| Alex Deymo | 63784a5 | 2014-05-28 10:46:14 -0700 | [diff] [blame] | 8 | #include "update_engine/update_manager/policy.h" | 
| Alex Deymo | 0d11c60 | 2014-04-23 20:12:20 -0700 | [diff] [blame] | 9 |  | 
|  | 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 Arnold | 48415f1 | 2014-06-27 07:10:58 -0700 | [diff] [blame] | 26 | #endif  // UPDATE_ENGINE_UPDATE_MANAGER_POLICY_UTILS_H_ |