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