ns-3 Direct Code Execution
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
file-usage.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  */
21 #include "file-usage.h"
22 #include "ns3/log.h"
23 #include "unix-fd.h"
24 
25 NS_LOG_COMPONENT_DEFINE ("FileUsage");
26 
27 namespace ns3 {
29  : m_count (0),
30  m_fd (fd),
31  m_file (file),
32  m_closing (0)
33 {
34 }
35 
37 {
38  m_file->DecFdCount ();
39  m_file->Unref ();
40 }
41 
42 void
44 {
45  m_count++;
46 }
47 bool
49 {
50  m_count--;
51  return ((0 == m_count)&&(m_closing));
52 }
53 bool
55 {
56  if (0 == m_count)
57  {
58  return true;
59  }
60  m_closing = true;
61  return false;
62 }
63 UnixFd*
65 {
66  IncUsage ();
67  return m_file;
68 }
69 UnixFd*
71 {
72  return m_file;
73 }
74 bool
76 {
77  return m_closing;
78 }
79 void
81 {
82  m_count = 0;
83 }
84 }