~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

Open Mash Cross Reference
mash/archive/mb-archive.h

Component: ~ [ mash ] ~ [ apps ] ~ [ gsm ] ~ [ lib ] ~ [ otcl ] ~ [ srm ] ~ [ tcl8.3 ] ~ [ tclcl ] ~ [ tk8.3 ] ~ [ tutorials ] ~

  1 /*
  2  * mb-archive.h --
  3  *
  4  *      MediaBoard Archive header
  5  *
  6  * Copyright (c) 1997-2002 The Regents of the University of California.
  7  * All rights reserved.
  8  *
  9  * Redistribution and use in source and binary forms, with or without
 10  * modification, are permitted provided that the following conditions are met:
 11  *
 12  * A. Redistributions of source code must retain the above copyright notice,
 13  *    this list of conditions and the following disclaimer.
 14  * B. Redistributions in binary form must reproduce the above copyright notice,
 15  *    this list of conditions and the following disclaimer in the documentation
 16  *    and/or other materials provided with the distribution.
 17  * C. Neither the names of the copyright holders nor the names of its
 18  *    contributors may be used to endorse or promote products derived from this
 19  *    software without specific prior written permission.
 20  *
 21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS
 22  * IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
 23  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 24  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE
 25  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 26  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 27  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 28  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 29  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 30  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 31  * POSSIBILITY OF SUCH DAMAGE.
 32  *
 33  * @(#) $Header: /usr/mash/src/repository/mash/mash-1/archive/mb-archive.h,v 1.7 2002/02/03 03:09:26 lim Exp $
 34  */
 35 
 36 
 37 #ifndef MASH_MB_BUFFER_H
 38 #define MASH_MB_BUFFER_H
 39 
 40 
 41 #include "archive/timeval.h"
 42 #include "mb/mb-time.h"
 43 
 44 class DataBuffer {
 45 public:
 46         DataBuffer() : pb(NULL), size(0) { }
 47         ~DataBuffer() { free(); }
 48         Bool alloc(int newSize) {
 49                 if (newSize > size) pb = (Byte*) realloc(pb, newSize);
 50                 if (pb==NULL) return FALSE;
 51                 size = newSize;
 52                 return TRUE;
 53         }
 54         void free() {
 55                 if (pb!=NULL) {
 56                         ::free(pb);
 57                         pb = NULL;
 58                         size = 0;
 59                 }
 60         }
 61 
 62         Byte *pb;
 63         int  size;
 64 };
 65 
 66 
 67 inline u_int32_t logical2mb(u_int32_t sec, u_int32_t usec)
 68 {
 69         return sec*100 + usec/10000;
 70 }
 71 
 72 
 73 inline u_int32_t logical2mb(timeval tv)
 74 {
 75         return logical2mb(tv.tv_sec, tv.tv_usec);
 76 }
 77 
 78 
 79 inline timeval mb2logical_units(u_int32_t ts)
 80 {
 81         timeval tv;
 82         tv.tv_sec = ts / 100;
 83         tv.tv_usec = (ts % 100) * 10000;
 84         return tv;
 85 }
 86 
 87 
 88 inline timeval mb2logical(u_int32_t ts, timeval reference)
 89 {
 90         u_int32_t refMB = logical2mb(reference);
 91         timeval diff;
 92 
 93         if (refMB <= ts) {
 94                 // this case will happen if sender and receiver
 95                 // clocks are not synchronized
 96                 diff = mb2logical_units(ts - refMB);
 97                 return (reference + diff);
 98         }
 99         else {
100                 diff = mb2logical_units(refMB - ts);
101                 return (reference - diff);
102         }
103 }
104 
105 
106 
107 #endif /* MASH_MB_BUFFER_H */
108 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

This page was automatically generated by the LXR engine.
Visit the LXR main site for more information.