Skip to content

Commit

Permalink
ustl: Modify libxipc to work with uSTL.
Browse files Browse the repository at this point in the history
Signed-off-by: Ben Greear <greearb@candelatech.com>
  • Loading branch information
greearb committed Jun 15, 2010
1 parent 2444709 commit d281ad5
Show file tree
Hide file tree
Showing 22 changed files with 102 additions and 42 deletions.
8 changes: 8 additions & 0 deletions xorp/libxipc/finder.cc
Expand Up @@ -53,6 +53,8 @@ class FinderTarget {
_enabled(false), _messenger(fm)
{}

FinderTarget() { _messenger = NULL; }

~FinderTarget() {
debug_msg("Destructing %s\n", name().c_str());
}
Expand Down Expand Up @@ -172,6 +174,9 @@ class FinderClass {
FinderClass(const string& name, bool singleton)
: _name(name), _singleton(singleton)
{}
#ifdef XORP_USE_USTL
FinderClass() { }
#endif

const string& name() const { return _name; }
bool singleton() const { return _singleton; }
Expand Down Expand Up @@ -238,6 +243,9 @@ class FinderEvent {
(_tag == TARGET_BIRTH) ? "birth" : "death",
_class_name.c_str(), _instance_name.c_str());
}
#ifdef XORP_USE_USTL
FinderEvent() { }
#endif
~FinderEvent()
{
debug_msg("~FinderEvent(%s, \"%s\", \"%s\")\n",
Expand Down
10 changes: 5 additions & 5 deletions xorp/libxipc/finder_client.cc
Expand Up @@ -19,10 +19,7 @@
// XORP, Inc, 2953 Bunker Hill Lane, Suite 204, Santa Clara, CA 95054, USA;
// http://xorp.net

#include <functional>



#include "libxorp/xorp.h"

#include "finder_module.h"

Expand Down Expand Up @@ -281,7 +278,7 @@ class FinderClientQuery :
}

pair<ResolvedTable::iterator, bool> result =
_rt.insert(std::make_pair(_key, FinderDBEntry(_key)));
_rt.insert(make_pair(_key, FinderDBEntry(_key)));

if (result.second == false && result.first == _rt.end()) {
// Out of memory (?)
Expand Down Expand Up @@ -591,6 +588,9 @@ class FinderClient::InstanceInfo
_dispatcher(dispatcher),
_id(_s_id++)
{}
#ifdef XORP_USE_USTL
InstanceInfo() { };
#endif
const string& instance_name() const { return _ins_name; }
const string& class_name() const { return _cls_name; }
const XrlDispatcher* dispatcher() const { return _dispatcher; }
Expand Down
3 changes: 3 additions & 0 deletions xorp/libxipc/finder_client.hh
Expand Up @@ -46,6 +46,9 @@ public:

FinderDBEntry(const string& key);
FinderDBEntry(const string& key, const string& value);
#ifdef XORP_USE_USTL
FinderDBEntry() { }
#endif

const string& key() const { return _key; }
const list<string>& values() const { return _values; }
Expand Down
3 changes: 3 additions & 0 deletions xorp/libxipc/finder_messenger.hh
Expand Up @@ -134,6 +134,9 @@ private:
callback(fmb, &FinderMessengerBase::response_timeout,
seqno));
}
#ifdef XORP_USE_USTL
ResponseState() { }
#endif

SendCallback scb;
XorpTimer expiry;
Expand Down
2 changes: 1 addition & 1 deletion xorp/libxipc/finder_server.cc
Expand Up @@ -104,7 +104,7 @@ FinderServer::add_binding(IPv4 addr, uint16_t port)
_listeners.push_back(
new FinderTcpListener(_e, _f, _f.commands(), addr, port)
);
} catch (const std::bad_alloc&) {
} catch (const bad_alloc&) {
return false;
}
// XXX we'd probably be better to leave permits alone here
Expand Down
6 changes: 3 additions & 3 deletions xorp/libxipc/finder_tcp.cc
Expand Up @@ -21,7 +21,7 @@



#include <functional>


#include "finder_module.h"

Expand Down Expand Up @@ -163,9 +163,9 @@ FinderTcpBase::read_callback(AsyncFileOperator::Event ev,
try {
_isize = ntohl(_isize);
if (0 == _isize || _isize > MAX_XRL_INPUT_SIZE)
throw std::bad_alloc();
throw bad_alloc();
_input_buffer.resize(_isize);
} catch (std::bad_alloc) {
} catch (bad_alloc) {
XLOG_ERROR("Bad input buffer size (%d bytes) from wire, "
"dropping connection", XORP_INT_CAST(_isize));
error_event();
Expand Down
6 changes: 5 additions & 1 deletion xorp/libxipc/finder_tcp_messenger.cc
Expand Up @@ -63,7 +63,11 @@ FinderTcpMessenger::read_event(int errval,
return true;
}

string s(data, data + data_bytes);
// TODO: This doesn't seem to conform to STL, not sure how it worked before.
//string s(data, data + data_bytes);
// Going to assume second arg should just be data_bytes (length)
// Needs some actual testing! --Ben
string s((const char*)(data), data_bytes);

string ex;
try {
Expand Down
10 changes: 10 additions & 0 deletions xorp/libxipc/finder_xrl_queue.cc
Expand Up @@ -44,6 +44,16 @@ FinderXrlCommandQueue::~FinderXrlCommandQueue()
{
}

FinderXrlCommandQueue& FinderXrlCommandQueue::operator=(const FinderXrlCommandQueue& rhs) {
if (&rhs != this) {
_m = rhs._m;
_cmds = rhs._cmds;
_pending = rhs._pending;
_dispatcher = rhs._dispatcher;
}
return *this;
}

inline EventLoop&
FinderXrlCommandQueue::eventloop()
{
Expand Down
9 changes: 6 additions & 3 deletions xorp/libxipc/finder_xrl_queue.hh
Expand Up @@ -46,12 +46,18 @@ public:
public:
FinderXrlCommandQueue(FinderMessengerBase* messenger);
FinderXrlCommandQueue(const FinderXrlCommandQueue& oq);
FinderXrlCommandQueue() { _m = NULL; }
~FinderXrlCommandQueue();

FinderMessengerBase& messenger() { return *_m; }

void enqueue(const Command& cmd);

#ifndef XORP_USE_USTL
private:
#endif
FinderXrlCommandQueue& operator=(const FinderXrlCommandQueue&);

protected:
void push();
void dispatch_one();
Expand All @@ -62,9 +68,6 @@ protected:
void crank();
void kill_messenger();

private:
FinderXrlCommandQueue& operator=(const FinderXrlCommandQueue&); // no impl

private:
FinderMessengerBase* _m;
list<Command> _cmds;
Expand Down
2 changes: 1 addition & 1 deletion xorp/libxipc/finder_xrl_target.cc
Expand Up @@ -382,7 +382,7 @@ FinderXrlTarget::finder_0_2_get_xrls_registered_by(const string& tgt,
_finder.commands().get_command_names(cmds);
// Turn command names into Xrls
for (list<string>::iterator i = cmds.begin(); i != cmds.end(); i++) {
xrls.push_back(Xrl("finder", *i).str());
xrls.push_back(Xrl("finder", i->c_str()).str());
}
} else if (_finder.fill_targets_xrl_list(tgt, xrls) == false) {
return
Expand Down
2 changes: 1 addition & 1 deletion xorp/libxipc/xrl.hh
Expand Up @@ -24,7 +24,7 @@
#ifndef __LIBXIPC_XRL_HH__
#define __LIBXIPC_XRL_HH__


#include "libxorp/xorp.h"

#include "libxorp/ref_ptr.hh"
#include "xrl_pf.hh" // Needed for ref_ptr instantiation of XrlPFSender
Expand Down
8 changes: 6 additions & 2 deletions xorp/libxipc/xrl_args.cc
Expand Up @@ -29,8 +29,10 @@

#include "libproto/packet.hh"

#include <functional>

#ifndef XORP_USE_USTL
#include <stdexcept>
#endif

#include "xrl_args.hh"
#include "xrl_tokens.hh"
Expand Down Expand Up @@ -636,7 +638,9 @@ XrlArgs::XrlArgs(const char* serialized) throw (InvalidString)
XrlAtom xa(tok.c_str());
add(xa);
} catch (const XrlAtomFound& /*xaf*/) {
xorp_throw(InvalidString, "Duplicate Atom found:" + tok);
string tmp("Duplicate Atom found: ");
tmp += tok;
xorp_throw(InvalidString, tmp);
}
start = end;
}
Expand Down
10 changes: 5 additions & 5 deletions xorp/libxipc/xrl_atom.cc
Expand Up @@ -697,10 +697,10 @@ XrlAtom::packed_bytes() const
return bytes;
}

static_assert(sizeof(IPv4) == 4);
static_assert(sizeof(IPv6) == 16);
static_assert(sizeof(IPv4Net) == sizeof(IPv4) + 4);
static_assert(sizeof(IPv6Net) == sizeof(IPv6) + 4);
x_static_assert(sizeof(IPv4) == 4);
x_static_assert(sizeof(IPv6) == 16);
x_static_assert(sizeof(IPv4Net) == sizeof(IPv4) + 4);
x_static_assert(sizeof(IPv6Net) == sizeof(IPv6) + 4);

switch (_type) {
case xrlatom_no_type:
Expand Down Expand Up @@ -1046,7 +1046,7 @@ XrlAtom::pack_list(uint8_t* buffer, size_t buffer_bytes) const
size_t done = 0;

uint32_t nelem = htonl(_list->size());
static_assert(sizeof(nelem) == 4);
x_static_assert(sizeof(nelem) == 4);

memcpy(buffer, &nelem, sizeof(nelem));
done += sizeof(nelem);
Expand Down
7 changes: 5 additions & 2 deletions xorp/libxipc/xrl_atom.hh
Expand Up @@ -500,14 +500,17 @@ public:
const XrlAtomType& type,
const string& m)
: _xa(XrlAtom(name, type)), _spell(m) {}
#ifdef XORP_USE_USTL
XrlAtomSpell() { }
#endif
const string& atom_name() const { return _xa.name(); }
const XrlAtomType& atom_type() const { return _xa.type(); }
const XrlAtom& atom() const { return _xa; }
const string& spell() const { return _spell; }

protected:
const XrlAtom _xa;
const string _spell;
XrlAtom _xa;
string _spell;
};

#endif // __LIBXIPC_XRL_ATOM_HH__
5 changes: 4 additions & 1 deletion xorp/libxipc/xrl_cmd_map.hh
Expand Up @@ -38,7 +38,10 @@ XorpCallback2<const XrlCmdError, const XrlArgs&, XrlArgs*>::RefPtr XrlRecvCallba
class XrlCmdEntry {
public:
XrlCmdEntry(const string& s, XrlRecvCallback cb) :
_name(s), _cb(cb) {}
_name(s), _cb(cb) {}
#ifdef XORP_USE_USTL
XrlCmdEntry() { }
#endif

const string& name() const { return _name; }

Expand Down
6 changes: 4 additions & 2 deletions xorp/libxipc/xrl_error.cc
Expand Up @@ -94,8 +94,10 @@ XrlError::XrlError(XrlErrorCode errcode, const string& note)
if (_errlet == 0) {
_errlet = &internal_error;
_note = c_format("Errorcode %d unknown", errcode);
if (note.empty() == false)
_note += " " + note;
if (note.empty() == false) {
_note += " ";
_note += note;
}
}
}

Expand Down
10 changes: 5 additions & 5 deletions xorp/libxipc/xrl_parser.cc
Expand Up @@ -299,7 +299,7 @@ get_single_quoted_value(const string& s, string::const_iterator& sci,
assert(*sci == '\'');

sci++;
token.erase();
token.clear();

string::const_iterator sci_start = sci;
advance_to_char(s, sci, '\'');
Expand All @@ -317,7 +317,7 @@ get_double_quoted_value(const string& input,
{
assert(*sci == '\"');

token.erase();
token.clear();

sci++;

Expand Down Expand Up @@ -485,7 +485,7 @@ push_atoms_and_spells(XrlArgs* args,
bool
XrlParser::start_next() throw (XrlParserInputException)
{
_input.erase();
_input.clear();

while (_xpi.getline(_input) == true) {
// Ignore blank lines and CPP directives (at least for time being).
Expand Down Expand Up @@ -594,8 +594,8 @@ XrlParser::get(string& protocol, string& target, string& command,
return false;
}

target.erase();
command.erase();
target.clear();
command.clear();
if (args) args->clear();
if (spells) spells->clear();

Expand Down
21 changes: 18 additions & 3 deletions xorp/libxipc/xrl_parser_input.cc
Expand Up @@ -59,8 +59,23 @@ XrlParserFileInput::slurp_line(string& line)
}

stack_top().incr_line();
#ifdef XORP_USE_USTL
{
// Lame as can be, but uSTL doesn't have working getline(), so
// fake one out here..
line.clear();
char c[2];
while (stack_top().input()->remaining() > 0) {
stack_top().input()->read(&c[0], 1);
c[1] = 0;
if (c[0] == '\n')
break;
line.append(c);
}
}
#else
std::getline(*stack_top().input(), line);

#endif
// Okay, got line see if it's a pre-processor directive
for (string::const_iterator c = line.begin();
c != line.end(); c++) {
Expand Down Expand Up @@ -279,7 +294,7 @@ XrlParserFileInput::stack_depth() const
bool
XrlParserFileInput::getline(string& line) throw (XrlParserInputException)
{
line.erase();
line.clear();

if (_inserted_lines.empty() == false) {
line = _inserted_lines.front();
Expand All @@ -301,7 +316,7 @@ XrlParserFileInput::getline(string& line) throw (XrlParserInputException)
return false; // Non blank line
}

line.erase();
line.clear();
return true;
}

Expand Down
2 changes: 2 additions & 0 deletions xorp/libxipc/xrl_parser_input.hh
Expand Up @@ -109,6 +109,8 @@ protected:
struct FileState {
FileState(istream* input, const char* fname) :
_input(input), _fname(fname), _line(0) {}
FileState() { _input = NULL; _fname = NULL; } // for uSTL

// Accessors
istream* input() const { return _input; }
const char* filename() const { return _fname; }
Expand Down
4 changes: 2 additions & 2 deletions xorp/libxipc/xrl_pf_stcp_ph.cc
Expand Up @@ -62,11 +62,11 @@ STCPPacketHeader::STCPPacketHeader(uint8_t* data)
_error_note_bytes(_data + _error_note_bytes_offset),
_xrl_data_bytes(_data + _xrl_data_bytes_offset)
{
static_assert(STCPPacketHeader::SIZE == _fourcc_sizeof + _major_sizeof
x_static_assert(STCPPacketHeader::SIZE == _fourcc_sizeof + _major_sizeof
+ _minor_sizeof + _seqno_sizeof + _flags_sizeof + _type_sizeof
+ _error_code_sizeof + _error_note_bytes_sizeof
+ _xrl_data_bytes_sizeof);
static_assert(STCPPacketHeader::SIZE ==
x_static_assert(STCPPacketHeader::SIZE ==
_xrl_data_bytes_offset + _xrl_data_bytes_sizeof);
}

Expand Down
2 changes: 1 addition & 1 deletion xorp/libxipc/xrl_router.cc
Expand Up @@ -62,7 +62,7 @@ static class TraceXrl {

#define trace_xrl(p, x) \
do { \
if (xrl_trace.on()) XLOG_INFO("%s", string((p) + (x).str()).c_str()); \
if (xrl_trace.on()) XLOG_INFO("%s", string(string(p) + (x).str()).c_str()); \
} while (0)


Expand Down

0 comments on commit d281ad5

Please sign in to comment.