FILE_Addr.cpp

Go to the documentation of this file.
00001 // $Id: FILE_Addr.cpp 80826 2008-03-04 14:51:23Z wotte $
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, "$Id: FILE_Addr.cpp 80826 2008-03-04 14:51:23Z wotte $")
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_, MAXPATHLEN - 15) == -1)
00037         // -15 for ace-file-XXXXXX
00038         {
00039           ACE_ERROR ((LM_ERROR,
00040                       ACE_TEXT ("Temporary path too long, ")
00041                       ACE_TEXT ("defaulting to current directory\n")));
00042           this->filename_[0] = 0;
00043         }
00044 
00045       // Add the filename to the end
00046       ACE_OS::strcat (this->filename_, ACE_TEXT ("ace-fileXXXXXX"));
00047 
00048 #endif /* ACE_DEFAULT_TEMP_FILE */
00049 
00050       if (ACE_OS::mktemp (this->filename_) == 0)
00051         return -1;
00052       this->base_set (AF_FILE,
00053                       static_cast<int> (ACE_OS::strlen (this->filename_) + 1));
00054     }
00055   else
00056     {
00057       (void)ACE_OS::strsncpy (this->filename_, sa.filename_, sa.get_size ());
00058 
00059       this->base_set (sa.get_type (), sa.get_size ());
00060     }
00061   return 0;
00062 }
00063 
00064 // Copy constructor.
00065 
00066 ACE_FILE_Addr::ACE_FILE_Addr (const ACE_FILE_Addr &sa)
00067   : ACE_Addr (AF_FILE, sizeof this->filename_)
00068 {
00069   this->set (sa);
00070 }
00071 
00072 int
00073 ACE_FILE_Addr::set (const ACE_TCHAR *filename)
00074 {
00075   this->ACE_Addr::base_set (AF_FILE,
00076                             static_cast<int> (ACE_OS::strlen (filename) + 1));
00077   (void) ACE_OS::strsncpy (this->filename_,
00078                            filename,
00079                            sizeof this->filename_ / sizeof (ACE_TCHAR));
00080   return 0;
00081 }
00082 
00083 ACE_FILE_Addr &
00084 ACE_FILE_Addr::operator= (const ACE_FILE_Addr &sa)
00085 {
00086   if (this != &sa)
00087     this->set (sa);
00088   return *this;
00089 }
00090 
00091 // Create a ACE_Addr from a ACE_FILE pathname.
00092 
00093 ACE_FILE_Addr::ACE_FILE_Addr (const ACE_TCHAR *filename)
00094 {
00095   this->set (filename);
00096 }
00097 
00098 int
00099 ACE_FILE_Addr::addr_to_string (ACE_TCHAR *s, size_t len) const
00100 {
00101   ACE_OS::strsncpy (s, this->filename_, len);
00102   return 0;
00103 }
00104 
00105 // Return the address.
00106 
00107 void *
00108 ACE_FILE_Addr::get_addr (void) const
00109 {
00110   return (void *)&this->filename_;
00111 }
00112 
00113 void
00114 ACE_FILE_Addr::dump (void) const
00115 {
00116 #if defined (ACE_HAS_DUMP)
00117   ACE_TRACE ("ACE_FILE_Addr::dump");
00118 
00119   ACE_DEBUG ((LM_DEBUG, ACE_BEGIN_DUMP, this));
00120   ACE_DEBUG ((LM_DEBUG,  ACE_TEXT ("filename_ = %s"), this->filename_));
00121   ACE_DEBUG ((LM_DEBUG, ACE_END_DUMP));
00122 #endif /* ACE_HAS_DUMP */
00123 }
00124 ACE_END_VERSIONED_NAMESPACE_DECL

Generated on Tue Feb 2 17:18:39 2010 for ACE by  doxygen 1.4.7