tahoma2d/toonz/sources/include/tipcsrv.h

80 lines
1.8 KiB
C
Raw Normal View History

2016-05-17 03:04:11 +12:00
#pragma once
2016-03-19 06:57:51 +13:00
#ifndef TIPC_SERVER_H
#define TIPC_SERVER_H
2016-06-15 18:43:10 +12:00
// Toonz includes
2016-03-19 06:57:51 +13:00
#include "tcommon.h"
2016-06-15 18:43:10 +12:00
// STL includes
2016-03-19 06:57:51 +13:00
#include <map>
2016-06-15 18:43:10 +12:00
// Qt includes
2016-03-19 06:57:51 +13:00
#include <QString>
#include <QHash>
#include <QSharedMemory>
#include <QLocalServer>
#include <QLocalSocket>
#undef DVAPI
#undef DVVAR
#ifdef TNZCORE_EXPORTS
#define DVAPI DV_EXPORT_API
#define DVVAR DV_EXPORT_VAR
#else
#define DVAPI DV_IMPORT_API
#define DVVAR DV_IMPORT_VAR
#endif
2016-06-15 18:43:10 +12:00
namespace tipc {
2016-03-19 06:57:51 +13:00
class MessageParser;
//*******************************************************************************
// Server declaration
//*******************************************************************************
/*!
2016-06-15 18:43:10 +12:00
The tipc::Server class is the base server class for inter-process
communication
2016-03-19 06:57:51 +13:00
in Toonz-related applications.
2016-06-15 18:43:10 +12:00
A tipc::Server is a specialized QLocalServer which stores
header/message-callback
2016-03-19 06:57:51 +13:00
associations to perform message parsing.
*/
class DVAPI Server final : public QLocalServer {
2016-06-15 18:43:10 +12:00
Q_OBJECT
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
QHash<QString, MessageParser *> m_parsers;
bool m_lock;
2016-03-19 06:57:51 +13:00
public:
2016-06-15 18:43:10 +12:00
Server();
~Server();
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
void addParser(MessageParser *parser);
void removeParser(QString header);
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
//! Generic dispatcher function for socket messages.
//! Acceptable socket messages are composed of a header and a body part.
//! The header part, containing an explanation of the message's body, is
//! the first line of the message, and is expected to be at max 1024 chars
//! long.
//! Depending on the header content, the rest of the message is read in
//! specialized message handler functions.
void dispatchSocket(QLocalSocket *socket);
2016-03-19 06:57:51 +13:00
public Q_SLOTS:
2016-06-15 18:43:10 +12:00
//! Receives a client connection to the server and prepares a socket for the
//! connection.
void onNewConnection();
void onError(QLocalSocket::LocalSocketError);
2016-03-19 06:57:51 +13:00
};
2016-06-15 18:43:10 +12:00
} // namespace tipc
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
#endif // TIPC_SERVER_H