blob: 34c3de6074534b1c517876c0f273457f3cb32e37 [file] [log] [blame]
Alexander Afanasyeve4795ae2013-07-11 20:01:31 -07001/* -*- 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
16NS_LOG_COMPONENT_DEFINE ("CallbackBasedApp");
17
18namespace ns3 {
19
20NS_OBJECT_ENSURE_REGISTERED (CallbackBasedApp);
21
22TypeId
23CallbackBasedApp::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
43CallbackBasedApp::CallbackBasedApp ()
44{
45}
46
47CallbackBasedApp::~CallbackBasedApp ()
48{
49}
50
51void
52CallbackBasedApp::SetOnStartCallback (Callback< void, Ptr<Application> > onStart)
53{
54 m_onStart = onStart;
55}
56
57void
58CallbackBasedApp::SetOnStopCallback (Callback< void, Ptr<Application> > onStop)
59{
60 m_onStop = onStop;
61}
62
63void
64CallbackBasedApp::StartApplication ()
65{
66 NS_LOG_FUNCTION (this);
67 if (!m_onStart.IsNull ())
68 m_onStart (this);
69}
70
71void
72CallbackBasedApp::StopApplication ()
73{
74 NS_LOG_FUNCTION (this);
75 if (!m_onStop.IsNull ())
76 m_onStop (this);
77}
78
79}