1 /* 2 * Copyright (C) 2016 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 #include "resetreasonevent.h" 18 19 #include "contexthub.h" 20 #include "log.h" 21 22 namespace android { 23 24 /* ResetReasonEvent *************************************************************/ 25 FromBytes(const std::vector<uint8_t> & buffer)26std::unique_ptr<ResetReasonEvent> ResetReasonEvent::FromBytes( 27 const std::vector<uint8_t>& buffer) { 28 auto event = std::unique_ptr<ResetReasonEvent>(new ResetReasonEvent()); 29 event->Populate(buffer); 30 31 return event; 32 } 33 GetReason() const34uint32_t ResetReasonEvent::GetReason() const { 35 // After the event type header (uint32_t), we should have the reset reason, 36 // which is of type uint32_t 37 if (event_data.size() < (sizeof(uint32_t) + sizeof(uint32_t))) { 38 LOGW("Invalid/short ResetReason event of size %zu", event_data.size()); 39 return 0; 40 } else { 41 return *(uint32_t*)reinterpret_cast<const uint32_t*>( 42 event_data.data() + sizeof(uint32_t)); 43 } 44 } 45 46 } // namespace android 47