Alexander Afanasyev | 09e8d75 | 2012-04-10 16:05:55 -0700 | [diff] [blame] | 1 | /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /* |
| 3 | * Copyright (c) 2011 University of California, Los Angeles |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License version 2 as |
| 7 | * published by the Free Software Foundation; |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * GNU General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU General Public License |
| 15 | * along with this program; if not, write to the Free Software |
| 16 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 17 | * |
| 18 | * Author: Alexander Afanasyev <alexander.afanasyev@ucla.edu> |
| 19 | */ |
| 20 | |
| 21 | #include "sync-logic-helper.h" |
| 22 | #include "sync-logic.h" |
| 23 | |
| 24 | #include "ns3/log.h" |
| 25 | #include "ns3/string.h" |
| 26 | #include "ns3/names.h" |
| 27 | |
| 28 | NS_LOG_COMPONENT_DEFINE ("SyncLogicHelper"); |
| 29 | |
| 30 | using namespace ns3; |
| 31 | |
| 32 | namespace Sync |
| 33 | { |
| 34 | |
| 35 | SyncLogicHelper::SyncLogicHelper () |
| 36 | { |
| 37 | // m_factory.SetTypeId ("Sync::SyncLogic"); |
| 38 | } |
| 39 | |
| 40 | void |
| 41 | SyncLogicHelper::SetPrefix (const std::string &prefix) |
| 42 | { |
| 43 | m_prefix = prefix; |
| 44 | } |
| 45 | |
| 46 | |
| 47 | void |
| 48 | SyncLogicHelper::SetCallbacks (LogicUpdateCallback onUpdate, LogicRemoveCallback onRemove) |
| 49 | { |
| 50 | m_onUpdate = onUpdate; |
| 51 | m_onRemove = onRemove; |
| 52 | } |
| 53 | |
| 54 | // void |
| 55 | // CcnxAppHelper::SetAttribute (std::string name, const AttributeValue &value) |
| 56 | // { |
| 57 | // m_factory.Set (name, value); |
| 58 | // } |
| 59 | |
| 60 | ApplicationContainer |
| 61 | SyncLogicHelper::Install (Ptr<Node> node) |
| 62 | { |
| 63 | return ApplicationContainer (InstallPriv (node)); |
| 64 | } |
| 65 | |
| 66 | ApplicationContainer |
| 67 | SyncLogicHelper::Install (std::string nodeName) |
| 68 | { |
| 69 | Ptr<Node> node = Names::Find<Node> (nodeName); |
| 70 | return ApplicationContainer (InstallPriv (node)); |
| 71 | } |
| 72 | |
| 73 | ApplicationContainer |
| 74 | SyncLogicHelper::Install (NodeContainer c) |
| 75 | { |
| 76 | ApplicationContainer apps; |
| 77 | for (NodeContainer::Iterator i = c.Begin (); i != c.End (); ++i) |
| 78 | { |
| 79 | apps.Add (InstallPriv (*i)); |
| 80 | } |
| 81 | |
| 82 | return apps; |
| 83 | } |
| 84 | |
| 85 | Ptr<Application> |
| 86 | SyncLogicHelper::InstallPriv (Ptr<Node> node) |
| 87 | { |
| 88 | Ptr<SyncLogic> app = CreateObject<SyncLogic> ("/sync", m_onUpdate, m_onRemove); |
| 89 | node->AddApplication (app); |
| 90 | |
| 91 | return app; |
| 92 | } |
| 93 | |
| 94 | } |