FILE_Addr.cpp

Go to the documentation of this file.
00001 // FILE_Addr.cpp,v 4.34 2005/10/28 16:14:52 ossama Exp
00002 
00003 #include "ace/FILE_Addr.h"
00004 #include "ace/Lib_Find.h"
00005 #include "ace/Log_Msg.h"
00006 #include "ace/OS_NS_stdlib.h"
00007 #include "ace/OS_NS_string.h"
00008 #include "ace/os_include/sys/os_socket.h"
00009 
00010 #if !defined (__ACE_INLINE__)
00011 #include "ace/FILE_Addr.inl"
00012 #endif /* __ACE_INLINE__ */
00013 
00014 ACE_RCSID(ace, FILE_Addr, "FILE_Addr.cpp,v 4.34 2005/10/28 16:14:52 ossama Exp")
00015 
00016 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
00017 
00018 ACE_ALLOC_HOOK_DEFINE(ACE_FILE_Addr)
00019 
00020 ACE_FILE_Addr::ACE_FILE_Addr (void)
00021   : ACE_Addr (AF_FILE, sizeof this->filename_ / sizeof (ACE_TCHAR))
00022 {
00023   this->filename_[0] = '\0';
00024 }
00025 
00026 int
00027 ACE_FILE_Addr::set (const ACE_FILE_Addr &sa)
00028 {
00029   if (sa.get_type () == AF_ANY)
00030     {
00031 #if defined (ACE_DEFAULT_TEMP_FILE)
00032       // Create a temporary file.
00033       ACE_OS::strcpy (this->filename_,
00034                       ACE_DEFAULT_TEMP_FILE);
00035 #else /* ACE_DEFAULT_TEMP_FILE */
00036       if (ACE::get_temp_dir (this->filename_,
00037                                       MAXPATHLEN - 15) == -1)
00038         // -15 for ace-file-XXXXXX
00039         {
00040           ACE_ERROR ((LM_ERROR,
00041                       ACE_LIB_TEXT ("Temporary path too long, ")
00042                       ACE_LIB_TEXT ("defaulting to current directory\n")));
00043           this->filename_[0] = 0;
00044         }
00045 
00046       // Add the filename to the end
00047       ACE_OS::strcat (this->filename_, ACE_LIB_TEXT ("ace-fileXXXXXX"));
00048 
00049 #endif /* ACE_DEFAULT_TEMP_FILE */
00050 
00051       if (ACE_OS::mktemp (this->filename_) == 0)
00052         return -1;
00053       this->base_set (AF_FILE,
00054                       static_cast<int> (ACE_OS::strlen (this->filename_) + 1));
00055     }
00056   else
00057     {
00058       (void) ACE_OS::strsncpy (this->filename_,
00059                                sa.filename_,
00060                                sa.get_size ());
00061 
00062       this->base_set (sa.get_type (),
00063                       sa.get_size ());
00064     }
00065   return 0;
00066 }
00067 
00068 // Copy constructor.
00069 
00070 ACE_FILE_Addr::ACE_FILE_Addr (const ACE_FILE_Addr &sa)
00071   : ACE_Addr (AF_FILE, sizeof this->filename_)
00072 {
00073   this->set (sa);
00074 }
00075 
00076 int
00077 ACE_FILE_Addr::set (const ACE_TCHAR *filename)
00078 {
00079   this->ACE_Addr::base_set (AF_FILE,
00080                             static_cast<int> (ACE_OS::strlen (filename) + 1));
00081   (void) ACE_OS::strsncpy (this->filename_,
00082                            filename,
00083                            sizeof this->filename_ / sizeof (ACE_TCHAR));
00084   return 0;
00085 }
00086 
00087 ACE_FILE_Addr &
00088 ACE_FILE_Addr::operator= (const ACE_FILE_Addr &sa)
00089 {
00090   if (this != &sa)
00091     this->set (sa);
00092   return *this;
00093 }
00094 
00095 // Create a ACE_Addr from a ACE_FILE pathname.
00096 
00097 ACE_FILE_Addr::ACE_FILE_Addr (const ACE_TCHAR *filename)
00098 {
00099   this->set (filename);
00100 }
00101 
00102 int
00103 ACE_FILE_Addr::addr_to_string (ACE_TCHAR *s, size_t len) const
00104 {
00105   ACE_OS::strsncpy (s, this->filename_, len);
00106   return 0;
00107 }
00108 
00109 // Return the address.
00110 
00111 void *
00112 ACE_FILE_Addr::get_addr (void) const
00113 {
00114   return (void *) &this->filename_;
00115 }
00116 
00117 void
00118 ACE_FILE_Addr::dump (void) const
00119 {
00120 #if defined (ACE_HAS_DUMP)
00121   ACE_TRACE ("ACE_FILE_Addr::dump");
00122 
00123   ACE_DEBUG ((LM_DEBUG, ACE_BEGIN_DUMP, this));
00124   ACE_DEBUG ((LM_DEBUG,  ACE_LIB_TEXT ("filename_ = %s"), this->filename_));
00125   ACE_DEBUG ((LM_DEBUG, ACE_END_DUMP));
00126 #endif /* ACE_HAS_DUMP */
00127 }
00128 ACE_END_VERSIONED_NAMESPACE_DECL

Generated on Thu Nov 9 09:41:51 2006 for ACE by doxygen 1.3.6