Drizzled Public API Documentation

write_buffer.h
Go to the documentation of this file.
00001 /* - mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
00002  *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
00003  *
00004  *  Copyright (C) 2010 Jay Pipes <jaypipes@gmail.com>
00005  *
00006  *  Authors:
00007  *
00008  *  Jay Pipes <jaypipes@gmail.com>
00009  *
00010  *  This program is free software; you can redistribute it and/or modify
00011  *  it under the terms of the GNU General Public License as published by
00012  *  the Free Software Foundation; either version 2 of the License, or
00013  *  (at your option) any later version.
00014  *
00015  *  This program is distributed in the hope that it will be useful,
00016  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00017  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018  *  GNU General Public License for more details.
00019  *
00020  *  You should have received a copy of the GNU General Public License
00021  *  along with this program; if not, write to the Free Software
00022  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00023  */
00024 
00031 #pragma once
00032 
00033 #include <stdint.h>
00034 #include <vector>
00035 #include <pthread.h>
00036 
00037 class WriteBuffer
00038 {
00039 public:
00040   static const size_t DEFAULT_WRITE_BUFFER_SIZE= 1024; /* Many GPB messages are < 1 KB... */
00044   WriteBuffer();
00045   ~WriteBuffer();
00049   void lock()
00050   {
00051     pthread_mutex_lock(&latch);
00052   }
00056   void unlock()
00057   {
00058     pthread_mutex_unlock(&latch);
00059   }
00065   void resize(size_t new_size);
00069   uint8_t *getRawBytes()
00070   {
00071     return &buffer[0];
00072   }
00076   size_t getCapacity()
00077   {
00078     return buffer.size();
00079   }
00080 private:
00081   /* Prohibit these */
00082   WriteBuffer(const WriteBuffer&);
00083   WriteBuffer &operator=(const WriteBuffer&);
00084 
00085   std::vector<uint8_t> buffer; 
00086   pthread_mutex_t latch; 
00087 };
00088