To fix ANA's compilation in MSVC,

...removed the inclusion of cstdint.h and used the previously declared
types (which in turn use boost headers.)
This commit is contained in:
Guillermo Biset 2010-08-13 14:41:33 +00:00
parent 0c26a8ce4f
commit 77e5285794
4 changed files with 106 additions and 41 deletions

View file

@ -38,7 +38,6 @@
#include <string>
#include <assert.h>
#include <stdint.h>
namespace ana
{
@ -116,7 +115,7 @@ namespace ana
*/
bostream& operator<< (const std::string& s)
{
(*this) << uint32_t( s.size() );
(*this) << ana::ana_uint32( s.size() );
_s += s;
return *this;
}
@ -127,7 +126,7 @@ namespace ana
template <class Other>
bostream& operator<< (const std::vector<Other>& vec)
{
const uint32_t size(vec.size());
const ana::ana_uint32 size(vec.size());
(*this) << size;
for (size_t i(0); i < size; ++i)
(*this) << vec[i];
@ -230,7 +229,7 @@ namespace ana
*/
bistream& operator >> (std::string& str)
{
uint32_t size;
ana::ana_uint32 size;
(*this) >> size;
assert(_s.size() >= size+_pos);
str = _s.substr(_pos,size);
@ -249,7 +248,7 @@ namespace ana
template <class Other>
bistream& operator>> (std::vector<Other>& vec)
{
uint32_t size;
ana::ana_uint32 size;
(*this) >> size;
assert(_s.size() >= (size * sizeof(Other)) + _pos);
vec.resize(size);
@ -298,7 +297,7 @@ namespace ana
_elements_left( size ),
_bos( bos )
{
_bos << uint32_t( size );
_bos << ana::ana_uint32( size );
}
/**
@ -445,7 +444,7 @@ namespace ana
{
static void call(bostream* bos, const T& cont)
{
const uint32_t size(cont.size());
const ana::ana_uint32 size(cont.size());
(*bos) << size;
typename T::const_iterator it( cont.begin() );

View file

@ -97,7 +97,7 @@ void asio_sender::handle_sent_header(const ana::error_code& ec,
{
delete bos;
if (bytes_sent != sizeof(uint32_t) )
if (bytes_sent != sizeof( ana::ana_uint32 ) )
throw std::runtime_error("Couldn't send header.");
if ( ec )

View file

@ -323,6 +323,51 @@ void ana_multiple_receive_handler::handle_timeout(ana::error_code error_code)
timeout_called_mutex_.unlock();
}
// Begin ana_connect_handler implementation -------------------------------------------------------
ana_simple_receive_handler::ana_simple_receive_handler( ) :
mutex_(),
error_code_(),
buffer_()
{
mutex_.lock();
}
ana_simple_receive_handler::~ana_simple_receive_handler()
{
mutex_.lock();
mutex_.unlock();
}
const ana::error_code& ana_simple_receive_handler::error() const
{
return error_code_;
}
void ana_simple_receive_handler::wait_completion()
{
mutex_.lock();
mutex_.unlock();
}
ana::detail::read_buffer ana_simple_receive_handler::buffer() const
{
return buffer_;
}
void ana_simple_receive_handler::handle_receive( ana::error_code error,
ana::net_id /*client*/,
ana::detail::read_buffer buffer)
{
error_code_ = error;
buffer_ = buffer;
mutex_.unlock();
}
void ana_simple_receive_handler::handle_disconnect( ana::error_code error, ana::net_id )
{
error_code_ = error;
}
// Begin ana_connect_handler implementation -------------------------------------------------------
@ -346,13 +391,15 @@ const ana::error_code& ana_connect_handler::error() const
void ana_connect_handler::handle_connect(ana::error_code error_code, ana::net_id /*client*/)
{
if ( ! error_code_ )
error_code_ = error_code;
mutex_.unlock();
/* if ( ! error_code_ )
{
error_code_ = error_code;
mutex_.unlock(); //only unlock if it's the first time called
}
else
error_code_ = error_code; //use the latest error
error_code_ = error_code; //use the latest error*/
}
void ana_connect_handler::wait_completion()
@ -664,17 +711,30 @@ network::connection ana_network_manager::create_client_and_connect(std::string h
uint32_t my_id;
ana::serializer::bistream bis;
client->wait_raw_object(bis, sizeof(uint32_t) );
bis >> my_id;
ana::network_to_host_long( my_id );
new_component->set_wesnoth_id( my_id );
client->set_header_first_mode();
ana_simple_receive_handler rcv_handler;
client->set_listener_handler( &rcv_handler );
client->expecting_message( ana::time::seconds( 3 ) );
client->run_listener();
rcv_handler.wait_completion();
client->cancel_pending();
client->set_listener_handler( this );
return network::connection( client->id() );
if ( rcv_handler.error() )
throw network::error(_("Could not connect to host"), client->id() );
else
{
bis.str( rcv_handler.buffer()->string() );
// client->wait_raw_object(bis, sizeof(my_id) );
bis >> my_id;
ana::network_to_host_long( my_id );
new_component->set_wesnoth_id( my_id );
client->set_header_first_mode();
client->run_listener();
return network::connection( client->id() );
}
}
}
}
@ -685,24 +745,6 @@ network::connection ana_network_manager::create_client_and_connect(std::string h
}
}
/*
network::connection ana_network_manager::create_client_and_connect(std::string host,
int port,
threading::waiter& waiter)
{
const threading::async_operation_ptr op(new connect_operation(this,components_,host,port));
const connect_operation::RESULT res = op->execute(op, waiter);
if(res == connect_operation::ABORTED)
return 0;
static_cast<connect_operation*>(op.get())->check_error();
return static_cast<connect_operation*>(op.get())->result();
}
*/
network::connection ana_network_manager::new_connection_id( )
{
ana_component_set::iterator it;

View file

@ -363,6 +363,34 @@ class ana_connect_handler : public ana::connection_handler
ana::error_code error_code_;
};
class ana_simple_receive_handler : public ana::listener_handler
{
public:
ana_simple_receive_handler( );
/** Destructor. */
~ana_simple_receive_handler();
const ana::error_code& error() const;
/** Locks current thread until a message or an error has been received. */
void wait_completion();
/** Returns the buffer from the operation. */
ana::detail::read_buffer buffer() const;
private:
virtual void handle_receive( ana::error_code error,
ana::net_id client,
ana::detail::read_buffer buffer);
virtual void handle_disconnect( ana::error_code, ana::net_id );
boost::mutex mutex_;
ana::error_code error_code_;
ana::detail::read_buffer buffer_;
};
/**
* Provides network functionality for Wesnoth using the ana API and library.
*/
@ -387,10 +415,6 @@ class ana_network_manager : public ana::listener_handler,
*/
network::connection create_client_and_connect(std::string host, int port);
// network::connection create_client_and_connect(std::string host,
// int port,
// threading::waiter&);
network::connection new_connection_id( );
/**