root/coordinatorapi.h

/* [<][>][^][v][top][bottom][index][help] */

INCLUDED FROM


   1 /****************************************************************************
   2  *   Copyright (C) 2006-2010 by Jason Ansel, Kapil Arya, and Gene Cooperman *
   3  *   jansel@csail.mit.edu, kapil@ccs.neu.edu, gene@ccs.neu.edu              *
   4  *                                                                          *
   5  *  This file is part of DMTCP.                                             *
   6  *                                                                          *
   7  *  DMTCP is free software: you can redistribute it and/or                  *
   8  *  modify it under the terms of the GNU Lesser General Public License as   *
   9  *  published by the Free Software Foundation, either version 3 of the      *
  10  *  License, or (at your option) any later version.                         *
  11  *                                                                          *
  12  *  DMTCP is distributed in the hope that it will be useful,                *
  13  *  but WITHOUT ANY WARRANTY; without even the implied warranty of          *
  14  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the           *
  15  *  GNU Lesser General Public License for more details.                     *
  16  *                                                                          *
  17  *  You should have received a copy of the GNU Lesser General Public        *
  18  *  License along with DMTCP:dmtcp/src.  If not, see                        *
  19  *  <http://www.gnu.org/licenses/>.                                         *
  20  ****************************************************************************/
  21 
  22 #ifndef COORDINATORAPI_H
  23 #define COORDINATORAPI_H
  24 
  25 #include "constants.h"
  26 #include "protectedfds.h"
  27 #include "dmtcpmessagetypes.h"
  28 #include "shareddata.h"
  29 #include "../jalib/jsocket.h"
  30 #include "../jalib/jalloc.h"
  31 
  32 namespace dmtcp
  33 {
  34   enum CoordinatorMode {
  35     COORD_INVALID   = 0x0000,
  36     COORD_JOIN      = 0x0001,
  37     COORD_NEW       = 0x0002,
  38     COORD_NONE      = 0x0004,
  39     COORD_ANY       = 0x0010
  40   };
  41 
  42   class CoordinatorAPI
  43   {
  44     public:
  45 #ifdef JALIB_ALLOCATOR
  46       static void* operator new(size_t nbytes, void* p) { return p; }
  47       static void* operator new(size_t nbytes) { JALLOC_HELPER_NEW(nbytes); }
  48       static void  operator delete(void* p) { JALLOC_HELPER_DELETE(p); }
  49 #endif
  50       CoordinatorAPI (void) : _coordinatorSocket(-1), _nsSock(-1) {}
  51       // Use default destructor
  52 
  53       static CoordinatorAPI& instance();
  54       static void init();
  55       static void restart();
  56       static void resetOnFork(CoordinatorAPI& coordAPI);
  57 
  58       void setupVirtualCoordinator(CoordinatorInfo *coordInfo,
  59                                    struct in_addr  *localIP);
  60       void waitForCheckpointCommand();
  61       static bool noCoordinator();
  62 
  63       void connectToCoordOnStartup(CoordinatorMode  mode,
  64                                    string           progname,
  65                                    DmtcpUniqueProcessId *compId,
  66                                    CoordinatorInfo *coordInfo,
  67                                    struct in_addr  *localIP);
  68       void createNewConnectionBeforeFork(string& progname);
  69       void connectToCoordOnRestart(CoordinatorMode  mode,
  70                                    string progname,
  71                                    UniquePid compGroup,
  72                                    int np,
  73                                    CoordinatorInfo *coordInfo,
  74                                    const char *host,
  75                                    int port,
  76                                    struct in_addr  *localIP);
  77       void closeConnection() { _coordinatorSocket.close(); }
  78 
  79       //jalib::JSocket& coordinatorSocket() { return _coordinatorSocket; }
  80       bool isValid() { return _coordinatorSocket.isValid(); }
  81 
  82       void sendMsgToCoordinator(const DmtcpMessage &msg,
  83                                 const void *extraData = NULL,
  84                                 size_t len = 0);
  85       void recvMsgFromCoordinator(DmtcpMessage *msg,
  86                                   void **extraData = NULL);
  87       void connectAndSendUserCommand(char c,
  88                                      int *coordCmdStatus = NULL,
  89                                      int *numPeers = NULL,
  90                                      int *isRunning = NULL,
  91                                      int *ckptInterval = NULL);
  92 
  93       void updateCoordCkptDir(const char *dir);
  94       string getCoordCkptDir(void);
  95 
  96       void sendCkptFilename();
  97 
  98       int sendKeyValPairToCoordinator(const char *id,
  99                                       const void *key, uint32_t key_len,
 100                                       const void *val, uint32_t val_len,
 101                                       int sync = 0);
 102       int sendQueryToCoordinator(const char *id,
 103                                  const void *key, uint32_t key_len,
 104                                  void *val, uint32_t *val_len);
 105 
 106     private:
 107       void startNewCoordinator(CoordinatorMode mode);
 108       void createNewConnToCoord(CoordinatorMode mode);
 109       DmtcpMessage sendRecvHandshake(DmtcpMessage msg, string progname,
 110                                      UniquePid *compId = NULL);
 111 
 112       jalib::JSocket          _coordinatorSocket;
 113       jalib::JSocket          _nsSock;
 114   };
 115 }
 116 
 117 #endif

/* [<][>][^][v][top][bottom][index][help] */