NS-3 based Named Data Networking (NDN) simulator
ndnSIM: NDN, CCN, CCNx, content centric networks
API Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Groups Pages
callback-based-app.cc
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 
44 {
45 }
46 
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
65 {
66  NS_LOG_FUNCTION (this);
67  if (!m_onStart.IsNull ())
68  m_onStart (this);
69 }
70 
71 void
73 {
74  NS_LOG_FUNCTION (this);
75  if (!m_onStop.IsNull ())
76  m_onStop (this);
77 }
78 
79 }
virtual void StartApplication()
Called at time specified by Start.
CallbackBasedApp()
Default constructor.
void SetOnStopCallback(Callback< void, Ptr< Application > > onStart)
Define callback that will be fired when application need to stop its work.
virtual ~CallbackBasedApp()
Virtual destructor.
virtual void StopApplication()
Called at time specified by Stop.
void SetOnStartCallback(Callback< void, Ptr< Application > > onStart)
Define callback that will be fired when application need to start its work.