Merge branch 'next' of git://gitorious.org/fg/simgear into next
This commit is contained in:
+7
-4
@@ -18,9 +18,10 @@ SET(CPACK_RESOURCE_FILE_README "${PROJECT_SOURCE_DIR}/README")
|
|||||||
set(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/CMakeModules;${CMAKE_MODULE_PATH}")
|
set(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/CMakeModules;${CMAKE_MODULE_PATH}")
|
||||||
|
|
||||||
option(SIMGEAR_SHARED "Set to ON to build SimGear as a shared library/framework" OFF)
|
option(SIMGEAR_SHARED "Set to ON to build SimGear as a shared library/framework" OFF)
|
||||||
option(SIMGEAR_HEADLESS "Set to ON to build SimGear with GUI/graphics support" OFF)
|
option(SIMGEAR_HEADLESS "Set to ON to build SimGear without GUI/graphics support" OFF)
|
||||||
option(JPEG_FACTORY "Enable JPEG-factory support" OFF)
|
option(JPEG_FACTORY "Enable JPEG-factory support" OFF)
|
||||||
option(ENABLE_LIBSVN "Set to ON to build SimGear with libsvnclient support" ON)
|
option(ENABLE_LIBSVN "Set to ON to build SimGear with libsvnclient support" ON)
|
||||||
|
option(ENABLE_RTI "Set to ON to build SimGear with RTI support" OFF)
|
||||||
|
|
||||||
set(MSVC_3RDPARTY_ROOT NOT_FOUND CACHE PATH "Location where the third-party dependencies are extracted")
|
set(MSVC_3RDPARTY_ROOT NOT_FOUND CACHE PATH "Location where the third-party dependencies are extracted")
|
||||||
|
|
||||||
@@ -53,7 +54,7 @@ set (BOOST_CXX_FLAGS "-DBOOST_MULTI_INDEX_DISABLE_SERIALIZATION -DBOOST_BIMAP_DI
|
|||||||
find_package(ZLIB REQUIRED)
|
find_package(ZLIB REQUIRED)
|
||||||
find_package(Threads REQUIRED)
|
find_package(Threads REQUIRED)
|
||||||
|
|
||||||
if (${SIMGEAR_HEADLESS})
|
if(SIMGEAR_HEADLESS)
|
||||||
message(STATUS "headlesss mode")
|
message(STATUS "headlesss mode")
|
||||||
set(NO_OPENSCENEGRAPH_INTERFACE 1)
|
set(NO_OPENSCENEGRAPH_INTERFACE 1)
|
||||||
else()
|
else()
|
||||||
@@ -61,13 +62,13 @@ else()
|
|||||||
find_package(OpenAL REQUIRED)
|
find_package(OpenAL REQUIRED)
|
||||||
find_package(ALUT REQUIRED)
|
find_package(ALUT REQUIRED)
|
||||||
find_package(OpenSceneGraph 2.8.1 REQUIRED osgText osgSim osgDB osgParticle osgUtil)
|
find_package(OpenSceneGraph 2.8.1 REQUIRED osgText osgSim osgDB osgParticle osgUtil)
|
||||||
endif()
|
endif(SIMGEAR_HEADLESS)
|
||||||
|
|
||||||
if(JPEG_FACTORY)
|
if(JPEG_FACTORY)
|
||||||
message(STATUS "JPEG-factory enabled")
|
message(STATUS "JPEG-factory enabled")
|
||||||
find_package(JPEG REQUIRED)
|
find_package(JPEG REQUIRED)
|
||||||
include_directories(${JPEG_INCLUDE_DIR})
|
include_directories(${JPEG_INCLUDE_DIR})
|
||||||
endif()
|
endif(JPEG_FACTORY)
|
||||||
|
|
||||||
if(ENABLE_LIBSVN)
|
if(ENABLE_LIBSVN)
|
||||||
find_package(SvnClient)
|
find_package(SvnClient)
|
||||||
@@ -86,8 +87,10 @@ check_include_file(sys/timeb.h HAVE_SYS_TIMEB_H)
|
|||||||
check_include_file(unistd.h HAVE_UNISTD_H)
|
check_include_file(unistd.h HAVE_UNISTD_H)
|
||||||
check_include_file(windows.h HAVE_WINDOWS_H)
|
check_include_file(windows.h HAVE_WINDOWS_H)
|
||||||
|
|
||||||
|
if(ENABLE_RTI)
|
||||||
# See if we have any rti library variant installed
|
# See if we have any rti library variant installed
|
||||||
find_package(RTI)
|
find_package(RTI)
|
||||||
|
endif(ENABLE_RTI)
|
||||||
|
|
||||||
check_function_exists(gettimeofday HAVE_GETTIMEOFDAY)
|
check_function_exists(gettimeofday HAVE_GETTIMEOFDAY)
|
||||||
check_function_exists(ftime HAVE_FTIME)
|
check_function_exists(ftime HAVE_FTIME)
|
||||||
|
|||||||
@@ -100,7 +100,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
activeRequest = r;
|
activeRequest = r;
|
||||||
state = STATE_IDLE;
|
state = STATE_SENT_REQUEST;
|
||||||
bodyTransferSize = -1;
|
bodyTransferSize = -1;
|
||||||
chunkedTransfer = false;
|
chunkedTransfer = false;
|
||||||
setTerminator("\r\n");
|
setTerminator("\r\n");
|
||||||
@@ -146,7 +146,7 @@ public:
|
|||||||
virtual void foundTerminator(void)
|
virtual void foundTerminator(void)
|
||||||
{
|
{
|
||||||
switch (state) {
|
switch (state) {
|
||||||
case STATE_IDLE:
|
case STATE_SENT_REQUEST:
|
||||||
activeRequest->responseStart(buffer);
|
activeRequest->responseStart(buffer);
|
||||||
state = STATE_GETTING_HEADERS;
|
state = STATE_GETTING_HEADERS;
|
||||||
buffer.clear();
|
buffer.clear();
|
||||||
@@ -170,6 +170,7 @@ public:
|
|||||||
state = STATE_GETTING_CHUNKED;
|
state = STATE_GETTING_CHUNKED;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|
||||||
case STATE_GETTING_TRAILER:
|
case STATE_GETTING_TRAILER:
|
||||||
processTrailer();
|
processTrailer();
|
||||||
buffer.clear();
|
buffer.clear();
|
||||||
@@ -354,6 +355,7 @@ private:
|
|||||||
|
|
||||||
enum ConnectionState {
|
enum ConnectionState {
|
||||||
STATE_IDLE = 0,
|
STATE_IDLE = 0,
|
||||||
|
STATE_SENT_REQUEST,
|
||||||
STATE_GETTING_HEADERS,
|
STATE_GETTING_HEADERS,
|
||||||
STATE_GETTING_BODY,
|
STATE_GETTING_BODY,
|
||||||
STATE_GETTING_CHUNKED,
|
STATE_GETTING_CHUNKED,
|
||||||
|
|||||||
+82
-43
@@ -25,8 +25,7 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <simgear/compiler.h>
|
#include <simgear/compiler.h>
|
||||||
|
#include "raw_socket.hxx"
|
||||||
#include "sg_socket.hxx"
|
|
||||||
|
|
||||||
#if defined(_WIN32) && !defined(__CYGWIN__)
|
#if defined(_WIN32) && !defined(__CYGWIN__)
|
||||||
# define WINSOCK // use winsock convetions, otherwise standard POSIX
|
# define WINSOCK // use winsock convetions, otherwise standard POSIX
|
||||||
@@ -37,9 +36,11 @@
|
|||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
#include <cstdio> // for snprintf
|
#include <cstdio> // for snprintf
|
||||||
|
#include <errno.h>
|
||||||
|
|
||||||
#if defined(WINSOCK)
|
#if defined(WINSOCK)
|
||||||
# include <winsock.h>
|
# include <winsock2.h>
|
||||||
|
# include <ws2tcpip.h>
|
||||||
# include <stdarg.h>
|
# include <stdarg.h>
|
||||||
#else
|
#else
|
||||||
# include <sys/types.h>
|
# include <sys/types.h>
|
||||||
@@ -67,44 +68,73 @@ IPAddress::IPAddress ( const char* host, int port )
|
|||||||
set ( host, port ) ;
|
set ( host, port ) ;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
IPAddress::IPAddress( const IPAddress& other ) :
|
||||||
|
addr(NULL)
|
||||||
|
{
|
||||||
|
if (other.addr) {
|
||||||
|
addr = (struct sockaddr_in*) malloc(sizeof(struct sockaddr_in));
|
||||||
|
memcpy(addr, other.addr, sizeof(struct sockaddr_in));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const IPAddress& IPAddress::operator=(const IPAddress& other)
|
||||||
|
{
|
||||||
|
if (addr) {
|
||||||
|
free(addr);
|
||||||
|
addr = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (other.addr) {
|
||||||
|
addr = (struct sockaddr_in*) malloc(sizeof(struct sockaddr_in));
|
||||||
|
memcpy(addr, other.addr, sizeof(struct sockaddr_in));
|
||||||
|
}
|
||||||
|
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
void IPAddress::set ( const char* host, int port )
|
void IPAddress::set ( const char* host, int port )
|
||||||
{
|
{
|
||||||
memset(this, 0, sizeof(IPAddress));
|
addr = (struct sockaddr_in*) malloc(sizeof(struct sockaddr_in));
|
||||||
|
memset(addr, 0, sizeof(struct sockaddr_in));
|
||||||
|
|
||||||
sin_family = AF_INET ;
|
addr->sin_family = AF_INET ;
|
||||||
sin_port = htons (port);
|
addr->sin_port = htons (port);
|
||||||
|
|
||||||
/* Convert a string specifying a host name or one of a few symbolic
|
/* Convert a string specifying a host name or one of a few symbolic
|
||||||
** names to a numeric IP address. This usually calls gethostbyname()
|
** names to a numeric IP address. This usually calls getaddrinfo()
|
||||||
** to do the work; the names "" and "<broadcast>" are special.
|
** to do the work; the names "" and "<broadcast>" are special.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if (!host || host[0] == '\0') {
|
if (!host || host[0] == '\0') {
|
||||||
sin_addr = INADDR_ANY;
|
addr->sin_addr.s_addr = INADDR_ANY;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (strcmp(host, "<broadcast>") == 0) {
|
if (strcmp(host, "<broadcast>") == 0) {
|
||||||
sin_addr = INADDR_BROADCAST;
|
addr->sin_addr.s_addr = INADDR_BROADCAST;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
sin_addr = inet_addr ( host ) ;
|
struct addrinfo* result = NULL;
|
||||||
if (sin_addr != INADDR_NONE) {
|
int err = getaddrinfo(host, NULL, NULL /* no hints */, &result);
|
||||||
return;
|
if (err) {
|
||||||
|
SG_LOG(SG_IO, SG_WARN, "getaddrinfo failed for '" << host << "' : " << gai_strerror(err));
|
||||||
|
} else if (result->ai_addrlen != getAddrLen()) {
|
||||||
|
SG_LOG(SG_IO, SG_ALERT, "mismatch in socket address sizes");
|
||||||
|
} else {
|
||||||
|
memcpy(addr, result->ai_addr, result->ai_addrlen);
|
||||||
}
|
}
|
||||||
// finally, try gethostbyname
|
|
||||||
struct hostent *hp = gethostbyname ( host ) ;
|
freeaddrinfo(result);
|
||||||
if (!hp) {
|
addr->sin_port = htons (port); // fix up port after getaddrinfo
|
||||||
SG_LOG(SG_IO, SG_WARN, "gethostbyname failed for " << host);
|
|
||||||
sin_addr = INADDR_ANY ;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
memcpy ( (char *) &sin_addr, hp->h_addr, hp->h_length ) ;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
IPAddress::~IPAddress()
|
||||||
|
{
|
||||||
|
if (addr) {
|
||||||
|
free (addr);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* Create a string object representing an IP address.
|
/* Create a string object representing an IP address.
|
||||||
This is always a string of the form 'dd.dd.dd.dd' (with variable
|
This is always a string of the form 'dd.dd.dd.dd' (with variable
|
||||||
@@ -112,31 +142,27 @@ void IPAddress::set ( const char* host, int port )
|
|||||||
|
|
||||||
const char* IPAddress::getHost () const
|
const char* IPAddress::getHost () const
|
||||||
{
|
{
|
||||||
#if 0
|
|
||||||
const char* buf = inet_ntoa ( sin_addr ) ;
|
|
||||||
#else
|
|
||||||
static char buf [32];
|
static char buf [32];
|
||||||
long x = ntohl(sin_addr);
|
long x = ntohl(addr->sin_addr.s_addr);
|
||||||
sprintf(buf, "%d.%d.%d.%d",
|
sprintf(buf, "%d.%d.%d.%d",
|
||||||
(int) (x>>24) & 0xff, (int) (x>>16) & 0xff,
|
(int) (x>>24) & 0xff, (int) (x>>16) & 0xff,
|
||||||
(int) (x>> 8) & 0xff, (int) (x>> 0) & 0xff );
|
(int) (x>> 8) & 0xff, (int) (x>> 0) & 0xff );
|
||||||
#endif
|
|
||||||
return buf;
|
return buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned int IPAddress::getIP () const
|
unsigned int IPAddress::getIP () const
|
||||||
{
|
{
|
||||||
return sin_addr;
|
return addr->sin_addr.s_addr;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned int IPAddress::getPort() const
|
unsigned int IPAddress::getPort() const
|
||||||
{
|
{
|
||||||
return ntohs(sin_port);
|
return ntohs(addr->sin_port);
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned int IPAddress::getFamily () const
|
unsigned int IPAddress::getFamily () const
|
||||||
{
|
{
|
||||||
return sin_family;
|
return addr->sin_family;
|
||||||
}
|
}
|
||||||
|
|
||||||
const char* IPAddress::getLocalHost ()
|
const char* IPAddress::getLocalHost ()
|
||||||
@@ -163,9 +189,18 @@ const char* IPAddress::getLocalHost ()
|
|||||||
|
|
||||||
bool IPAddress::getBroadcast () const
|
bool IPAddress::getBroadcast () const
|
||||||
{
|
{
|
||||||
return sin_addr == INADDR_BROADCAST;
|
return (addr->sin_addr.s_addr == INADDR_BROADCAST);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
unsigned int IPAddress::getAddrLen() const
|
||||||
|
{
|
||||||
|
return sizeof(struct sockaddr_in);
|
||||||
|
}
|
||||||
|
|
||||||
|
struct sockaddr* IPAddress::getAddr() const
|
||||||
|
{
|
||||||
|
return (struct sockaddr*) addr;
|
||||||
|
}
|
||||||
|
|
||||||
Socket::Socket ()
|
Socket::Socket ()
|
||||||
{
|
{
|
||||||
@@ -262,8 +297,8 @@ int Socket::bind ( const char* host, int port )
|
|||||||
IPAddress addr ( host, port ) ;
|
IPAddress addr ( host, port ) ;
|
||||||
|
|
||||||
#if !defined(WINSOCK)
|
#if !defined(WINSOCK)
|
||||||
if( (result = ::bind(handle,(const sockaddr*)&addr,sizeof(IPAddress))) < 0 ) {
|
if( (result = ::bind(handle, addr.getAddr(), addr.getAddrLen() ) ) < 0 ) {
|
||||||
SG_LOG(SG_IO, SG_ALERT, "bind(" << host << ":" << port << ") failed. Errno " << errno << " (" << strerror(errno) << ")");
|
SG_LOG(SG_IO, SG_ALERT, "bind(" << addr.getHost() << ":" << addr.getPort() << ") failed. Errno " << errno << " (" << strerror(errno) << ")");
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@@ -294,7 +329,7 @@ int Socket::bind ( const char* host, int port )
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
#if defined(WINSOCK)
|
#if defined(WINSOCK)
|
||||||
else if( (result = ::bind(handle,(const sockaddr*)&addr,sizeof(IPAddress))) < 0 ) {
|
else if( (result = ::bind(handle,addr.getAddr(), addr.getAddrLen())) < 0 ) {
|
||||||
SG_LOG(SG_IO, SG_ALERT, "bind(" << host << ":" << port << ") failed. Errno " << errno << " (" << strerror(errno) << ")");
|
SG_LOG(SG_IO, SG_ALERT, "bind(" << host << ":" << port << ") failed. Errno " << errno << " (" << strerror(errno) << ")");
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@@ -321,20 +356,26 @@ int Socket::accept ( IPAddress* addr )
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
socklen_t addr_len = (socklen_t) sizeof(IPAddress) ;
|
socklen_t addr_len = addr->getAddrLen(); ;
|
||||||
return ::accept(handle,(sockaddr*)addr,&addr_len);
|
return ::accept(handle, addr->getAddr(), &addr_len);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int Socket::connect ( const char* host, int port )
|
int Socket::connect ( const char* host, int port )
|
||||||
{
|
{
|
||||||
assert ( handle != -1 ) ;
|
|
||||||
IPAddress addr ( host, port ) ;
|
IPAddress addr ( host, port ) ;
|
||||||
if ( addr.getBroadcast() ) {
|
return connect ( &addr );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int Socket::connect ( IPAddress* addr )
|
||||||
|
{
|
||||||
|
assert ( handle != -1 ) ;
|
||||||
|
if ( addr->getBroadcast() ) {
|
||||||
setBroadcast( true );
|
setBroadcast( true );
|
||||||
}
|
}
|
||||||
return ::connect(handle,(const sockaddr*)&addr,sizeof(IPAddress));
|
return ::connect(handle, addr->getAddr(), addr->getAddrLen() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -350,7 +391,7 @@ int Socket::sendto ( const void * buffer, int size,
|
|||||||
{
|
{
|
||||||
assert ( handle != -1 ) ;
|
assert ( handle != -1 ) ;
|
||||||
return ::sendto(handle,(const char*)buffer,size,flags,
|
return ::sendto(handle,(const char*)buffer,size,flags,
|
||||||
(const sockaddr*)to,sizeof(IPAddress));
|
(const sockaddr*) to->getAddr(), to->getAddrLen());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -365,8 +406,8 @@ int Socket::recvfrom ( void * buffer, int size,
|
|||||||
int flags, IPAddress* from )
|
int flags, IPAddress* from )
|
||||||
{
|
{
|
||||||
assert ( handle != -1 ) ;
|
assert ( handle != -1 ) ;
|
||||||
socklen_t fromlen = (socklen_t) sizeof(IPAddress) ;
|
socklen_t fromlen = (socklen_t) from->getAddrLen() ;
|
||||||
return ::recvfrom(handle,(char*)buffer,size,flags,(sockaddr*)from,&fromlen);
|
return ::recvfrom(handle,(char*)buffer,size,flags, from->getAddr(),&fromlen);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -526,8 +567,6 @@ static void netExit ( void )
|
|||||||
|
|
||||||
int Socket::initSockets()
|
int Socket::initSockets()
|
||||||
{
|
{
|
||||||
assert ( sizeof(sockaddr_in) == sizeof(IPAddress) ) ;
|
|
||||||
|
|
||||||
#if defined(WINSOCK)
|
#if defined(WINSOCK)
|
||||||
/* Start up the windows networking */
|
/* Start up the windows networking */
|
||||||
WORD version_wanted = MAKEWORD(1,1);
|
WORD version_wanted = MAKEWORD(1,1);
|
||||||
|
|||||||
+17
-19
@@ -23,12 +23,15 @@
|
|||||||
#ifndef SG_IO_SOCKET_HXX
|
#ifndef SG_IO_SOCKET_HXX
|
||||||
#define SG_IO_SOCKET_HXX
|
#define SG_IO_SOCKET_HXX
|
||||||
|
|
||||||
#include <errno.h>
|
//#include <errno.h>
|
||||||
|
|
||||||
#if defined(__APPLE__) || defined(__FreeBSD__)
|
//#if defined(__APPLE__) || defined(__FreeBSD__)
|
||||||
# include <netinet/in.h>
|
//# include <netinet/in.h>
|
||||||
#endif
|
//#endif
|
||||||
|
|
||||||
|
struct sockaddr_in;
|
||||||
|
struct sockaddr;
|
||||||
|
|
||||||
namespace simgear
|
namespace simgear
|
||||||
{
|
{
|
||||||
|
|
||||||
@@ -37,23 +40,14 @@ namespace simgear
|
|||||||
*/
|
*/
|
||||||
class IPAddress
|
class IPAddress
|
||||||
{
|
{
|
||||||
/* DANGER!!! This MUST match 'struct sockaddr_in' exactly! */
|
struct sockaddr_in* addr;
|
||||||
#if defined(__APPLE__) || defined(__FreeBSD__)
|
|
||||||
__uint8_t sin_len;
|
|
||||||
__uint8_t sin_family;
|
|
||||||
in_port_t sin_port;
|
|
||||||
in_addr_t sin_addr;
|
|
||||||
char sin_zero[8];
|
|
||||||
#else
|
|
||||||
short sin_family ;
|
|
||||||
unsigned short sin_port ;
|
|
||||||
unsigned int sin_addr ;
|
|
||||||
char sin_zero [ 8 ] ;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
IPAddress () {}
|
IPAddress () : addr(0) {}
|
||||||
IPAddress ( const char* host, int port ) ;
|
IPAddress ( const char* host, int port ) ;
|
||||||
|
~IPAddress();
|
||||||
|
|
||||||
|
IPAddress( const IPAddress& other );
|
||||||
|
const IPAddress& operator=(const IPAddress& other);
|
||||||
|
|
||||||
void set ( const char* host, int port ) ;
|
void set ( const char* host, int port ) ;
|
||||||
const char* getHost () const ;
|
const char* getHost () const ;
|
||||||
@@ -63,6 +57,9 @@ public:
|
|||||||
static const char* getLocalHost () ;
|
static const char* getLocalHost () ;
|
||||||
|
|
||||||
bool getBroadcast () const ;
|
bool getBroadcast () const ;
|
||||||
|
|
||||||
|
unsigned int getAddrLen() const;
|
||||||
|
sockaddr* getAddr() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -89,6 +86,7 @@ public:
|
|||||||
int listen ( int backlog ) ;
|
int listen ( int backlog ) ;
|
||||||
int accept ( IPAddress* addr ) ;
|
int accept ( IPAddress* addr ) ;
|
||||||
int connect ( const char* host, int port ) ;
|
int connect ( const char* host, int port ) ;
|
||||||
|
int connect ( IPAddress* addr ) ;
|
||||||
int send ( const void * buffer, int size, int flags = 0 ) ;
|
int send ( const void * buffer, int size, int flags = 0 ) ;
|
||||||
int sendto ( const void * buffer, int size, int flags, const IPAddress* to ) ;
|
int sendto ( const void * buffer, int size, int flags, const IPAddress* to ) ;
|
||||||
int recv ( void * buffer, int size, int flags = 0 ) ;
|
int recv ( void * buffer, int size, int flags = 0 ) ;
|
||||||
|
|||||||
@@ -34,6 +34,7 @@
|
|||||||
#include <memory>
|
#include <memory>
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
|
#include <errno.h>
|
||||||
|
|
||||||
#include <simgear/debug/logstream.hxx>
|
#include <simgear/debug/logstream.hxx>
|
||||||
|
|
||||||
|
|||||||
+104
-70
@@ -126,21 +126,27 @@ public:
|
|||||||
const char * propname );
|
const char * propname );
|
||||||
virtual void setRightProperty( SGPropertyNode *prop_root,
|
virtual void setRightProperty( SGPropertyNode *prop_root,
|
||||||
const char * propname );
|
const char * propname );
|
||||||
|
virtual void setPrecisionProperty( SGPropertyNode *prop_root,
|
||||||
|
const char * propname );
|
||||||
// will make a local copy
|
// will make a local copy
|
||||||
virtual void setLeftValue (const SGPropertyNode * value);
|
virtual void setLeftValue (const SGPropertyNode * value);
|
||||||
virtual void setRightValue (const SGPropertyNode * value);
|
virtual void setRightValue (const SGPropertyNode * value);
|
||||||
|
virtual void setPrecisionValue (const SGPropertyNode * value);
|
||||||
|
|
||||||
void setLeftDExpression(SGExpressiond* dexp);
|
void setLeftDExpression(SGExpressiond* dexp);
|
||||||
void setRightDExpression(SGExpressiond* dexp);
|
void setRightDExpression(SGExpressiond* dexp);
|
||||||
|
void setPrecisionDExpression(SGExpressiond* dexp);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Type _type;
|
Type _type;
|
||||||
bool _reverse;
|
bool _reverse;
|
||||||
SGPropertyNode_ptr _left_property;
|
SGPropertyNode_ptr _left_property;
|
||||||
SGPropertyNode_ptr _right_property;
|
SGPropertyNode_ptr _right_property;
|
||||||
|
SGPropertyNode_ptr _precision_property;
|
||||||
|
|
||||||
SGSharedPtr<SGExpressiond> _left_dexp;
|
SGSharedPtr<SGExpressiond> _left_dexp;
|
||||||
SGSharedPtr<SGExpressiond> _right_dexp;
|
SGSharedPtr<SGExpressiond> _right_dexp;
|
||||||
|
SGSharedPtr<SGExpressiond> _precision_dexp;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -261,8 +267,20 @@ SGOrCondition::addCondition (SGCondition * condition)
|
|||||||
// Implementation of SGComparisonCondition.
|
// Implementation of SGComparisonCondition.
|
||||||
////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
static int doComp( T v1, T v2, T e )
|
||||||
|
{
|
||||||
|
T d = v1 - v2;
|
||||||
|
if( d < -e )
|
||||||
|
return SGComparisonCondition::LESS_THAN;
|
||||||
|
else if( d > e )
|
||||||
|
return SGComparisonCondition::GREATER_THAN;
|
||||||
|
else
|
||||||
|
return SGComparisonCondition::EQUALS;
|
||||||
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
doComparison (const SGPropertyNode * left, const SGPropertyNode *right)
|
doComparison (const SGPropertyNode * left, const SGPropertyNode * right, const SGPropertyNode * precision )
|
||||||
{
|
{
|
||||||
using namespace simgear;
|
using namespace simgear;
|
||||||
switch (left->getType()) {
|
switch (left->getType()) {
|
||||||
@@ -277,55 +295,28 @@ doComparison (const SGPropertyNode * left, const SGPropertyNode *right)
|
|||||||
return SGComparisonCondition::EQUALS;
|
return SGComparisonCondition::EQUALS;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case props::INT: {
|
case props::INT:
|
||||||
int v1 = left->getIntValue();
|
return doComp<int>(left->getIntValue(), right->getIntValue(),
|
||||||
int v2 = right->getIntValue();
|
precision ? abs(precision->getIntValue()/2) : 0 );
|
||||||
if (v1 < v2)
|
|
||||||
return SGComparisonCondition::LESS_THAN;
|
case props::LONG:
|
||||||
else if (v1 > v2)
|
return doComp<long>(left->getLongValue(), right->getLongValue(),
|
||||||
return SGComparisonCondition::GREATER_THAN;
|
precision ? abs(precision->getLongValue()/2L) : 0L );
|
||||||
else
|
|
||||||
return SGComparisonCondition::EQUALS;
|
case props::FLOAT:
|
||||||
break;
|
return doComp<float>(left->getFloatValue(), right->getFloatValue(),
|
||||||
}
|
precision ? fabs(precision->getFloatValue()/2.0f) : 0.0f );
|
||||||
case props::LONG: {
|
|
||||||
long v1 = left->getLongValue();
|
case props::DOUBLE:
|
||||||
long v2 = right->getLongValue();
|
return doComp<double>(left->getDoubleValue(), right->getDoubleValue(),
|
||||||
if (v1 < v2)
|
precision ? fabs(precision->getDoubleValue()/2.0) : 0.0 );
|
||||||
return SGComparisonCondition::LESS_THAN;
|
|
||||||
else if (v1 > v2)
|
|
||||||
return SGComparisonCondition::GREATER_THAN;
|
|
||||||
else
|
|
||||||
return SGComparisonCondition::EQUALS;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case props::FLOAT: {
|
|
||||||
float v1 = left->getFloatValue();
|
|
||||||
float v2 = right->getFloatValue();
|
|
||||||
if (v1 < v2)
|
|
||||||
return SGComparisonCondition::LESS_THAN;
|
|
||||||
else if (v1 > v2)
|
|
||||||
return SGComparisonCondition::GREATER_THAN;
|
|
||||||
else
|
|
||||||
return SGComparisonCondition::EQUALS;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case props::DOUBLE: {
|
|
||||||
double v1 = left->getDoubleValue();
|
|
||||||
double v2 = right->getDoubleValue();
|
|
||||||
if (v1 < v2)
|
|
||||||
return SGComparisonCondition::LESS_THAN;
|
|
||||||
else if (v1 > v2)
|
|
||||||
return SGComparisonCondition::GREATER_THAN;
|
|
||||||
else
|
|
||||||
return SGComparisonCondition::EQUALS;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case props::STRING:
|
case props::STRING:
|
||||||
case props::NONE:
|
case props::NONE:
|
||||||
case props::UNSPECIFIED: {
|
case props::UNSPECIFIED: {
|
||||||
string v1 = left->getStringValue();
|
size_t l = precision ? precision->getLongValue() : string::npos;
|
||||||
string v2 = right->getStringValue();
|
string v1 = string(left->getStringValue()).substr(0,l);
|
||||||
|
string v2 = string(right->getStringValue()).substr(0,l);
|
||||||
if (v1 < v2)
|
if (v1 < v2)
|
||||||
return SGComparisonCondition::LESS_THAN;
|
return SGComparisonCondition::LESS_THAN;
|
||||||
else if (v1 > v2)
|
else if (v1 > v2)
|
||||||
@@ -367,8 +358,12 @@ SGComparisonCondition::test () const
|
|||||||
if (_right_dexp) {
|
if (_right_dexp) {
|
||||||
_right_property->setDoubleValue(_right_dexp->getValue(NULL));
|
_right_property->setDoubleValue(_right_dexp->getValue(NULL));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (_precision_dexp) {
|
||||||
|
_precision_property->setDoubleValue(_precision_dexp->getValue(NULL));
|
||||||
|
}
|
||||||
|
|
||||||
int cmp = doComparison(_left_property, _right_property);
|
int cmp = doComparison(_left_property, _right_property, _precision_property );
|
||||||
if (!_reverse)
|
if (!_reverse)
|
||||||
return (cmp == _type);
|
return (cmp == _type);
|
||||||
else
|
else
|
||||||
@@ -389,12 +384,24 @@ SGComparisonCondition::setRightProperty( SGPropertyNode *prop_root,
|
|||||||
_right_property = prop_root->getNode(propname, true);
|
_right_property = prop_root->getNode(propname, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
SGComparisonCondition::setPrecisionProperty( SGPropertyNode *prop_root,
|
||||||
|
const char * propname )
|
||||||
|
{
|
||||||
|
_precision_property = prop_root->getNode(propname, true);
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
SGComparisonCondition::setLeftValue (const SGPropertyNode *node)
|
SGComparisonCondition::setLeftValue (const SGPropertyNode *node)
|
||||||
{
|
{
|
||||||
_left_property = new SGPropertyNode(*node);
|
_left_property = new SGPropertyNode(*node);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
SGComparisonCondition::setPrecisionValue (const SGPropertyNode *node)
|
||||||
|
{
|
||||||
|
_precision_property = new SGPropertyNode(*node);
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
SGComparisonCondition::setRightValue (const SGPropertyNode *node)
|
SGComparisonCondition::setRightValue (const SGPropertyNode *node)
|
||||||
@@ -414,6 +421,13 @@ SGComparisonCondition::setRightDExpression(SGExpressiond* dexp)
|
|||||||
{
|
{
|
||||||
_right_property = new SGPropertyNode();
|
_right_property = new SGPropertyNode();
|
||||||
_right_dexp = dexp;
|
_right_dexp = dexp;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
SGComparisonCondition::setPrecisionDExpression(SGExpressiond* dexp)
|
||||||
|
{
|
||||||
|
_precision_property = new SGPropertyNode();
|
||||||
|
_precision_dexp = dexp;
|
||||||
}
|
}
|
||||||
////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////
|
||||||
// Read a condition and use it if necessary.
|
// Read a condition and use it if necessary.
|
||||||
@@ -479,34 +493,54 @@ readComparison( SGPropertyNode *prop_root,
|
|||||||
bool reverse)
|
bool reverse)
|
||||||
{
|
{
|
||||||
SGComparisonCondition * condition = new SGComparisonCondition(type, reverse);
|
SGComparisonCondition * condition = new SGComparisonCondition(type, reverse);
|
||||||
if (node->nChildren() != 2) {
|
if (node->nChildren() < 2 || node->nChildren() > 3 ) {
|
||||||
throw sg_exception("condition: comparison without two children");
|
throw sg_exception("condition: comparison without two or three children");
|
||||||
}
|
}
|
||||||
|
|
||||||
const SGPropertyNode* left = node->getChild(0),
|
const SGPropertyNode* left = node->getChild(0),
|
||||||
*right = node->getChild(1);
|
*right = node->getChild(1);
|
||||||
string leftName(left->getName());
|
|
||||||
if (leftName == "property") {
|
{
|
||||||
condition->setLeftProperty(prop_root, left->getStringValue());
|
string leftName(left->getName());
|
||||||
} else if (leftName == "value") {
|
if (leftName == "property") {
|
||||||
condition->setLeftValue(left);
|
condition->setLeftProperty(prop_root, left->getStringValue());
|
||||||
} else if (leftName == "expression") {
|
} else if (leftName == "value") {
|
||||||
SGExpressiond* exp = SGReadDoubleExpression(prop_root, left->getChild(0));
|
condition->setLeftValue(left);
|
||||||
condition->setLeftDExpression(exp);
|
} else if (leftName == "expression") {
|
||||||
} else {
|
SGExpressiond* exp = SGReadDoubleExpression(prop_root, left->getChild(0));
|
||||||
throw sg_exception("Unknown condition comparison left child:" + leftName);
|
condition->setLeftDExpression(exp);
|
||||||
|
} else {
|
||||||
|
throw sg_exception("Unknown condition comparison left child:" + leftName);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
string rightName(right->getName());
|
{
|
||||||
if (rightName == "property") {
|
string rightName(right->getName());
|
||||||
condition->setRightProperty(prop_root, right->getStringValue());
|
if (rightName == "property") {
|
||||||
} else if (rightName == "value") {
|
condition->setRightProperty(prop_root, right->getStringValue());
|
||||||
condition->setRightValue(right);
|
} else if (rightName == "value") {
|
||||||
} else if (rightName == "expression") {
|
condition->setRightValue(right);
|
||||||
SGExpressiond* exp = SGReadDoubleExpression(prop_root, right->getChild(0));
|
} else if (rightName == "expression") {
|
||||||
condition->setRightDExpression(exp);
|
SGExpressiond* exp = SGReadDoubleExpression(prop_root, right->getChild(0));
|
||||||
} else {
|
condition->setRightDExpression(exp);
|
||||||
throw sg_exception("Unknown condition comparison right child:" + rightName);
|
} else {
|
||||||
|
throw sg_exception("Unknown condition comparison right child:" + rightName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if( node->nChildren() == 3 ) {
|
||||||
|
const SGPropertyNode *n = node->getChild(2);
|
||||||
|
string name(n->getName());
|
||||||
|
if (name == "precision-property") {
|
||||||
|
condition->setPrecisionProperty(prop_root, n->getStringValue());
|
||||||
|
} else if (name == "precision-value") {
|
||||||
|
condition->setPrecisionValue(n);
|
||||||
|
} else if (name == "precision-expression") {
|
||||||
|
SGExpressiond* exp = SGReadDoubleExpression(prop_root, n->getChild(0));
|
||||||
|
condition->setPrecisionDExpression(exp);
|
||||||
|
} else {
|
||||||
|
throw sg_exception("Unknown condition comparison precision child:" + name );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return condition;
|
return condition;
|
||||||
|
|||||||
Reference in New Issue
Block a user