Click here to Skip to main content
15,895,656 members
Articles / Programming Languages / C++

DynObj - C++ Cross Platform Plugin Objects

Rate me:
Please Sign up or sign in to vote.
4.95/5 (34 votes)
27 Sep 200727 min read 146.3K   3.4K   132  
DynObj is an open source library that provides a C++ application with run-time class loading facilities
#ifndef NOTIFIABLEI_HPP
#define NOTIFIABLEI_HPP

/*
	This includes the interfaces without any implementation code.
*/


// Predefined NotDataI IDs here (values<0)
#define NOT_EVT_ALIVE       -2  // An alive signal, do nothing (also allows the source to count number of subscribers)
#define NOT_EVT_DESTRUCTOR	-1  // Destructor notification
#define NOT_EVT_ALL         0   // All notifications (on subscribing)


class NotifierI;   //  (source)
class NotifiableI; //  (target)

// Notifications has one ID and one NotDataI* pdata


/** @ingroup VObj 
 * This is the base class for data passed along when notifying. */
class NotDataI {
public:
	/** For async notification, make a copy and store for later delivery. */ 
	virtual NotDataI* docall Clone(){ return NULL; };
};


/** @ingroup VObj 
 * The receiver (target) of notifications.
 * The expectation is that these methods are thread safe. */
class NotifiableI {
public:
	/** This function gets called when the source has a notification. */ 
	virtual bool docall OnNotify(NotifierI* src, int evt, NotDataI *pnd=NULL ) = 0;
};

/** @ingroup VObj 
 * The generator (source) of notifications. 
 * The expectation is that these methods are thread safe. */
class NotifierI {
public:
	/** Add a notification target. 
     * @param pnot is the target, where we send notifications. 
     * @param evt is the type of notifications we want to know about, set to 
     * 0 to receive all notifications. */ 
	virtual bool docall AddNotifiable(NotifiableI* pnot, int evt) = 0;
	/** Remove a notification target.
     * @param pnot is the target, that should have no more notifications. 
     * @param evt is the type of notifications we stop subscribing to, set to 
     * 0 to stop for all notifications. */ 
	virtual bool docall RemoveNotifiable(NotifiableI* pnot, int evt) = 0;
	/** Trigger send notification to all added targets. 
     * @param evt is the event type to send 
     * @param pnd is an optional structure with data
     * @return Returns the number of objects that were notified */
	virtual int docall Notify(int evt, NotDataI *pnd) = 0;
};

#endif // NOTIFIABLEI_HPP

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
United Kingdom United Kingdom
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions