1 // Copyright 2018 The Chromium 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 5 #ifndef OSP_IMPL_WITH_DESTRUCTION_CALLBACK_H_ 6 #define OSP_IMPL_WITH_DESTRUCTION_CALLBACK_H_ 7 8 #include "platform/base/macros.h" 9 10 namespace openscreen { 11 namespace osp { 12 13 // A decoration for classes which allows a callback to be run just after 14 // destruction. Setting the callback is optional. 15 class WithDestructionCallback { 16 public: 17 using DestructionCallbackFunctionPointer = void (*)(void*); 18 19 WithDestructionCallback(); 20 ~WithDestructionCallback(); 21 22 // Sets the function to be called from the destructor. 23 void SetDestructionCallback(DestructionCallbackFunctionPointer function, 24 void* state); 25 26 private: 27 DestructionCallbackFunctionPointer destruction_callback_function_ = nullptr; 28 void* destruction_callback_state_ = nullptr; 29 30 OSP_DISALLOW_COPY_AND_ASSIGN(WithDestructionCallback); 31 }; 32 33 } // namespace osp 34 } // namespace openscreen 35 36 #endif // OSP_IMPL_WITH_DESTRUCTION_CALLBACK_H_ 37