home *** CD-ROM | disk | FTP | other *** search
/ Dream 52 / Amiga_Dream_52.iso / Linux / Divers / lyx-0.13.2.tar.gz / lyx-0.13.2.tar / lyx-0.13.2 / src / lyxserver.h < prev    next >
C/C++ Source or Header  |  1998-04-23  |  3KB  |  121 lines

  1. // -*- C++ -*-
  2. /* This file is part of
  3. * ======================================================
  4. *           LyX, The Document Processor
  5. *        
  6. *           Copyright (C) 1995 Matthias Ettrich
  7. *           Copyright (C) 1995-1998 The LyX Team.
  8. *
  9. *======================================================*/
  10.  
  11. #ifndef _LYXSERVER_H_
  12. #define _LYXSERVER_H_
  13.  
  14. #ifdef __GNUG__
  15. #pragma interface
  16. #endif
  17.  
  18. #include "LString.h"
  19. class LyXFunc;
  20. class LyXServer;
  21.  
  22. /* --- i/o pipes --------------------------------------------------------- */
  23.  
  24. /** This class managed the pipes used for communicating with clients.
  25.  Usage: Initialize with pipe-filename-base, client class to receive
  26.  messages, and callback-function that will be called with the messages.
  27.  When you want to send, use "send()".
  28.  This class encapsulates all the dirty communication and thus provides
  29.  a clean LString interface.
  30.  */
  31. class LyXComm
  32. {
  33. public:
  34.     /** When we receive a message, we send it to a client.
  35.       This is one of the small things that would have been a lot
  36.       cleaner with a Signal/Slot thing.
  37.      */
  38.     typedef void (*ClientCallbackfct)(LyXServer *, LString const &);
  39.  
  40.     /// Construct with pipe-basename and callback to receive messages
  41.     LyXComm(LString const &pip, LyXServer * cli, ClientCallbackfct ccb = 0)
  42.         :pipename(pip), client(cli), clientcb(ccb)
  43.     {
  44.         ready = false;
  45.         openConnection();
  46.     }
  47.  
  48.     ///
  49.     ~LyXComm() {
  50.         closeConnection();
  51.     }
  52.  
  53.     /// Send message
  54.     void send(LString const &);
  55. private:
  56.     /// Open pipes
  57.     void openConnection();
  58.     
  59.     /// Close pipes
  60.     void closeConnection();
  61.  
  62.     /// We receive messages via XForms through this callback
  63.     static void callback(int fd, void *v);
  64.  
  65.     /// This is -1 if not open
  66.     int infd;
  67.  
  68.     /// This is -1 if not open
  69.     int outfd;
  70.  
  71.     /// Are we up and running?
  72.     bool ready;
  73.  
  74.     /// Base of pipename including path
  75.     LString pipename;
  76.  
  77.     /// The client
  78.     LyXServer * client;
  79.  
  80.     /// The client callback function
  81.     ClientCallbackfct clientcb;
  82. };
  83.  
  84.  
  85. /* --- prototypes -------------------------------------------------------- */
  86. class LyXServer
  87. {
  88. public:
  89.     // FIXME IN 0.13
  90.     // Hack! This should be changed in 0.13
  91.  
  92.     /// The lyx server should not take an argument "LyXFunc" but this is
  93.     // how it will be done for 0.12. In 0.13 we must write a non-gui
  94.     // bufferview.
  95.         // IMO lyxserver is atypical, and for the moment the only one, non-gui
  96.         // bufferview. We just have to find a way to handle situations like if
  97.         // lyxserver is using a buffer that is being edited with a bufferview.
  98.         // With a common buffer list this is not a problem, maybe. (Alejandro)
  99.     LyXServer(LyXFunc *f, LString const &pip)
  100.         : func(f), pipes(pip, (this), callback)
  101.     { }
  102.         /// 
  103.     ~LyXServer();
  104.     ///
  105.     void notifyClient(LString const &);
  106. private:
  107.     ///
  108.     static void callback(LyXServer *, LString const & msg);
  109.     /// Number of current clients
  110.     int clients;
  111.     ///
  112.     LyXFunc *func;
  113.     ///
  114.     LyXComm pipes;
  115. };
  116.  
  117. #endif /* _LYXSERVER_H_ */
  118.  
  119. /* === End of File: lyxserver.h ========================================== */
  120.