root/lookup_service.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 LOOKUP_SERVICE_H
  23 #define LOOKUP_SERVICE_H
  24 
  25 #include <map>
  26 #include <string.h>
  27 #include "dmtcpmessagetypes.h"
  28 #include "../jalib/jsocket.h"
  29 
  30 namespace dmtcp
  31 {
  32   class KeyValue {
  33     public:
  34       KeyValue(const void *data, const size_t len) {
  35         _data = JALLOC_HELPER_MALLOC(len);
  36         _len = len;
  37         memcpy(_data, data, len);
  38       }
  39       ~KeyValue() {}
  40 
  41       void destroy() {
  42         JASSERT(_data != NULL);
  43         JALLOC_HELPER_FREE(_data);
  44       }
  45 
  46       void *data() {return _data;}
  47       size_t len() {return _len;}
  48 
  49       bool operator< ( const KeyValue& that ) const {
  50         if (_len == that._len) {
  51           return memcmp(_data, that._data, _len) < 0;
  52         }
  53         return _len < that._len;
  54       }
  55       bool operator== ( const KeyValue& that ) const {
  56         return _len == that._len && memcmp(_data, that._data, _len) == 0;
  57       }
  58       bool operator!= ( const KeyValue& that ) const {
  59         return ! operator== ( that );
  60       }
  61 
  62     private:
  63       void *_data;
  64       size_t _len;
  65   };
  66 
  67   class LookupService {
  68     public:
  69       LookupService(){}
  70       ~LookupService() { reset(); }
  71       void reset();
  72       void registerData(const DmtcpMessage& msg, const void *data);
  73       void respondToQuery(jalib::JSocket& remote,
  74                           const DmtcpMessage& msg, const void *data);
  75 
  76     private:
  77       typedef map<KeyValue, KeyValue*> KeyValueMap;
  78       typedef map<string, KeyValueMap>::iterator MapIterator;
  79       void addKeyValue(string id, const void *key, size_t keyLen,
  80                        const void *val, size_t valLen);
  81       void query(string id, const void *key, size_t keyLen,
  82                  void **val, size_t *valLen);
  83 
  84     private:
  85       map<string, KeyValueMap> _maps;
  86   };
  87 }
  88 #endif

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