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

Open Mash Cross Reference
mash/tgw/BidderHouse.h

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

  1 /*
  2  * BidderHouse.h --
  3  *
  4  *      FIXME: This file needs a description here.
  5  *
  6  * Copyright (c) 2001-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 
 34 #ifndef BIDDERHOUSE_H
 35 #define BIDDERHOUSE_H
 36 
 37 #define BID_INTERVAL    33      // how often to have a bid (in ms).
 38 #define UPDATE_INTERVAL 1000    // how often to have a bid (in ms).
 39 #define MAX_STREAMS     10      // max number of streams to handle.
 40 #define MAX_BW_SECONDS  2       // max amount of saved bw (in bytes).
 41 #define WAGE_FACTOR     1000    // inflate the wages so we don't have to worry about precision loss.
 42 #define MAX_SAVED_MONEY MAX_BW_SECONDS*(1000/BID_INTERVAL)*100*WAGE_FACTOR      // max amount of saved bw (in bytes).
 43 #include <vector>
 44 #include "tclcl.h"
 45 
 46 #if __GNUC__ >= 3 || _MSC_VER
 47 using namespace std;
 48 #endif
 49 
 50 class PipeRenderer;
 51 
 52 class Bidder {
 53 public:
 54   Bidder(int m, int w, int dw, int ds, int bw, PipeRenderer* ms): money(m), wage(w), diffsWant(dw), diffSize(ds), bandwidth(bw), msource(ms) { ;};
 55 
 56   int money;            // accumulated wealth of the source
 57   int wage;             // its income (based on slider)
 58   int diffsWant;        // how many diffs it wants to send
 59   int diffSize;         // average size of a diff, in bytes
 60   int bandwidth;        // bandwidth that this source is using in bps.
 61   PipeRenderer* msource;// link to the renderer.
 62 };
 63 
 64 class BidderHouse : public TclObject {
 65 public:
 66   BidderHouse(int bw): bps(bw), bytesToSend(0) { ;};
 67 
 68   void addSource(PipeRenderer* msource);
 69   void setDiffCount(PipeRenderer* msource, int diffCount, int meanDiffSize);
 70   Bidder* lookupSource(PipeRenderer* msource);
 71   void giveBWtoSource(Bidder* source, int price);
 72   void lotterySort(int num_of_sources);
 73   void sellBandwidth();
 74   int  command(int argc, const char*const* argv);
 75   void getBandwidthUsage();
 76   void setPriority(PipeRenderer* msource, int percentage);
 77 private:
 78   int bps;              // bits per second for the aggregate outgoing bw
 79   int bytesToSend;      // amount of bandwidth that is available to use now.
 80   vector<Bidder*> sources;
 81   Bidder* lottery_source[MAX_STREAMS];  // these three arrays are used to sort
 82   int lottery_units[MAX_STREAMS];       // and find the highest bidder
 83   int lottery_price[MAX_STREAMS];
 84 };
 85 
 86 #endif
 87 
 88 

~ [ 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.