Ejemplo n.º 1
0
bool
PAP::Up()
{
	TRACE("PAP: Up() state=%d\n", State());

	switch (State()) {
		case INITIAL:
			if (Side() == PPP_LOCAL_SIDE) {
				NewState(REQ_SENT);
				InitializeRestartCount();
				SendRequest();
			} else if (Side() == PPP_PEER_SIDE) {
				NewState(WAITING_FOR_REQ);
				InitializeRestartCount();
				fNextTimeout = system_time() + kPAPTimeout;
			} else {
				UpFailedEvent();
				return false;
			}
		break;

		default:
			;
	}

	return true;
}
Ejemplo n.º 2
0
status_t
PAP::InitCheck() const
{
	if (Side() != PPP_LOCAL_SIDE && Side() != PPP_PEER_SIDE)
		return B_ERROR;

	return KPPPProtocol::InitCheck();
}
Ejemplo n.º 3
0
static int BuildEllipse2(REAL8 xmajor_a, REAL8 yminor_b, REAL8 angle)
{
	int i,nrLines,xCeil;
	int lineStart,lineEndIncl;
	REAL8 xIncr,c=cos(angle),s=sin(angle);
	HOR_CUT_LINE *l;
	PRECOND(xmajor_a != 0);
	PRECOND(yminor_b != 0);
	xmajor_a /= Side();
	yminor_b /= Side();

	xCeil = (size_t)ceil(xmajor_a);
	nrLines = (xCeil*2)+1;
	l = (HOR_CUT_LINE *)ChkMalloc(sizeof(HOR_CUT_LINE)*nrLines);
	for(i=0; i < nrLines; i++) {
		/* mark not initialized */
		SET_MV_REAL4(&(l[i].start.f));
	}

	for (xIncr = 0; xIncr < xCeil; xIncr+=1) {
	 REAL8 y = sqrt( fabs(1-(sqr(xIncr)/sqr(xmajor_a)))*sqr(yminor_b));
	 Add2Lines(l,nrLines,xCeil,c,s, xIncr, y);
	 Add2Lines(l,nrLines,xCeil,c,s, xIncr,-y);
	 Add2Lines(l,nrLines,xCeil,c,s,-xIncr, y);
	 Add2Lines(l,nrLines,xCeil,c,s,-xIncr,-y);
	}
	if (0) {
	 REAL8 y;
	 xIncr = xmajor_a;
	 y = sqrt( fabs(1-(sqr(xIncr)/sqr(xmajor_a)))*sqr(yminor_b));
	 Add2Lines(l,nrLines,xCeil,c,s, xIncr, y);
	 Add2Lines(l,nrLines,xCeil,c,s, xIncr,-y);
	 Add2Lines(l,nrLines,xCeil,c,s,-xIncr, y);
	 Add2Lines(l,nrLines,xCeil,c,s,-xIncr,-y);
	}

	for(i=0; i < nrLines; i++) {
		/* mark not initialized */
		if (!IS_MV_REAL4(&(l[i].start.f)))
			break;
	}
	POSTCOND(i < nrLines);
	lineStart = i;
	for(i = nrLines-1; i >=0;i--) {
		/* mark not initialized */
		if (!IS_MV_REAL4(&(l[i].start.f)))
			break;
	}
	POSTCOND(i >= 0);
	lineEndIncl = i;
	
	for (i=lineStart ; i <= lineEndIncl; i++) {
		PRECOND(!IS_MV_REAL4(&(l[i].start.f)));
		l[i].start.i = (int)Rint(l[i].start.f);
		l[i].end.i   = (int)Rint(l[i].end.f);
	}
	return 1;
}
Ejemplo n.º 4
0
Side Side::oppositeSide() const
{
  switch (val) {
  case LEFT:
    return Side(RIGHT);
  case RIGHT:
    return Side(LEFT);
  default:
    throw std::runtime_error("should not get here");
  }
}
Ejemplo n.º 5
0
void stage3_init(Rubiks &now)
{
    for (int i = 0; i < 6; i++) {
        if (now.data[i][1][1] == White)
        {
            now.change_vp(Side(i), Side((i+2)%6));
            now.FtoU();
            return ;
        }
    }
}
Ejemplo n.º 6
0
status_t
PAP::Receive(net_buffer *packet, uint16 protocolNumber)
{
	if (!packet)
		return B_ERROR;

	if (protocolNumber != PAP_PROTOCOL)
		return PPP_UNHANDLED;

	NetBufferHeaderReader<ppp_lcp_packet> bufferheader(packet);
	if (bufferheader.Status() != B_OK)
		return B_ERROR;
	ppp_lcp_packet &data = bufferheader.Data();

	// check if the packet is meant for us:
	// only peer authenticators handle requests
	if (data.code == PPP_CONFIGURE_REQUEST && Side() != PPP_PEER_SIDE)
		return PPP_UNHANDLED;
	// only local authenticators handle acks and naks
	if ((data.code == PPP_CONFIGURE_ACK || data.code == PPP_CONFIGURE_NAK)
			&& Side() != PPP_LOCAL_SIDE)
		return PPP_UNHANDLED;

	// remove padding
	int32 length = packet->size;
	length -= ntohs(data.length);

	if (ntohs(data.length) < 4)
		return B_ERROR;

	// packet is freed by event methods
	// code values are the same as for LCP (but very reduced)
	switch (data.code) {
		case PPP_CONFIGURE_REQUEST:
			RREvent(packet);
		break;

		case PPP_CONFIGURE_ACK:
			RAEvent(packet);
		break;

		case PPP_CONFIGURE_NAK:
			RNEvent(packet);
		break;

		default:
			return PPP_UNHANDLED;
	}

	return B_OK;
}
Ejemplo n.º 7
0
void HuobiApp::submitLimitOrder(const char *symbol, OrderSide side, double price, double amount, const char *userId)
{
    int ts = timestamp();
    FIX44::NewOrderSingle message;
    message.set(Account(_publicKey));
    if (userId)
        message.set(ClOrdID(userId));
    else
        message.set(ClOrdID("HuobiOrder"));
    message.set(Price(price));
    message.set(MinQty(amount));
    message.set(OrdType(OrdType_LIMIT));
    message.set(Symbol(symbol));
    message.set(Side(side == OrderBuy ? Side_BUY : Side_SELL));
    message.set(TransactTime());
    message.setField(IntField(957, ts));
    message.setField(StringField(958, _publicKey));
    char str[1024];
    sprintf(str, "access_key=%s&amount=%s&coin_type=%d&created=%d&method=%s&price=%s&secret_key=%s",
            _publicKey.c_str(),
            float2str(amount).c_str(),
            getCoinType(symbol),
            ts,
            side == OrderBuy ? "buy" : "sell",
            float2str(price).c_str(),
            _privateKey.c_str());
    message.setField(StringField(959, md5::MD5String(str, false)));
    Session *session = Session::lookupSession(_sessionID);
    if (session)
        session->send(message);
}
Ejemplo n.º 8
0
Box<Dimensions> Box<Dimensions>::ZeroOrigin( typename ImageTypes<Dimensions>::Size sz )
{
    Box<Dimensions> rv;
    for (int i = 0; i < Dimensions; ++i)
        rv.sides[i] = Side( 0 * camera::pixel, sz[i] - 1 * camera::pixel );
    return rv;
}
Ejemplo n.º 9
0
RelativePosition
Side(ContourEQW& a, ContourEQW& b)
{
	RelativePosition rp = UndeterminedSide;
	for(int i=0; i<a.size(); ++i)
	{
		float th = a.Orientation(i);
		float x = a.X[i];
		float y = a.Y[i];
		for(int j=0; j<b.size(); ++j)
		{
			float x2 = b.X[j];
			float y2 = b.Y[j];
			float th2 = atan2(y2-y, x2-x);
			RelativePosition rp2 = Side(th, th2);
			if(rp == UndeterminedSide)
			{
				rp = rp2;
			}
			else if(rp != rp2)
			{
				return UndeterminedSide;
			}
		}
	}
	return rp;
}
Ejemplo n.º 10
0
static Side crosside (BoxRegion  &region, BoxPoint &p)
{
    BoxPoint center = region.origin() + (region.space() / BoxPoint(2)) ;
    BoxPoint delta = center  - p ;
	
    int side = North | South | East | West ;
    
    // exclude opposite side
    
    if (p[X] > center[X]) 
	side &= ~West ;
    else
	side &= ~East ;
    if (p[Y] > center[Y])
	side &= ~North ;
    else
	side &= ~South ;
    
    delta[X] = abs(delta[X]);
    delta[Y] = abs(delta[Y]);
    
    if (region.space(Y) * delta[X] > region.space(X) * delta[Y]) 
	side &= ~(North | South);
    else
	side &= ~(East | West);
    
    return Side(side);
}
Ejemplo n.º 11
0
void BarrierRect::calcSides(){ //mpSides can be list either
    //left
    PntR2 p(mGlobalVertex.mX - mL, mGlobalVertex.mY);
    PntR2 v((GLfloat)0.0f, mH);
    mpSides[0] = Side(p, v);
    //top
    p = PntR2(mGlobalVertex.mX - mL, mGlobalVertex.mY + mH);
    v = PntR2(mL, (GLfloat)0.0f);
    mpSides[1] = Side(p, v);
    //bottom
    p = PntR2(mGlobalVertex.mX - mL, mGlobalVertex.mY);
    v = PntR2(mL, (GLfloat)0.0f);
    mpSides[2] = Side(p, v);
    //right
    p = PntR2(mGlobalVertex.mX, mGlobalVertex.mY);
    v = PntR2((GLfloat)0.0f, mH);
    mpSides[3] = Side(p, v);
}
Ejemplo n.º 12
0
void
PAP::NewState(pap_state next)
{
	TRACE("PAP: NewState(%d) state=%d\n", next, State());

	//  state changes
	if (State() == INITIAL && next != State()) {
		if (Side() == PPP_LOCAL_SIDE)
			Interface().StateMachine().LocalAuthenticationRequested();
		else if (Side() == PPP_PEER_SIDE)
			Interface().StateMachine().PeerAuthenticationRequested();

		UpStarted();
	} else if (State() == ACCEPTED && next != State())
		DownStarted();

	// maybe we do not need the timer anymore
	if (next == INITIAL || next == ACCEPTED)
		fNextTimeout = 0;

	fState = next;
}
Ejemplo n.º 13
0
static int BuildCircle(REAL8 radius)
{
	int i,nrLines,xFloor;
	REAL8 xIncr,lineStart,lineEndIncl;
	HOR_CUT_LINE *l;
	PRECOND(radius != 0);
	radius /= (Side()*2);

	xFloor = (size_t)floor(radius);
	radius *= radius;
	nrLines = (xFloor*2)+1;
	l = (HOR_CUT_LINE *)ChkMalloc(sizeof(HOR_CUT_LINE)*nrLines);
	for(i=0; i < nrLines; i++) {
		/* mark not initialized */
		SET_MV_REAL4(&(l[i].start.f));
	}

	for (xIncr = 0; xIncr <= xFloor; xIncr+=1) {
	 REAL8 y = floor(sqrt(radius-sqr(xIncr))); 
	 Add2Lines(l,nrLines,xFloor,1,0, xIncr, y);
	 Add2Lines(l,nrLines,xFloor,1,0, xIncr,-y);
	 Add2Lines(l,nrLines,xFloor,1,0,-xIncr, y);
	 Add2Lines(l,nrLines,xFloor,1,0,-xIncr,-y);
	}
	for(i=0; i < nrLines; i++) {
		/* mark not initialized */
		if (!IS_MV_REAL4(&(l[i].start.f)))
			break;
	}
	POSTCOND(i < nrLines);
	lineStart = i;
	for(i = nrLines-1; i >=0;i--) {
		/* mark not initialized */
		if (!IS_MV_REAL4(&(l[i].start.f)))
			break;
	}
	POSTCOND(i >= 0);
	lineEndIncl = i;
	
	for (i=(int)lineStart ; i <= (int)lineEndIncl; i++) {
		PRECOND(!IS_MV_REAL4(&(l[i].start.f)));
		l[i].start.i = (int)Rint(l[i].start.f);
		l[i].end.i   = (int)Rint(l[i].end.f);
	}
	return 1;
}
Ejemplo n.º 14
0
void OkcoinApp::submitMarketOrder(const char *symbol, OrderSide side, double amount, const char *userId)
{
    int ts = timestamp();
    FIX44::NewOrderSingle message;
    message.set(Account(_publicKey + "," + _privateKey));
    if (userId)
        message.set(ClOrdID(userId));
    else
        message.set(ClOrdID("OkcoinOrder"));
    message.set(Price(amount));
    message.set(OrderQty(amount));
    message.set(OrdType(OrdType_MARKET));
    message.set(Symbol(symbol));
    message.set(Side(side == OrderBuy ? Side_BUY : Side_SELL));
    message.set(TransactTime());
    Session *session = Session::lookupSession(_sessionID);
    if (session)
        session->send(message);
}
Ejemplo n.º 15
0
// LOAD
void loadBlockData(ifstream& file, GridBlock* gb)
{
	char cont;
	file >> cont;	
	int v[7];
	file >> v[6];
	gb->setGround(Object::create(ObjType(GROUND), v[6]));
	
	for(file >> cont; !file.eof() && cont != 'g'; file >> cont){
		if(cont == 'o'){
			file >> v[0];		// modelType
			file >> v[1];		// objType
			file >> v[6];		// index
			if(v[0] == CONST_MODEL)
				gb->addObject(Object::create(ObjType(v[1]), v[6]));
			else if(v[0] == SIDE_MODEL){
				file >> v[2];	// side
				gb->addObject(SideObject::create(ObjType(v[1]), Side(v[2]), v[6]));
			}
			else{
Ejemplo n.º 16
0
/*!	\brief Allows private extensions.
	
	If you override this method you must call the parent's method for unknown ops.
*/
status_t
KPPPProtocol::Control(uint32 op, void *data, size_t length)
{
	switch (op) {
		case PPPC_GET_PROTOCOL_INFO:
		{
			if (length < sizeof(ppp_protocol_info_t) || !data)
				return B_ERROR;
			
			ppp_protocol_info *info = (ppp_protocol_info*) data;
			memset(info, 0, sizeof(ppp_protocol_info_t));
			if (Name())
				strncpy(info->name, Name(), PPP_HANDLER_NAME_LENGTH_LIMIT);
			if (Type())
				strncpy(info->type, Type(), PPP_HANDLER_NAME_LENGTH_LIMIT);
			info->activationPhase = ActivationPhase();
			info->addressFamily = AddressFamily();
			info->flags = Flags();
			info->side = Side();
			info->level = Level();
			info->overhead = Overhead();
			info->connectionPhase = fConnectionPhase;
			info->protocolNumber = ProtocolNumber();
			info->isEnabled = IsEnabled();
			info->isUpRequested = IsUpRequested();
			break;
		}

		case PPPC_ENABLE:
			if (length < sizeof(uint32) || !data)
				return B_ERROR;
			
			SetEnabled(*((uint32*)data));
			break;

		default:
			return B_BAD_VALUE;
	}
	
	return B_OK;
}
Ejemplo n.º 17
0
/* computes the number of pixelss surrounding
 * the current pixel that must 
 * be analyzed 
 */
static int DetWindow(
	REAL8 *bw, /* write-only, border weight, 0 if border pixel are
	            * compeltely covered by window
	            */
	REAL8 winSize) /* window size */
{
	double Floor;
	PRECOND(winSize > 0);
	winSize /= Side();
	if (winSize <= 1)
	{
		*bw = winSize;
		return 0;
	}
	winSize *= 0.5;
	winSize -= 0.5;
	*bw = modf(winSize, &Floor);
	if (*bw == 1)
		*bw = 0;
	return (int)ceil(winSize);
}
Ejemplo n.º 18
0
void HuobiApp::requestOrderStatus(const char *symbol, const char *orderId, OrderSide side)
{
    int ts = timestamp();
    FIX44::OrderStatusRequest message;
    message.set(Account(_publicKey));
    message.set(ClOrdID(orderId));
    message.set(Symbol(symbol));
    message.set(Side(side == OrderBuy ? Side_BUY : Side_SELL));
    message.setField(IntField(957, ts));
    message.setField(StringField(958, _publicKey));
    char str[1024];
    sprintf(str, "access_key=%s&coin_type=%d&created=%d&id=%s&method=order_info&secret_key=%s",
            _publicKey.c_str(),
            getCoinType(symbol),
            ts,
            orderId,
            _privateKey.c_str());
    message.setField(StringField(959, md5::MD5String(str, false)));
    Session *session = Session::lookupSession(_sessionID);
    if (session)
        session->send(message);
}
Ejemplo n.º 19
0
/* Check whether segment P0P1 intersects with triangle t0t1t2 */
int Intersecting(ofVec3f &p0, ofVec3f &p1, ofVec3f &t0, ofVec3f &t1, ofVec3f &t2)
{
    /* Check whether segment is outside one of the three half-planes
     * delimited by the triangle. */
    float f1 = Side(p0, t2, t0, t1), f2 = Side(p1, t2, t0, t1);
    float f3 = Side(p0, t0, t1, t2), f4 = Side(p1, t0, t1, t2);
    float f5 = Side(p0, t1, t2, t0), f6 = Side(p1, t1, t2, t0);
    /* Check whether triangle is totally inside one of the two half-planes
     * delimited by the segment. */
    float f7 = Side(t0, t1, p0, p1);
    float f8 = Side(t1, t2, p0, p1);
    
    /* If segment is strictly outside triangle, or triangle is strictly
     * apart from the line, we're not intersecting */
    if ((f1 < 0 && f2 < 0) || (f3 < 0 && f4 < 0) || (f5 < 0 && f6 < 0)
        || (f7 > 0 && f8 > 0))
        return 0;
    
    /* If segment is aligned with one of the edges, we're overlapping */
    if ((f1 == 0 && f2 == 0) || (f3 == 0 && f4 == 0) || (f5 == 0 && f6 == 0))
        return 2;
    
    /* If segment is outside but not strictly, or triangle is apart but
     * not strictly, we're touching */
    if ((f1 <= 0 && f2 <= 0) || (f3 <= 0 && f4 <= 0) || (f5 <= 0 && f6 <= 0)
        || (f7 >= 0 && f8 >= 0))
        return 2; // Touching.
    
    /* If both segment points are strictly inside the triangle, we
     * are not intersecting either */
    if (f1 > 0 && f2 > 0 && f3 > 0 && f4 > 0 && f5 > 0 && f6 > 0)
        return 0;
    
    /* Otherwise we're intersecting with at least one edge */
    return 1;
}
Ejemplo n.º 20
0
RelativePosition
FrontBack(ContourEQW& a, ContourEQW& b)
{
	RelativePosition rp = UndeterminedSide;
	float eps = 1.0e-6;
	for(int i=0; i<a.size(); ++i)
	{
		float th = a.Orientation(i);
		float x = a.X[i];
		float y = a.Y[i];
		for(int j=0; j<b.size(); ++j)
		{
			float x2 = b.X[j];
			float y2 = b.Y[j];
			if(Abs(y2-y)<eps && Abs(x2-x)<eps) continue;

			float th2 = atan2(y2-y, x2-x);
			RelativePosition rp2 = Side(th, th2);
			if(rp == UndeterminedSide)
			{
				rp = rp2;
				continue;
			}
			else if(rp2 == FrontSide || rp2 == BackSide)
			{
				if(rp != rp2)
				{
					return UndeterminedSide;
				}
			}
			else
			{
				return UndeterminedSide; //neither front nor back
			}
		}
	}
	return rp;
}
Ejemplo n.º 21
0
  Vertex4 normal;

  Side( int i0, int i1, int i2, int i3, Vertex4 v )
   : normal(v)
  {
    vidx[0] = i0;
    vidx[1] = i1;
    vidx[2] = i2;
    vidx[3] = i3;
  }

};

static Side side[6] = {
  // BACK
  Side(0, 2, 3, 1, Vertex4( 0.0f, 0.0f,-1.0f, 0.0f) ),

  // FRONT
  Side(4, 5, 7, 6, Vertex4( 0.0f, 0.0f, 1.0f, 0.0f) ),

  // LEFT
  Side(4, 6, 2, 0, Vertex4(-1.0f, 0.0f, 0.0f, 0.0f) ),

  // RIGHT
  Side(5, 1, 3, 7, Vertex4( 1.0f, 0.0f, 0.0f, 0.0f) ),

  // BOTTOM
  Side(0, 1, 5, 4, Vertex4( 0.0f,-1.0f, 0.0f, 0.0f) ),

  // TOP
  Side(6, 7, 3, 2, Vertex4( 0.0f, 1.0f, 0.0f, 0.0f) )
Ejemplo n.º 22
0
int IBNGauss(
     MAP_REAL8 *out,
     const MAP_REAL8 *units,
     const MAP_REAL8 *range,
     const MAP_REAL8 *nrPackages)
{
  int   rSrc,nrRows= units->NrRows(units);
  int   cSrc,nrCols= units->NrCols(units);
  REAL8 unitsValSrc,rangeValSrc,nrPackValSrc;

  /* algorithm wants points->Get() and all others to
   * return FALSE if a value is a missing value
   */
  out->SetGetTest(GET_MV_TEST, out);
  units->SetGetTest(GET_MV_TEST, units);
  nrPackages->SetGetTest(GET_MV_TEST, nrPackages);
  range->SetGetTest(GET_MV_TEST, range);

  /* set all to 0 or MV
   * check range of rangeValSrc
   */
  for(rSrc = 0; rSrc < nrRows; rSrc++)
   for(cSrc = 0; cSrc < nrCols; cSrc++)
   {
    if(units->Get(&unitsValSrc, rSrc, cSrc, units) &&
       nrPackages->Get(&nrPackValSrc, rSrc, cSrc, nrPackages) &&
       range->Get(&rangeValSrc, rSrc, cSrc, range))
    { /* init with remainder */
      REAL8 remainder = unitsValSrc - floor(unitsValSrc);
      out->Put(remainder, rSrc, cSrc, out);
      if (rangeValSrc < 0)
       return  RetError(1,"ibngauss: Domain error on parameters");
    } else /* some of the units maps are MV */
      out->PutMV(rSrc, cSrc, out);
   }


  for(rSrc = 0; rSrc < nrRows; rSrc++)
   for(cSrc = 0; cSrc < nrCols; cSrc++)
    if(units->Get(&unitsValSrc, rSrc, cSrc, units) &&
       nrPackages->Get(&nrPackValSrc, rSrc, cSrc, nrPackages) &&
       range->Get(&rangeValSrc, rSrc, cSrc, range)
      )
    {
      int i,nrInputUnits = (int)floor(unitsValSrc);
      int nrPackages = (int)nrPackValSrc; /* round to integer */
      int packageSize;
      int nrPackagesWithOneMore;
      if (nrPackages <= 0 || nrPackages > nrInputUnits) {
        nrPackages=nrInputUnits;
        packageSize=1;
        nrPackagesWithOneMore=0;
      }
      else {
        packageSize=nrInputUnits/nrPackages;          /* integer division */
        nrPackagesWithOneMore= nrInputUnits%nrPackages; /* integer modulo */
      }
      rangeValSrc /= Side(); /* transform to pixel lengths */
       for(i=0; i < nrPackages; i++) {
         /* GasDev returns value from normal distribution mean=0,sd=1 */
          REAL8 length = GasDev()*rangeValSrc;
         /* Ran() return an uniform number
          * we create an angle between 0 and 180 degrees
          */
          REAL8 angle =Ran()*M_PI;
         /* now since length can be negative or positive we
          * generate a receiving cell address having an angle
          * with the src cell between 0 and 360 degrees
          */
          int xColDest = cSrc+(int)(length*cos(angle));
          int yRowDest = rSrc+(int)(length*sin(angle));
          REAL8 valDest;
          if (out->Get(&valDest, yRowDest, xColDest, out)) {
            /* destination is defined area */
            valDest+=packageSize;
           if (i < nrPackagesWithOneMore) {
             /* the first nrPackagesWithOneMore package do 1 more */
             valDest+=1;
           }
           out->Put(valDest, yRowDest, xColDest, out);
          }
       } /* for all packages */
    } /* eo for all cells */
  return 0;    /* successful terminated */
}
double area_tet(tetrahedron T)
{
    double area = 0;
    for(int i=0; i<4; i++) area = area + Area(Side(T,i));
    return area;
}
Ejemplo n.º 24
0
void
IPCP::UpdateAddresses()
{
	RemoveRoutes();
	
	if(State() != PPP_OPENED_STATE && !Interface().DoesConnectOnDemand())
		return;
	
	struct in_aliasreq inreq;
	struct ifreq ifreqAddress, ifreqDestination;
	memset(&inreq, 0, sizeof(struct in_aliasreq));
	memset(&ifreqAddress, 0, sizeof(struct ifreq));
	memset(&ifreqDestination, 0, sizeof(struct ifreq));
	memset(&fGateway, 0, sizeof(struct sockaddr_in));
	
	// create local address
	inreq.ifra_addr.sin_family = AF_INET;
	if(fLocalRequests.address != INADDR_ANY)
		inreq.ifra_addr.sin_addr.s_addr = fLocalRequests.address;
	else if(fLocalConfiguration.address == INADDR_ANY)
		inreq.ifra_addr.sin_addr.s_addr = 0x010F0F0F; // was: INADDR_BROADCAST
	else
		inreq.ifra_addr.sin_addr.s_addr = fLocalConfiguration.address;
	inreq.ifra_addr.sin_len = sizeof(struct sockaddr_in);
	memcpy(&ifreqAddress.ifr_addr, &inreq.ifra_addr, sizeof(struct sockaddr_in));
	
	// create destination address
	fGateway.sin_family = AF_INET;
	if(fPeerRequests.address != INADDR_ANY)
		fGateway.sin_addr.s_addr = fPeerRequests.address;
	else if(fPeerConfiguration.address == INADDR_ANY)
		fGateway.sin_addr.s_addr = 0x020F0F0F; // was: INADDR_BROADCAST
	else
		fGateway.sin_addr.s_addr = fPeerConfiguration.address;
	fGateway.sin_len = sizeof(struct sockaddr_in);
	memcpy(&inreq.ifra_dstaddr, &fGateway,
		sizeof(struct sockaddr_in));
	memcpy(&ifreqDestination.ifr_dstaddr, &inreq.ifra_dstaddr,
		sizeof(struct sockaddr_in));
	
	// create netmask
	inreq.ifra_mask.sin_family = AF_INET;
	inreq.ifra_mask.sin_addr.s_addr = fLocalRequests.netmask;
	inreq.ifra_mask.sin_len = sizeof(struct sockaddr_in);
	
	// tell stack to use these values
	if(in_control(NULL, SIOCAIFADDR, (caddr_t) &inreq,
			Interface().Ifnet()) != B_OK)
		ERROR("IPCP: UpdateAddress(): SIOCAIFADDR returned error!\n");
	if(in_control(NULL, SIOCSIFADDR, (caddr_t) &ifreqAddress,
			Interface().Ifnet()) != B_OK)
		ERROR("IPCP: UpdateAddress(): SIOCSIFADDR returned error!\n");
	if(in_control(NULL, SIOCSIFDSTADDR, (caddr_t) &ifreqDestination,
			Interface().Ifnet()) != B_OK)
		ERROR("IPCP: UpdateAddress(): SIOCSIFDSTADDR returned error!\n");
	memcpy(&inreq.ifra_addr, &inreq.ifra_mask, sizeof(struct sockaddr_in));
		// SIOCISFNETMASK wants the netmask to be in ifra_addr
	if(in_control(NULL, SIOCSIFNETMASK, (caddr_t) &inreq,
			Interface().Ifnet()) != B_OK)
		ERROR("IPCP: UpdateAddress(): SIOCSIFNETMASK returned error!\n");
	
	// add default/subnet route
	if(Side() == PPP_LOCAL_SIDE) {
		if(rtrequest(RTM_ADD, (struct sockaddr*) &inreq.ifra_mask,
				(struct sockaddr*) &fGateway, (struct sockaddr*) &inreq.ifra_mask,
				RTF_UP | RTF_GATEWAY, &fDefaultRoute) != B_OK)
			ERROR("IPCP: UpdateAddress(): could not add default/subnet route!\n");
		
		--fDefaultRoute->rt_refcnt;
	}
}
Ejemplo n.º 25
0
void Box<Dimensions>::set_range(Span lower, Span upper, Direction dir) 
    { sides[dir] = Side( lower, upper ); }
Ejemplo n.º 26
0
BarrierRect::BarrierRect():mGlobalVertex(), mL(0), mH(0){
    mpGL4Vertices = NULL;
    for (int i=0; i<SZS; i++){
        mpSides[i] = Side();
    }
}
Ejemplo n.º 27
0
Box<Dimensions>::Box( Position lower, Position upper )
{
    for (int i = 0; i < Dimensions; ++i)
        sides[i] = Side( lower[i], upper[i] );
}
Ejemplo n.º 28
0
	void HWLight::SetView(const std::vector<Vector3D> &frustum)
	{
		if (Directionnal)
		{
			Vector3D Side(0.0f, 1.0f, 0.0f);
			Vector3D Up(Side * Dir);
			Up.unit();
			Side = Dir * Up;
			Side.unit();

			float mx = 0.0f, Mx = 0.0f;
			float my = 0.0f, My = 0.0f;
			float mz = 0.0f, Mz = 0.0f;
			for (unsigned int i = 0; i < frustum.size(); i++)
			{
				float X = frustum[i] % Side;
				float Z = frustum[i] % Dir;
				float Y = frustum[i] % Up;
				if (i == 0)
				{
					mx = Mx = X;
					my = My = Y;
					mz = Mz = Z;
				}
				else
				{
					mx = Math::Min(mx, X);
					Mx = Math::Max(Mx, X);
					my = Math::Min(my, Y);
					My = Math::Max(My, Y);
					mz = Math::Min(mz, Z);
					Mz = Math::Max(Mz, Z);
				}
			}
			Vector3D c_pos(Mz * Dir + 0.5f * (mx + Mx) * Side + 0.5f * (my + My) * Up);

			const float zfar = Mz - mz;
			const float znear = -128.0f;
			const float widthFactor = (Mx - mx) / (My - my);
			const float f = 0.5f * (My - my);

			glMatrixMode (GL_PROJECTION);
			glLoadIdentity ();
			glOrtho(-widthFactor * f, widthFactor * f, -f, f, znear, zfar);

			Vector3D c_at(c_pos - Dir);
			gluLookAt(c_pos.x, c_pos.y, c_pos.z, c_at.x, c_at.y, c_at.z, Up.x, Up.y, Up.z);

			glMatrixMode(GL_MODELVIEW);
			glLoadIdentity();
		}
		else
		{
			float zfar = 1000.0f;
			float znear = 0.01f;
			float widthFactor = 1.0f;
			//float f = 10.0f;

			glMatrixMode (GL_PROJECTION);
			glLoadIdentity ();
			glFrustum(-widthFactor * znear, widthFactor * znear, -0.75f * znear, 0.75f * znear, znear, zfar);

			Vector3D Up(Pos * Dir);
			Up.unit();
			gluLookAt(Pos.x, Pos.y, Pos.z, Dir.x, Dir.y, Dir.z, Up.x, Up.y, Up.z);

			glMatrixMode(GL_MODELVIEW);
			glLoadIdentity();
		}
	}