Urbi SDK Remote for C++  2.7.5
uabstractclient.hxx
Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2004-2011, Gostai S.A.S.
00003  *
00004  * This software is provided "as is" without warranty of any kind,
00005  * either expressed or implied, including but not limited to the
00006  * implied warranties of fitness for a particular purpose.
00007  *
00008  * See the LICENSE file for more information.
00009  */
00010 
00011 #ifndef URBI_UABSTRACTCLIENT_HXX
00012 # define URBI_UABSTRACTCLIENT_HXX
00013 
00014 # include <libport/debug.hh>
00015 # include <libport/escape.hh>
00016 
00017 namespace urbi
00018 {
00019 
00020   /*----------------.
00021   | UCallbackInfo.  |
00022   `----------------*/
00023 
00024   inline
00025   UCallbackInfo::UCallbackInfo(UCallbackWrapper &w)
00026     : callback(w)
00027   {}
00028 
00029   inline
00030   bool
00031   UCallbackInfo::operator==(UCallbackID id) const
00032   {
00033     return this->id == id;
00034   }
00035 
00036   /*------------------.
00037   | UAbstractClient.  |
00038   `------------------*/
00039 
00040   // This constant is declared as an inlined function instead of a
00041   // simple value because of Windows.  Indeed, libuco uses the
00042   // default_host value at various places, but it does not include
00043   // UAbstractClient.o.  So in the end, our libraries depend on values
00044   // that will be provided by those who link against these libraries.
00045   // This is not portable.
00046   //
00047   // So use an inline function.  This probably means there are several
00048   // instances of this value, one per library.  But who would compare
00049   // the pointers instead of the values?
00050   inline
00051   const char*
00052   UAbstractClient::default_host()
00053   {
00054     // When using Boost.Asio, "localhost" on OS X is IPv6, and nothing
00055     // works as expected.  Make sure we run in IPv4.
00056     // FIXME: Find out why we run in IPv6 by default.
00057     return "127.0.0.1";
00058   }
00059 
00060   inline
00061   bool
00062   UAbstractClient::init() const
00063   {
00064     return init_;
00065   }
00066 
00067   inline
00068   UAbstractClient::error_type
00069   UAbstractClient::effective_send(const void* buffer, size_t size)
00070   {
00071     GD_CATEGORY(Urbi.Client.Abstract);
00072     GD_FINFO_DUMP("Sending: \"%s\"",
00073                   libport::escape(std::string(static_cast<const char*>(buffer),
00074                                               size)));
00075     return effectiveSend(buffer, size);
00076   }
00077 
00078   inline
00079   UAbstractClient::error_type
00080   UAbstractClient::effective_send(const std::string& s)
00081   {
00082     return effective_send(s.c_str(), s.size());
00083   }
00084 
00085   inline
00086   UAbstractClient::error_type
00087   UAbstractClient::effective_send(const char* cp)
00088   {
00089     return effective_send(cp, strlen(cp));
00090   }
00091 
00092   inline
00093   UAbstractClient::error_type
00094   UAbstractClient::error() const
00095   {
00096     return rc;
00097   }
00098 
00099   inline
00100   const std::string&
00101   UAbstractClient::getServerName() const
00102   {
00103     return host_;
00104   }
00105 
00107   inline
00108   unsigned
00109   UAbstractClient::getServerPort() const
00110   {
00111     return port_;
00112   }
00113 
00114   inline
00115   int
00116   UAbstractClient::kernelMajor() const
00117   {
00118     waitForKernelVersion();
00119     libport::BlockLock bl(sendBufferLock);
00120     return kernelMajor_;
00121   }
00122 
00123   inline
00124   int
00125   UAbstractClient::kernelMinor() const
00126   {
00127     waitForKernelVersion();
00128     libport::BlockLock bl(sendBufferLock);
00129     return kernelMinor_;
00130   }
00131 
00132   inline
00133   const std::string&
00134   UAbstractClient::kernelVersion() const
00135   {
00136     waitForKernelVersion();
00137     libport::BlockLock bl(sendBufferLock);
00138     return kernelVersion_;
00139   }
00140 
00141   inline
00142   std::ostream&
00143   UAbstractClient::stream_get()
00144   {
00145     return *stream_;
00146   }
00147 
00148   inline
00149   UAbstractClient::error_type
00150   UAbstractClient::onClose()
00151   {
00152     closed_ = true;
00153     return 0;
00154   };
00155 
00156 } // namespace urbi
00157 
00158 #endif // URBI_UABSTRACTCLIENT_HXX