ns-3 Direct Code Execution
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
local-socket-fd-factory.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2011 INRIA
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: Frederic Urbani <frederic.urbani@inria.fr>
19  *
20  */
22 #include "local-socket-fd.h"
23 #include "local-stream-socket-fd.h"
25 #include "unix-fd.h"
26 #include "ns3/log.h"
27 #include <map>
28 
29 NS_LOG_COMPONENT_DEFINE ("LocalSocketFdFactory");
30 
31 namespace ns3 {
32 
33 NS_OBJECT_ENSURE_REGISTERED (LocalSocketFdFactory);
34 
35 TypeId
37 {
38  static TypeId tid = TypeId ("ns3::LocalSocketFdFactory").SetParent<Object> ()
39  .AddConstructor<LocalSocketFdFactory> ();
40 
41  return tid;
42 }
43 TypeId
45 {
47 }
49  : m_totalBuffersSize (0)
50 {
51 }
52 
54 {
55 }
56 
57 void
59 {
60  m_bindByPath.clear ();
61  // chain up
63 }
64 
65 UnixFd *
66 LocalSocketFdFactory::CreateSocket (int domain, int type, int protocol)
67 {
68  NS_ASSERT (domain == AF_UNIX);
69 
70  if (SOCK_STREAM == type)
71  {
72  UnixFd *fd = new LocalStreamSocketFd (this);
73 
74  return fd;
75  }
76  if (SOCK_DGRAM == type)
77  {
78  UnixFd *fd = new LocalDatagramSocketFd (this);
79 
80  return fd;
81  }
82 
83  return 0;
84 }
85 
87 LocalSocketFdFactory::FindBinder (std::string path, TypeId type) const
88 {
89  BindMap::const_iterator i = m_bindByPath.find (path);
90  if (m_bindByPath.end () == i)
91  {
92  return 0;
93  }
94 
95  LocalSocketFd* winner = i->second;
96 
97  if ((winner != 0) && (winner->GetInstanceTypeId () == type))
98  {
99  return winner;
100  }
101 
102  return 0;
103 }
104 
105 void
107 {
108  m_bindByPath[path] = socket;
109 }
110 
111 void
113 {
114  if (0 == m_bindByPath.count (path))
115  {
116  return;
117  }
118  m_bindByPath.erase (path);
119 }
120 void
122 {
123  UnRegisterBinder (path);
124 }
125 } // namespace ns3