Source: ../../libxipc/xrl_pf.hh


Annotated List
Files
Globals
Hierarchy
Index
// -*- c-basic-offset: 4; tab-width: 8; indent-tabs-mode: t -*-

// Copyright (c) 2001-2003 International Computer Science Institute
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software")
// to deal in the Software without restriction, subject to the conditions
// listed in the XORP LICENSE file. These conditions include: you must
// preserve this copyright notice, and you cannot mention the copyright
// holders in advertising related to the Software without their permission.
// The Software is provided WITHOUT ANY WARRANTY, EXPRESS OR IMPLIED. This
// notice is a summary of the XORP LICENSE file; the license in that file is
// legally binding.

// $XORP: xorp/libxipc/xrl_pf.hh,v 1.15 2003/05/30 23:15:56 hodson Exp $

// XRL Protocol Family Header

#ifndef __LIBXIPC_XRL_PF_HH__
#define __LIBXIPC_XRL_PF_HH__

#include <string>
#include "xrl.hh"
#include "xuid.hh"

#include "libxorp/eventloop.hh"
#include "libxorp/timer.hh"
#include "libxorp/selector.hh"
#include "libxorp/exceptions.hh"

class XrlPFConstructorError : public XorpReasonedException {
public:
    XrlPFConstructorError(const char* file, size_t line, const string& reason)
	: XorpReasonedException("XrlPFConstructorError", file, line, reason)
    {}
};

class XrlDispatcher;

class XrlPFListener {
public:
    XrlPFListener(EventLoop& e, XrlDispatcher* d = 0)
	: _eventloop(e), _dispatcher(d) {}
    virtual ~XrlPFListener() {}
    virtual const char*	address() const = 0;
    virtual const char*	protocol() const = 0;

    inline bool set_dispatcher(XrlDispatcher* d);
    inline const XrlDispatcher* dispatcher() const { return _dispatcher; }

    EventLoop& eventloop() const { return _eventloop; }

protected:
    EventLoop& _eventloop;
    const XrlDispatcher* _dispatcher;
};

// ----------------------------------------------------------------------------
// XrlPFSender

class XrlPFSender {
public:
    XrlPFSender(EventLoop& e, const char* address = "")
	: _eventloop(e), _address(address) {}

    virtual ~XrlPFSender() {}

    typedef
    XorpCallback3<void, const XrlError&, const Xrl&, XrlArgs*>::RefPtr
    SendCallback;

    virtual void send(const Xrl& x, const SendCallback& cb) = 0;
    virtual bool sends_pending() const = 0;

    const string& address() const { return _address; }
    EventLoop& eventloop() const { return _eventloop; }

    struct Request {
	XrlPFSender*	parent;
	XUID		xuid;		// to match requests and responses
	const Xrl*	xrl;
	SendCallback	callback;
	XorpTimer	timeout;
	Request(XrlPFSender* p, const Xrl& x, const SendCallback& cb)
	    : parent(p), xuid(), xrl(&x), callback(cb) {}
	Request() : xrl(0) {}
	bool operator==(const XUID& x) const { return xuid == x; }
    };

protected:
    EventLoop& _eventloop;
    string _address;
};

// ----------------------------------------------------------------------------
// Inline XrlPFListener Methods

inline bool
XrlPFListener::set_dispatcher(XrlDispatcher* d)
{
    if (_dispatcher == 0) {
	_dispatcher = d;
	return true;
    }
    return false;
}

#endif // __LIBXIPC_XRL_PF_HH__

Generated by: pavlin on possum.icir.org on Mon Jun 9 13:23:50 2003, using kdoc 2.0a54+XORP.