Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#ifndef TIPC_SERVER_H
Toshihiro Shimizu 890ddd
#define TIPC_SERVER_H
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//Toonz includes
Toshihiro Shimizu 890ddd
#include "tcommon.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//STL includes
Toshihiro Shimizu 890ddd
#include <map></map>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//Qt includes
Toshihiro Shimizu 890ddd
#include <qstring></qstring>
Toshihiro Shimizu 890ddd
#include <qhash></qhash>
Toshihiro Shimizu 890ddd
#include <qsharedmemory></qsharedmemory>
Toshihiro Shimizu 890ddd
#include <qlocalserver></qlocalserver>
Toshihiro Shimizu 890ddd
#include <qlocalsocket></qlocalsocket>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#undef DVAPI
Toshihiro Shimizu 890ddd
#undef DVVAR
Toshihiro Shimizu 890ddd
#ifdef TNZCORE_EXPORTS
Toshihiro Shimizu 890ddd
#define DVAPI DV_EXPORT_API
Toshihiro Shimizu 890ddd
#define DVVAR DV_EXPORT_VAR
Toshihiro Shimizu 890ddd
#else
Toshihiro Shimizu 890ddd
#define DVAPI DV_IMPORT_API
Toshihiro Shimizu 890ddd
#define DVVAR DV_IMPORT_VAR
Toshihiro Shimizu 890ddd
#endif
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
namespace tipc
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
class MessageParser;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//*******************************************************************************
Toshihiro Shimizu 890ddd
//    Server declaration
Toshihiro Shimizu 890ddd
//*******************************************************************************
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
/*!
Toshihiro Shimizu 890ddd
  The tipc::Server class is the base server class for inter-process communication
Toshihiro Shimizu 890ddd
  in Toonz-related applications.
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
  A tipc::Server is a specialized QLocalServer which stores header/message-callback
Toshihiro Shimizu 890ddd
  associations to perform message parsing.
Toshihiro Shimizu 890ddd
*/
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
class DVAPI Server : public QLocalServer
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	Q_OBJECT
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	QHash<qstring, *="" messageparser=""> m_parsers;</qstring,>
Toshihiro Shimizu 890ddd
	bool m_lock;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Toshihiro Shimizu 890ddd
	Server();
Toshihiro Shimizu 890ddd
	~Server();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void addParser(MessageParser *parser);
Toshihiro Shimizu 890ddd
	void removeParser(QString header);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	//!Generic dispatcher function for socket messages.
Toshihiro Shimizu 890ddd
	//!Acceptable socket messages are composed of a header and a body part.
Toshihiro Shimizu 890ddd
	//!The header part, containing an explanation of the message's body, is
Toshihiro Shimizu 890ddd
	//!the first line of the message, and is expected to be at max 1024 chars long.
Toshihiro Shimizu 890ddd
	//!Depending on the header content, the rest of the message is read in
Toshihiro Shimizu 890ddd
	//!specialized message handler functions.
Toshihiro Shimizu 890ddd
	void dispatchSocket(QLocalSocket *socket);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public Q_SLOTS:
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	//! Receives a client connection to the server and prepares a socket for the connection.
Toshihiro Shimizu 890ddd
	void onNewConnection();
Toshihiro Shimizu 890ddd
	void onError(QLocalSocket::LocalSocketError);
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
} //namespace tipc
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#endif //TIPC_SERVER_H