root/plugin/ipc/event/util_descriptor.h

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

INCLUDED FROM


   1 /****************************************************************************
   2  *   Copyright (C) 2012 by Onyeka Igabari                                   *
   3  *                                                                          *
   4  *   This file is part of the dmtcp/src module of DMTCP (DMTCP:dmtcp/src).  *
   5  *                                                                          *
   6  *  DMTCP:dmtcp/src is free software: you can redistribute it and/or        *
   7  *  modify it under the terms of the GNU Lesser General Public License as   *
   8  *  published by the Free Software Foundation, either version 3 of the      *
   9  *  License, or (at your option) any later version.                         *
  10  *                                                                          *
  11  *  DMTCP:dmtcp/src is distributed in the hope that it will be useful,      *
  12  *  but WITHOUT ANY WARRANTY; without even the implied warranty of          *
  13  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the           *
  14  *  GNU Lesser General Public License for more details.                     *
  15  *                                                                          *
  16  *  You should have received a copy of the GNU Lesser General Public        *
  17  *  License along with DMTCP:dmtcp/src.  If not, see                        *
  18  *  <http://www.gnu.org/licenses/>.                                         *
  19  ****************************************************************************/
  20 
  21 
  22 /******************************************************************
  23  * File:   util_descriptor.h
  24  *
  25  * Author: onyeka Igabari
  26  *
  27  * Description: Declares the Descriptor class for handling memory
  28  *              allocation for system calls with different descriptors
  29  *
  30  * Created on July 11, 2012, 6:02 PM
  31 ******************************************************************/
  32 
  33 #pragma once
  34 #ifndef UTIL_DESCRIPTOR_H
  35 #define UTIL_DESCRIPTOR_H
  36 
  37 #include <signal.h>
  38 
  39 #define SUCCESS             0
  40 #define FAILURE            -1
  41 #define MAX_DESCRIPTORS    24
  42 #define MAX_PATH_LEN       48
  43 
  44 typedef enum
  45 {
  46    UNUSED_DESCRIPTOR,
  47    TIMER_CREATE_DECRIPTOR,
  48    INOTIFY_ADD_WATCH_DESCRIPTOR,
  49    MAX_NUM_OF_DESCRIPTORS
  50 }descriptor_type_e;
  51 
  52 typedef struct
  53 {
  54    descriptor_type_e type;
  55    int watch_descriptor;
  56    int file_descriptor;
  57    unsigned int mask;
  58    char pathname [ MAX_PATH_LEN ];
  59 } inotify_add_watch_t;
  60 
  61 typedef struct
  62 {
  63    descriptor_type_e type;
  64    clockid_t clockid;
  65    sigevent signal_event;
  66    timer_t timerid;
  67 } timer_create_t;
  68 
  69 typedef union
  70 {
  71    timer_create_t create_timer;
  72    inotify_add_watch_t  add_watch;
  73 } descriptor_types_u;
  74 
  75 namespace dmtcp
  76 {
  77    namespace Util
  78    {
  79       class Descriptor
  80       {
  81          static descriptor_types_u* descrip_types_p[MAX_DESCRIPTORS];
  82          static unsigned int descriptor_counter;
  83          static bool is_initialized;
  84          int remove_timer_descriptor(timer_t timer_id);
  85          int remove_inotify_watch_descriptor(int watch_descriptor);
  86        public:
  87          Descriptor();
  88          ~Descriptor();
  89          unsigned int count_descriptors();
  90          void add_descriptor(descriptor_types_u*  descriptor);
  91          int remove_descriptor(descriptor_type_e type, void* descriptor);
  92          bool get_descriptor(unsigned int index, descriptor_type_e type,
  93                              descriptor_types_u*  descriptor);
  94       };
  95    }
  96 }
  97 
  98 #endif  /* UTIL_DESCRIPTOR_H */
  99 
 100 

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