Alexander Afanasyev | e4795ae | 2013-07-11 20:01:31 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */ |
| 2 | /* |
| 3 | * Copyright (c) 2013, Regents of the University of California |
| 4 | * Alexander Afanasyev |
| 5 | * Zhenkai Zhu |
| 6 | * |
| 7 | * GNU v3.0 license, See the LICENSE file for more information |
| 8 | * |
| 9 | * Author: Alexander Afanasyev <alexander.afanasyev@ucla.edu> |
| 10 | */ |
| 11 | |
| 12 | #include "callback-based-app.h" |
| 13 | |
| 14 | #include <ns3/log.h> |
| 15 | |
| 16 | NS_LOG_COMPONENT_DEFINE ("CallbackBasedApp"); |
| 17 | |
| 18 | namespace ns3 { |
| 19 | |
| 20 | NS_OBJECT_ENSURE_REGISTERED (CallbackBasedApp); |
| 21 | |
| 22 | TypeId |
| 23 | CallbackBasedApp::GetTypeId (void) |
| 24 | { |
| 25 | static TypeId tid = TypeId ("ns3::CallbackBasedApp") |
| 26 | .SetGroupName ("Ndn") |
| 27 | .SetParent<Application> () |
| 28 | .AddConstructor<CallbackBasedApp> () |
| 29 | |
| 30 | .AddAttribute ("OnStart", "OnStart callback", |
| 31 | CallbackValue (), |
| 32 | MakeCallbackAccessor (&CallbackBasedApp::m_onStart), |
| 33 | MakeCallbackChecker ()) |
| 34 | |
| 35 | .AddAttribute ("OnStop", "OnStop callback", |
| 36 | CallbackValue (), |
| 37 | MakeCallbackAccessor (&CallbackBasedApp::m_onStop), |
| 38 | MakeCallbackChecker ()) |
| 39 | ; |
| 40 | return tid; |
| 41 | } |
| 42 | |
| 43 | CallbackBasedApp::CallbackBasedApp () |
| 44 | { |
| 45 | } |
| 46 | |
| 47 | CallbackBasedApp::~CallbackBasedApp () |
| 48 | { |
| 49 | } |
| 50 | |
| 51 | void |
| 52 | CallbackBasedApp::SetOnStartCallback (Callback< void, Ptr<Application> > onStart) |
| 53 | { |
| 54 | m_onStart = onStart; |
| 55 | } |
| 56 | |
| 57 | void |
| 58 | CallbackBasedApp::SetOnStopCallback (Callback< void, Ptr<Application> > onStop) |
| 59 | { |
| 60 | m_onStop = onStop; |
| 61 | } |
| 62 | |
| 63 | void |
| 64 | CallbackBasedApp::StartApplication () |
| 65 | { |
| 66 | NS_LOG_FUNCTION (this); |
| 67 | if (!m_onStart.IsNull ()) |
| 68 | m_onStart (this); |
| 69 | } |
| 70 | |
| 71 | void |
| 72 | CallbackBasedApp::StopApplication () |
| 73 | { |
| 74 | NS_LOG_FUNCTION (this); |
| 75 | if (!m_onStop.IsNull ()) |
| 76 | m_onStop (this); |
| 77 | } |
| 78 | |
| 79 | } |