| OLD | NEW |
| (Empty) |
| 1 // Copyright 2007-2009 Google Inc. | |
| 2 // | |
| 3 // Licensed under the Apache License, Version 2.0 (the "License"); | |
| 4 // you may not use this file except in compliance with the License. | |
| 5 // You may obtain a copy of the License at | |
| 6 // | |
| 7 // http://www.apache.org/licenses/LICENSE-2.0 | |
| 8 // | |
| 9 // Unless required by applicable law or agreed to in writing, software | |
| 10 // distributed under the License is distributed on an "AS IS" BASIS, | |
| 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| 12 // See the License for the specific language governing permissions and | |
| 13 // limitations under the License. | |
| 14 // ======================================================================== | |
| 15 | |
| 16 #include "omaha/base/shutdown_handler.h" | |
| 17 | |
| 18 #include <atlsecurity.h> | |
| 19 #include "omaha/base/const_object_names.h" | |
| 20 #include "omaha/base/debug.h" | |
| 21 #include "omaha/base/error.h" | |
| 22 #include "omaha/base/logging.h" | |
| 23 #include "omaha/base/reactor.h" | |
| 24 #include "omaha/base/shutdown_callback.h" | |
| 25 #include "omaha/base/utils.h" | |
| 26 | |
| 27 namespace omaha { | |
| 28 | |
| 29 ShutdownHandler::ShutdownHandler() | |
| 30 : shutdown_callback_(NULL) { | |
| 31 } | |
| 32 | |
| 33 ShutdownHandler::~ShutdownHandler() { | |
| 34 if (get(shutdown_event_)) { | |
| 35 VERIFY1(SUCCEEDED(reactor_->UnregisterHandle(get(shutdown_event_)))); | |
| 36 } | |
| 37 } | |
| 38 | |
| 39 HRESULT ShutdownHandler::Initialize(Reactor* reactor, | |
| 40 ShutdownCallback* shutdown, | |
| 41 bool is_machine) { | |
| 42 ASSERT1(reactor); | |
| 43 ASSERT1(shutdown); | |
| 44 shutdown_callback_ = shutdown; | |
| 45 reactor_ = reactor; | |
| 46 is_machine_ = is_machine; | |
| 47 | |
| 48 NamedObjectAttributes attr; | |
| 49 GetNamedObjectAttributes(kShutdownEvent, is_machine_, &attr); | |
| 50 // Manual reset=true and signaled=false | |
| 51 reset(shutdown_event_, ::CreateEvent(&attr.sa, true, false, attr.name)); | |
| 52 if (!shutdown_event_) { | |
| 53 return HRESULTFromLastError(); | |
| 54 } | |
| 55 | |
| 56 HRESULT hr = reactor_->RegisterHandle(get(shutdown_event_), this, 0); | |
| 57 if (FAILED(hr)) { | |
| 58 return hr; | |
| 59 } | |
| 60 | |
| 61 return S_OK; | |
| 62 } | |
| 63 | |
| 64 void ShutdownHandler::HandleEvent(HANDLE handle) { | |
| 65 if (handle == get(shutdown_event_)) { | |
| 66 CORE_LOG(L1, (_T("[shutdown event is signaled]"))); | |
| 67 } else { | |
| 68 ASSERT1(false); | |
| 69 } | |
| 70 ASSERT1(shutdown_callback_); | |
| 71 shutdown_callback_->Shutdown(); | |
| 72 } | |
| 73 | |
| 74 } // namespace omaha | |
| 75 | |
| OLD | NEW |