Пример #1
0
void Notebook::selectPage(int n) {
	if(pages.size()>0 && n>=0 && n<(int)pages.size() && n!=selected) {
		NotebookPage *np;
		if(selected>=0) {
			np = (NotebookPage *)pages[selected];
			if(event_handler) event_handler(this,NOTEBOOK_PAGE_HIDE,(intptr_t)np->page,np->tab.index,(intptr_t)np->tab.name);
#ifdef USE_WIN32
			np->page->hide();
#endif
		}
#ifdef USE_GTK
debug_output("Notebook::selectPage((index: %d)\n",n);
		np = (NotebookPage *)pages[n];
		if(event_handler) event_handler(this,NOTEBOOK_PAGE_SHOW,(intptr_t)np->page,np->tab.index,(intptr_t)np->tab.name);
		gtk_notebook_set_current_page(GTK_NOTEBOOK(component),n);
		selected = n;
#endif
#ifdef USE_WIN32
		if(type==WIDGET_NOTEBOOK) TabCtrl_SetCurSel((HWND)component,n);
		np = (NotebookPage *)pages[n];
debug_output("Notebook::selectPage(action: %d, tab: %s, width: %ld, height: %ld)\n",NOTEBOOK_PAGE_SHOW,np->tab.name,client.right-client.left,client.bottom-client.top);
		selected = n;
		ShowWindow((HWND)np->page->getComponent(),SW_SHOW);
		if(np->status==1) {
			makeLayout(client.left,client.top,client.right-client.left,client.bottom-client.top);
			np->page->move();
			np->status = 0;
		}
//		BringWindowToTop((HWND)np->page->component);
//		InvalidateRect((HWND)np->page->component,0,false);
//		UpdateWindow((HWND)np->page->component);
		if(event_handler) event_handler(this,NOTEBOOK_PAGE_SHOW,(intptr_t)np->page,np->tab.index,(intptr_t)np->tab.name);
#endif
	}
}
Пример #2
0
int Notebook::openPage(NotebookPage *np,bool sel) {
	np->tab.index = pages.size();
	pages << np;
	np->page->parent = this;
debug_output("Notebook::openPage(page->create(%s))\n",np->page->getInstance().getName());
	np->page->create(window,0);
	np->page->createAll(0,false);
#ifdef USE_GTK
	GtkWidget *t;
	if((style&NOTEBOOK_CLOSE_BUTTON)) {
		GValue val = { 0 };
		int w,h;
		GtkWidget *bt,*im,*l;

		t = gtk_hbox_new(FALSE,3);
		l = gtk_label_new(np->tab.name);

		bt = gtk_button_new();
		gtk_widget_set_name(bt,"tab-close-button");
		g_value_init(&val,G_TYPE_INT);
		g_value_set_int(&val,GTK_RELIEF_NONE); 
		g_object_set_property(G_OBJECT(bt),"relief",&val);
		g_value_unset(&val);
		im = gtk_image_new_from_stock(GTK_STOCK_CLOSE,GTK_ICON_SIZE_MENU);
		gtk_icon_size_lookup(GTK_ICON_SIZE_MENU,&w,&h);
		gtk_widget_set_size_request(bt,w+2,h+2);
		gtk_container_add(GTK_CONTAINER(bt),im);
		g_signal_connect(G_OBJECT(bt),"clicked",G_CALLBACK(close_tab_callback),(gpointer)&np->tab);
		gtk_box_pack_start(GTK_BOX(t),l,TRUE,TRUE,0);
		gtk_box_pack_start(GTK_BOX(t),bt,FALSE,FALSE,0);

		np->tab.button = bt;
		np->tab.label = l;

		gtk_widget_show_all(t);
	} else {
		t = gtk_label_new(np->tab.name);
	}
	gtk_widget_show_all(t);
	np->page->show();
	gtk_notebook_append_page(GTK_NOTEBOOK(component),(GtkWidget *)np->page->getComponent(),t);
#endif
#ifdef USE_WIN32
	np->status = 1;
//	SetParent((HWND)page->getComponent(),(HWND)parent->getComponent());
debug_output("Notebook::openPage(%s)\n",np->tab.name);
	if(type==WIDGET_NOTEBOOK) {
		TCITEM ti = {TCIF_TEXT};
		ti.pszText = tstrdup(np->tab.name);
		TabCtrl_InsertItem((HWND)component,np->tab.index,&ti);
		tfree(ti.pszText);
	}
#endif
	if(sel) selectPage(np->tab.index);
	return selected;
}
Пример #3
0
Trail *Path::searchPath(void *o,int x1,int y1,int x2,int y2,int l) {
	int i,d,x,y,c;
	PathNode *p1 = 0,*p2 = 0;
debug_output("Path::searchPath(x1=%d,y1=%d,x2=%d,y2=%d)\n",x1,y1,x2,y2);

	clear();

	obj = o,sx = x1,sy = y1,dx = x2,dy = y2;
	if(sx==dx && sy==dy) return 0;

debug_output("Path::searchPath(x1=%d,y1=%d,x2=%d,y2=%d)\n",x1,y1,x2,y2);
	cap = heur(*this,sx,sy)*8+1;
	p1 = new PathNode(sx,sy,0,heur(*this,sx,sy),0);
	closest = p1;
	put(p1);
	push(p1);

debug_output("Path::searchPath(x1=%d,y1=%d,x2=%d,y2=%d)\n",x1,y1,x2,y2);

	while(open) {
		if(step) step(*this,*open);
		p1 = pop();
debug_output("key=%08x\tx1=%d\ty1=%d\tx2=%d\ty2=%d\ts=%d\tg=%d\th=%d\n",p1->key,p1->x,p1->y,
p1->parent? p1->parent->x : -1,p1->parent? p1->parent->y : -1,p1->s,p1->g,p1->h);
		if(!l || p1->s<l) for(i=0,d=0; d!=-1; ++i) {
			d = move(*this,*p1,x,y,i);
			c = weight(*this,*p1,x,y);
			if(x==dx && y==dy) {
				if(c!=PATH_CANNOT_MOVE) {
					p1 = new PathNode(x,y,p1->g+1,0,p1);
					closest = p1;
					put(p1);
				}
				goto finished;
			} else if(c!=PATH_CANNOT_MOVE && c!=PATH_AVOID_MOVE) {
				if((p2=get(x,y))) {
					if(p1->g+c<p2->g) {
						remove(p2);
						p2->parent = p1,p2->g = p1->g+c,p2->s = p1->s+1;
						push(p2);
					}
				} else {
					p2 = new PathNode(x,y,p1->g+c,heur(*this,x,y),p1);
					if(p2->h<closest->h || (p2->h==closest->h && p2->g<closest->g)) closest = p2;
					put(p2);
					push(p2);
				}
			}
		}
	}

finished:

	return getTrail(closest);
}
Пример #4
0
void panic(u8 v)
{
	while(1) {
		debug_output(v);
		set32(HW_GPIO1BOUT, GP_SLOTLED);
		udelay(500000);
		debug_output(0);
		clear32(HW_GPIO1BOUT, GP_SLOTLED);
		udelay(500000);
	}
}
Пример #5
0
void exec_iptables_rule(char *cmd, int8_t route_action) {
	if (disable_client_nat)
		return;

	if (nat_tool_avail == -1) {
		debug_output(3, "Warning - could not %sactivate NAT: iptables binary not found!\n", (route_action == ROUTE_ADD ? "" : "de"));
		debug_output(3, "          You may need to run this command: %s\n", cmd);
		return;
	}

	run_cmd(cmd);
}
Пример #6
0
void Notebook::create(Window *wnd,uint32_t st) {
	if(style&NOTEBOOK_HIDE_TABS) {
		style &= ~NOTEBOOK_CLOSE_BUTTON;
		type = WIDGET_CONTAINER;
	}

#ifdef USE_GTK
	component = gtk_notebook_new();

	if(style&NOTEBOOK_HIDE_TABS) {
		gtk_notebook_set_show_tabs(GTK_NOTEBOOK(component),FALSE);
	} else {
		gtk_notebook_set_show_border(GTK_NOTEBOOK(component),FALSE);
		gtk_notebook_set_scrollable(GTK_NOTEBOOK(component),TRUE);
		gtk_notebook_set_tab_border(GTK_NOTEBOOK(component),3);
		gtk_notebook_set_tab_pos(GTK_NOTEBOOK(component),GTK_POS_TOP);

		g_signal_connect(G_OBJECT(component),"switch-page",G_CALLBACK(switch_page_event_callback),&selected);
	}
#endif
debug_output("Notebook::create()\n");
	Widget::create(wnd,0);

#ifdef USE_WIN32
	captureEvents();
#endif
}
Пример #7
0
void tfe_arch_transmit(int force,       /* FORCE: Delete waiting frames in transmit buffer */
                       int onecoll,     /* ONECOLL: Terminate after just one collision */
                       int inhibit_crc, /* INHIBITCRC: Do not append CRC to the transmission */
                       int tx_pad_dis,  /* TXPADDIS: Disable padding to 60 Bytes */
                       int txlength,    /* Frame length */
                       BYTE *txframe    /* Pointer to the frame to be transmitted */
                      )
{
#ifdef TFE_DEBUG_ARCH
    if(g_fh) fprintf( g_fh, "tfe_arch_transmit() called, with: "
                          "force = %s, onecoll = %s, inhibit_crc=%s, tx_pad_dis=%s, txlength=%u",
                          force ?       "TRUE" : "FALSE",
                          onecoll ?     "TRUE" : "FALSE",
                          inhibit_crc ? "TRUE" : "FALSE",
                          tx_pad_dis ?  "TRUE" : "FALSE",
                          txlength
                        );
#endif

#ifdef TFE_DEBUG_PKTDUMP
    debug_output( "Transmit frame: ", txframe, txlength);
#endif // #ifdef TFE_DEBUG_PKTDUMP

    if ((*p_pcap_sendpacket)(TfePcapFP, txframe, txlength) == -1) {
        if(g_fh) fprintf(g_fh, "WARNING! Could not send packet!");
    }
}
Пример #8
0
NotebookPage *Notebook::getPage(int n) {
debug_output("Notebook::getPage(n: %d, pages: %d, selected: %d)\n",n,(int)pages.size(),selected);
	if(n<0 || n>=(int)pages.size()) n = selected;
	if(pages.size()>0)
		return (NotebookPage *)pages[n];
	return 0;
}
Пример #9
0
int8_t set_tun_addr( int32_t fd, uint32_t tun_addr, char *tun_dev ) {

	struct sockaddr_in addr;
	struct ifreq ifr_tun;


	memset( &ifr_tun, 0, sizeof(ifr_tun) );
	memset( &addr, 0, sizeof(addr) );

	addr.sin_addr.s_addr = tun_addr;
	addr.sin_family = AF_INET;
	memcpy( &ifr_tun.ifr_addr, &addr, sizeof(struct sockaddr) );

	strncpy( ifr_tun.ifr_name, tun_dev, IFNAMSIZ - 1 );

	if ( ioctl( fd, SIOCSIFADDR, &ifr_tun) < 0 ) {

		debug_output( 0, "Error - can't set tun address (SIOCSIFADDR): %s\n", strerror(errno) );
		return -1;

	}

	return 1;

}
Пример #10
0
Trail *Path::getTrail(PathNode *n) {
	Trail *t = 0;
	if(n) {
		int i,x,y;
		PathNode *p1 = 0,*p2 = 0;

char mem[height][width];memset(mem,' ',width*height);
for(y=0; y<height; ++y) for(x=0; x<width; ++x) if(get(x,y)) mem[y][x] = '+';

		if(n && n->g) {
//debug_output("Path::search(p.x=%d,p.y=%d,p.g=%d)\n",p1->x,p1->y,p1->g);
			for(p1=n,i=0; p1 && p1->parent!=p1; ++i,p1=p1->parent);
//debug_output("Path::search(trail.lenght=%d)\n",(int)t->len);
			if(!p1 && i>1) {
				t = new Trail();
				t->obj = obj;
				t->len = i;
				t->trail = (Trail::step *)malloc(t->len*sizeof(Trail::step));
				for(p1=n,p2=0,i=t->len-1; p1; --i,p2=p1,p1=p1->parent) {
//debug_output("key=%04x\tx1=%d\ty1=%d\tx2=%d\ty2=%d\tdir=%d\n",
//p1->key,p1->x,p1->y,p2? p2->x : -1,p2? p2->y : -1,p2? dir(*this,p1->x,p1->y,p2->x,p2->y) : 5);
					t->trail[i] = (Trail::step){ p1->x,p1->y,(uint8_t)(p2? dir(*this,p1->x,p1->y,p2->x,p2->y) : PATH_C) };

debug_output("Path::trail[%d]: x=%d, y=%d, dir=%d\n",i,(int)t->trail[i].x,(int)t->trail[i].y,(int)t->trail[i].dir);
mem[p1->y][p1->x] = (char)('a'+((t->len-1)%('z'-'a')));
				}
//debug_output("Path::search()\n");
			}
		}
for(y=0; y<height; ++y) {
for(x=0; x<width; ++x) putc(mem[y][x],stderr);
fputc('\n',stderr);fflush(stderr);}
	}
	return t;
}
Пример #11
0
void Notebook::makeLayout(int x,int y,int w,int h) {
	int i,w1 = width,h1 = height;
	client.left = x,client.top = y,client.right = x+w,client.bottom = y+h;
	NotebookPage *np = selected>=0? (NotebookPage *)pages[selected] : 0;
	Widget::makeLayout(x,y,w,h);
debug_output("Notebook::makeLayout(x: %d, y: %d, w: %d, h: %d)\n",this->x,this->y,width,height);
	RECT r = { 0,0,client.right-client.left,client.bottom-client.top };
	if(type==WIDGET_NOTEBOOK) TabCtrl_AdjustRect((HWND)component,FALSE,&r);
debug_output("Notebook::makeLayout(WIN32_CONTROL_TABS - TabCtrl_AdjustRect(l: %ld, t: %ld, r: %ld, b: %ld))\n",r.left,r.top,r.right,r.bottom);
	if(w1!=width || h1!=height)
		for(i=pages.size()-1; i>=0; --i)
			((NotebookPage *)pages[i])->status = 1;
	if(np && np->page) {
		np->page->makeLayout(x,r.top,width,height-r.top);
		np->status = 0;
	}
}
Пример #12
0
void Path::searchReach(void *o,int x,int y,int s,int m) {
	int i,d,c;
	PathNode *p1 = 0,*p2 = 0;
debug_output("Path::searchReach(x=%d,y=%d)\n",x,y);

	clear();
	closest = 0;
	obj = o,sx = x,sy = y,dx = -1,dy = -1;
	if(sx<0 || sy<0 || sx>=width || sy>=height || (s==0 && m==0)) return;

	cap = m*m*3;
	p1 = new PathNode(sx,sy,0,0,0);
	put(p1);
	push(p1);


	while(open) {
		if(step) step(*this,*open);
		p1 = pop();
debug_output("key=%08x\tx1=%d\ty1=%d\tx2=%d\ty2=%d\ts=%d\tg=%d\th=%d\n",p1->key,p1->x,p1->y,
p1->parent? p1->parent->x : -1,p1->parent? p1->parent->y : -1,p1->s,p1->g,p1->h);
		for(i=0,d=0; d!=-1; ++i) {
			d = move(*this,*p1,x,y,i);
			c = weight(*this,*p1,x,y);
			if(c!=PATH_CANNOT_MOVE && c!=PATH_AVOID_MOVE) {
				if((p2=get(x,y))) {
					if(p1->g+c<p2->g) {
						remove(p2);
						p2->parent = p1,p2->g = p1->g+c,p2->s = p1->s+1;
						push(p2);
					}
				} else if((s==0 || p1->s+1<=s) && (m==0 || p1->g+c<=m)) {
					p2 = new PathNode(x,y,p1->g+c,0,p1);
					put(p2);
					push(p2);
				}
			}
		}
	}

{char mem[height][width];memset(mem,' ',width*height);
for(y=0; y<height; ++y) for(x=0; x<width; ++x) if((p1=get(x,y))) mem[y][x] = '0'+p1->g;
for(y=0; y<height; ++y) {
for(x=0; x<width; ++x) putc(mem[y][x],stderr);
fputc('\n',stderr);fflush(stderr);}}
}
Пример #13
0
void CPHObject::Collide()
{
	if(m_flags.test(fl_ray_motions))
	{
		CPHMoveStorage* tracers=MoveStorage();
		CPHMoveStorage::iterator I=tracers->begin(),E=tracers->end();
		for(;E!=I;I++)
		{
				const Fvector	*from=0,	*to=0;
				Fvector dir;
				I.Positions(from,to);
				if(from->x==-dInfinity) continue;
				dir.sub(*to,*from);
				float	magnitude=dir.magnitude();
				if(magnitude<EPS) continue;
				dir.mul(1.f/magnitude);
				g_SpatialSpacePhysic->q_ray(ph_world->r_spatial,0,STYPE_PHYSIC,*from,dir,magnitude);//|ISpatial_DB::O_ONLYFIRST
#ifdef DEBUG
				if(debug_output().ph_dbg_draw_mask().test(phDbgDrawRayMotions))
				{
					debug_output().DBG_OpenCashedDraw();
					debug_output().DBG_DrawLine(*from,Fvector().add(*from,Fvector().mul(dir,magnitude)),D3DCOLOR_XRGB(0,255,0));
					debug_output().DBG_ClosedCashedDraw(30000);
				}

#endif
				qResultVec& result=ph_world->r_spatial;
				qResultIt i=result.begin(),e=result.end();
				for(;i!=e;++i)	{
					CPHObject* obj2=static_cast<CPHObject*>(*i);
					if(obj2==this || !obj2->m_flags.test(st_dirty))		continue;
					dGeomID	motion_ray=ph_world->GetMotionRayGeom();
					dGeomRayMotionSetGeom(motion_ray,I.dGeom());
					dGeomRayMotionsSet(motion_ray,(const dReal*) from,(const dReal*)&dir,magnitude);
					NearCallback(this,obj2,motion_ray,obj2->dSpacedGeom());
				}
		}
	}
	CollideDynamics					();
///////////////////////////////
	if(CPHCollideValidator::DoCollideStatic(*this)) CollideStatic(dSpacedGeom(),this);
	m_flags.set(st_dirty,FALSE);
}
Пример #14
0
/*
  tfe_arch_receive()

  This function checks if there was a frame received.
  If so, it returns 1, else 0.

  If there was no frame, none of the parameters is changed!

  If there was a frame, the following actions are done:

  - at maximum *plen byte are transferred into the buffer given by pbuffer
  - *plen gets the length of the received frame, EVEN if this is more
    than has been copied to pbuffer!
  - if the dest. address was accepted by the hash filter, *phashed is set, else
    cleared.
  - if the dest. address was accepted by the hash filter, *phash_index is
    set to the number of the rule leading to the acceptance
  - if the receive was ok (good CRC and valid length), *prx_ok is set,
    else cleared.
  - if the dest. address was accepted because it's exactly our MAC address
    (set by tfe_arch_set_mac()), *pcorrect_mac is set, else cleared.
  - if the dest. address was accepted since it was a broadcast address,
    *pbroadcast is set, else cleared.
  - if the received frame had a crc error, *pcrc_error is set, else cleared
*/
int tfe_arch_receive(BYTE *pbuffer  ,    /* where to store a frame */
                     int  *plen,         /* IN: maximum length of frame to copy;
                                            OUT: length of received frame
                                            OUT can be bigger than IN if received frame was
                                                longer than supplied buffer */
                     int  *phashed,      /* set if the dest. address is accepted by the hash filter */
                     int  *phash_index,  /* hash table index if hashed == TRUE */
                     int  *prx_ok,       /* set if good CRC and valid length */
                     int  *pcorrect_mac, /* set if dest. address is exactly our IA */
                     int  *pbroadcast,   /* set if dest. address is a broadcast address */
                     int  *pcrc_error    /* set if received frame had a CRC error */
                    )
{
    int len;

    TFE_PCAP_INTERNAL internal = { *plen, pbuffer };


#ifdef TFE_DEBUG_ARCH
    if(g_fh) fprintf( g_fh, "tfe_arch_receive() called, with *plen=%u.", *plen );
#endif

    assert((*plen&1)==0);

    len = tfe_arch_receive_frame(&internal);

    if (len!=-1) {

#ifdef TFE_DEBUG_PKTDUMP
        debug_output( "Received frame: ", internal.buffer, internal.len );
#endif // #ifdef TFE_DEBUG_PKTDUMP

        if (len&1)
            ++len;

        *plen = len;

        /* we don't decide if this frame fits the needs;
         * by setting all zero, we let tfe.c do the work
         * for us
         */
        *phashed =
            *phash_index =
                *pbroadcast =
                    *pcorrect_mac =
                        *pcrc_error = 0;

        /* this frame has been received correctly */
        *prx_ok = 1;

        return 1;
    }

    return 0;
}
Пример #15
0
//ZASSERT的扩展定义,
void ZCE_Trace_LogMsg::debug_assert(const char *file_name,
                                    const int file_line,
                                    const char *function_name,
                                    const char *expression_name)
{
    debug_output(RS_FATAL, "Assertion failed: FILENAME:[%s],LINENO:[%d],FUN:[%s],EXPRESSION:[%s].",
                 file_name,
                 file_line,
                 function_name,
                 expression_name);
}
Пример #16
0
int myprintf(char *format, ...){
    int rc;
    char szText[512];
    
    va_list paramList;
    va_start(paramList, format);
    rc = vsnprintf(szText, 512, format, paramList);
    va_end(paramList);
    
    debug_output(szText);

    return rc;    
}
Пример #17
0
int8_t del_dev_tun( int32_t fd ) {

	if ( ioctl( fd, TUNSETPERSIST, 0 ) < 0 ) {

		debug_output( 0, "Error - can't delete tun device: %s\n", strerror(errno) );
		return -1;

	}

	close( fd );

	return 1;

}
Пример #18
0
void Notebook::closePage(int n) {
	if(n<0 || n>=(int)pages.size()) n = selected;
	if(pages.size()>0) {
debug_output("Notebook::closePage(n: %d, pages: %d)\n",n,(int)pages.size());
		int i;
		NotebookPage *np = (NotebookPage *)pages[n];
		if(n==selected) selectPage(n==0? n+1 : n-1);
#ifdef USE_GTK
		gtk_notebook_remove_page(GTK_NOTEBOOK(component),n);
#endif
#ifdef USE_WIN32
		if(type==WIDGET_NOTEBOOK) TabCtrl_DeleteItem((HWND)component,n);
#endif
		pages.removeAt(n);
		delete np;

		for(i=pages.size()-1; i>=n; --i) {
			np = (NotebookPage *)pages[i];
debug_output("Notebook::closePage(index=%d -> i=%d)\n",np->tab.index,i);
			np->tab.index = i;
		}
	}
}
Пример #19
0
int run_cmd(char *cmd) {
	int error, pipes[2], _stderr = -1, ret = 0;
	char error_log[256];

	if (pipe(pipes) < 0) {
		debug_output(3, "Warning - could not create a pipe to '%s': %s\n", cmd, strerror(errno));
		return -1;
	}

	memset(error_log, 0, 256);

	/* save stderr */
	_stderr = dup(STDERR_FILENO);

	/* connect the commands output with the pipe for later logging */
	dup2(pipes[1], STDERR_FILENO);
	close(pipes[1]);

	error = system(cmd);

	/* copy stderr back */
	dup2(_stderr, STDERR_FILENO);
	close(_stderr);

	if ((error < 0) || (WEXITSTATUS(error) != 0)) {
		ret = read(pipes[0], error_log, sizeof(error_log));
		debug_output(3, "Warning - command '%s' returned an error\n", cmd);

		if (ret > 0)
			debug_output(3, "          %s\n", error_log);

		ret = -1;
	}

	close(pipes[0]);
	return ret;
}
Пример #20
0
void dc_printf(char *format, ...)
{
	char tmp[DCOLS*DROWS];
	va_list args;

	va_start(args, format);
	vsprintf(tmp, format, args);
	va_end(args);

	char *p = tmp;
	while( *p != '\0' ) {
		debug_output(*p);
		p++;
	}
}
Пример #21
0
void CElevatorState::UpdateClimbingCommon(const Fvector	&d_to_ax,float to_ax,const Fvector& control_accel,float ca)
{
	VERIFY(m_ladder&&m_character);
	if(to_ax-m_character->FootRadius()>out_dist)
										SwitchState((clbNoLadder));
	if(fis_zero(ca)&&d_to_ax.dotproduct(m_ladder->Norm())<0.f)
	{
#ifdef DEBUG
		if(debug_output().ph_dbg_draw_mask().test(phDbgLadder))
		{
//.			Msg("force applied");
		}
#endif
		m_character->ApplyForce(d_to_ax,m_character->Mass()*ph_world->Gravity());//

	}
}
Пример #22
0
	void getline(std::istream &ifs, std::string &line)
	{
		std::getline(ifs, line);

		if (line != "")
		{
			// remove CR from line
			if (line[line.size() - 1] == '\r')
				line.erase(line.size() - 1);

			// remove LF from line
			if (line[line.size() - 1] == '\n')
				line.erase(line.size() - 1);
		}

		debug_output(line);
	}
Пример #23
0
bool CElevatorState::GetControlDir(Fvector& dir)
{
	bool ret=true;
	VERIFY(m_ladder&&m_character);
	Fvector d;
	float dist;
	switch(m_state)
	{
	case	clbDepart		: 
	case	clbNoLadder		:
	case	clbNone			: 		break;			
	case 	clbNearUp		:		dist= m_ladder->DDUpperP(m_character,d);
									if(	dXZDotNormalized(d,m_character->CamDir())>look_angle_cosine&&
										!fis_zero(dist,EPS_L)&&m_character->ControlAccel().dotproduct(d)>0.f) dir.set(d);
									break;						
	case 	clbNearDown		:		
									dist=m_ladder->DDLowerP(m_character,d);
									if(dXZDotNormalized(d,m_character->CamDir())>look_angle_cosine&&
									   !fis_zero(dist,EPS_L)&&m_character->ControlAccel().dotproduct(d)>0.f) dir.set(d);
									break;					
	case 	clbClimbingUp	:		m_ladder->DDAxis(dir);
									m_ladder->DDToAxis(m_character,d);
									dir.add(d);dir.normalize();
									break;					
	case 	clbClimbingDown	:		m_ladder->DDToAxis(m_character,d);
									if(m_ladder->BeforeLadder(m_character)||d.dotproduct(dir)>0.f)
									{
										m_ladder->DDAxis(dir);
										dir.invert();
										dir.add(d);dir.normalize();
									}
									else 
									{
#ifdef DEBUG
										if(debug_output().ph_dbg_draw_mask().test(phDbgLadder))
										{
											Msg("no c dir");
										}
#endif
										ret=false;
									}
									break;				
	}
	return ret;
}
Пример #24
0
int rawnet_arch_receive(BYTE *pbuffer, int *plen, int *phashed, int *phash_index, int *prx_ok, int *pcorrect_mac, int *pbroadcast, int *pcrc_error)
{
    int len;

    TFE_PCAP_INTERNAL internal;

    internal.len = *plen;
    internal.buffer = pbuffer;

#ifdef RAWNET_DEBUG_ARCH
    log_message(rawnet_arch_log, "rawnet_arch_receive() called, with *plen=%u.", *plen);
#endif

    assert((*plen & 1) == 0);

    len = rawnet_arch_receive_frame(&internal);

    if (len != -1) {

#ifdef RAWNET_DEBUG_PKTDUMP
        debug_output("Received frame: ", internal.buffer, internal.len);
#endif /* #ifdef RAWNET_DEBUG_PKTDUMP */

        if (len & 1) {
            ++len;
        }

        *plen = len;

        /* we don't decide if this frame fits the needs;
         * by setting all zero, we let tfe.c do the work
         * for us
         */
        *phashed = *phash_index = *pbroadcast = *pcorrect_mac = *pcrc_error = 0;

        /* this frame has been received correctly */
        *prx_ok = 1;

        return 1;
    }

    return 0;
}
Пример #25
0
void rawnet_arch_transmit(int force, int onecoll, int inhibit_crc, int tx_pad_dis, int txlength, BYTE *txframe)
{
#ifdef RAWNET_DEBUG_ARCH
    log_message(rawnet_arch_log, "rawnet_arch_transmit() called, with: force = %s, onecoll = %s, inhibit_crc=%s, tx_pad_dis=%s, txlength=%u",
                force ? "TRUE" : "FALSE",
                onecoll ? "TRUE" : "FALSE",
                inhibit_crc ? "TRUE" : "FALSE",
                tx_pad_dis ?  "TRUE" : "FALSE",
                txlength);
#endif

#ifdef RAWNET_DEBUG_PKTDUMP
    debug_output("Transmit frame: ", txframe, txlength);
#endif /* #ifdef RAWNET_DEBUG_PKTDUMP */

    if ((*p_pcap_sendpacket)(TfePcapFP, txframe, txlength) == -1) {
        log_message(rawnet_arch_log, "WARNING! Could not send packet!");
    }
}
Пример #26
0
void CElevatorState::SwitchState(Estate new_state)
{
	if(!StateSwitchInertion(new_state))return;
#ifdef DEBUG
if(debug_output().ph_dbg_draw_mask().test(phDbgLadder))
				Msg("%s",dbg_state[new_state]);
#endif
	VERIFY(m_character);
	if((m_state!=clbClimbingUp&&m_state!=clbClimbingDown) &&
	   (new_state==clbClimbingUp||new_state==clbClimbingDown)
 	   )dBodySetGravityMode(m_character->get_body(),0);

	if((new_state!=clbClimbingUp&&new_state!=clbClimbingDown) &&
		(m_state==clbClimbingUp||m_state==clbClimbingDown)
		)dBodySetGravityMode(m_character->get_body(),1);

	//if(new_state==clbDepart) InitDepart();
	NewState();
	m_state=new_state;
}
Пример #27
0
/* Probe for tun interface availability */
int8_t probe_tun(uint8_t print_to_stderr) {

	int32_t fd;

	if ( ( fd = open( "/dev/net/tun", O_RDWR ) ) < 0 ) {

		if (print_to_stderr)
			fprintf( stderr, "Error - could not open '/dev/net/tun' ! Is the tun kernel module loaded ?\n" );
		else
			debug_output( 0, "Error - could not open '/dev/net/tun' ! Is the tun kernel module loaded ?\n" );

		return 0;

	}

	close( fd );

	return 1;

}
Пример #28
0
int8_t add_dev_tun( struct batman_if *batman_if, uint32_t tun_addr, char *tun_dev, size_t tun_dev_size, int32_t *fd, int32_t *ifi ) {

	int32_t tmp_fd, sock_opts;
	struct ifreq ifr_tun, ifr_if;
	struct sockaddr_in addr;

	/* set up tunnel device */
	memset( &ifr_tun, 0, sizeof(ifr_tun) );
	memset( &ifr_if, 0, sizeof(ifr_if) );

	ifr_tun.ifr_flags = IFF_TUN | IFF_NO_PI;
	strncpy( ifr_tun.ifr_name, "gate%d", IFNAMSIZ );

	if ( ( *fd = open( "/dev/net/tun", O_RDWR ) ) < 0 ) {

		debug_output( 0, "Error - can't create tun device (/dev/net/tun): %s\n", strerror(errno) );
		return -1;

	}

	if ( ( ioctl( *fd, TUNSETIFF, (void *)&ifr_tun ) ) < 0 ) {

		debug_output( 0, "Error - can't create tun device (TUNSETIFF): %s\n", strerror(errno) );
		close(*fd);
		return -1;

	}

	if ( ioctl( *fd, TUNSETPERSIST, 1 ) < 0 ) {

		debug_output( 0, "Error - can't create tun device (TUNSETPERSIST): %s\n", strerror(errno) );
		close(*fd);
		return -1;

	}


	tmp_fd = socket( AF_INET, SOCK_DGRAM, 0 );

	if ( tmp_fd < 0 ) {
		debug_output( 0, "Error - can't create tun device (udp socket): %s\n", strerror(errno) );
		del_dev_tun( *fd );
		return -1;
	}


	/* set ip of this end point of tunnel */
	memset( &addr, 0, sizeof(addr) );
	addr.sin_addr.s_addr = tun_addr;
	addr.sin_family = AF_INET;
	memcpy( &ifr_tun.ifr_addr, &addr, sizeof(struct sockaddr) );


	if ( ioctl( tmp_fd, SIOCSIFADDR, &ifr_tun) < 0 ) {

		debug_output( 0, "Error - can't create tun device (SIOCSIFADDR): %s\n", strerror(errno) );
		del_dev_tun( *fd );
		close( tmp_fd );
		return -1;

	}


	if ( ioctl( tmp_fd, SIOCGIFINDEX, &ifr_tun ) < 0 ) {

		debug_output( 0, "Error - can't create tun device (SIOCGIFINDEX): %s\n", strerror(errno) );
		del_dev_tun( *fd );
		close( tmp_fd );
		return -1;

	}

	*ifi = ifr_tun.ifr_ifindex;

	if ( ioctl( tmp_fd, SIOCGIFFLAGS, &ifr_tun) < 0 ) {

		debug_output( 0, "Error - can't create tun device (SIOCGIFFLAGS): %s\n", strerror(errno) );
		del_dev_tun( *fd );
		close( tmp_fd );
		return -1;

	}

	ifr_tun.ifr_flags |= IFF_UP;
	ifr_tun.ifr_flags |= IFF_RUNNING;

	if ( ioctl( tmp_fd, SIOCSIFFLAGS, &ifr_tun) < 0 ) {

		debug_output( 0, "Error - can't create tun device (SIOCSIFFLAGS): %s\n", strerror(errno) );
		del_dev_tun( *fd );
		close( tmp_fd );
		return -1;

	}

	/* get MTU from real interface */
	strncpy( ifr_if.ifr_name, batman_if->dev, IFNAMSIZ - 1 );

	if ( ioctl( tmp_fd, SIOCGIFMTU, &ifr_if ) < 0 ) {

		debug_output( 0, "Error - can't create tun device (SIOCGIFMTU): %s\n", strerror(errno) );
		del_dev_tun( *fd );
		close( tmp_fd );
		return -1;

	}

	/* set MTU of tun interface: real MTU - 29 */
	if ( ifr_if.ifr_mtu < 100 ) {

		debug_output( 0, "Warning - MTU smaller than 100 -> can't reduce MTU anymore\n" );

	} else {

		ifr_tun.ifr_mtu = ifr_if.ifr_mtu - 29;

		if ( ioctl( tmp_fd, SIOCSIFMTU, &ifr_tun ) < 0 ) {

			debug_output( 0, "Error - can't create tun device (SIOCSIFMTU): %s\n", strerror(errno) );
			del_dev_tun( *fd );
			close( tmp_fd );
			return -1;

		}

	}


	/* make tun socket non blocking */
	sock_opts = fcntl( *fd, F_GETFL, 0 );
	fcntl( *fd, F_SETFL, sock_opts | O_NONBLOCK );


	strncpy( tun_dev, ifr_tun.ifr_name, tun_dev_size - 1 );
	close( tmp_fd );

	return 1;

}
Пример #29
0
	void debug_output(const char *msg)
	{
#ifdef _DEBUG
		debug_output(std::string(msg));
#endif
	}
Пример #30
0
bool	CPHActivationShape::	Activate							(const Fvector need_size,u16 steps,float max_displacement,float max_rotation,bool	un_freeze_later/*	=false*/)										
{

#ifdef	DEBUG 
	if(debug_output().ph_dbg_draw_mask().test(phDbgDrawDeathActivationBox))
	{
		debug_output().DBG_OpenCashedDraw();
		Fmatrix M;
		PHDynamicData::DMXPStoFMX(dBodyGetRotation(m_body),dBodyGetPosition(m_body),M);
		Fvector v;dGeomBoxGetLengths(m_geom,cast_fp(v));v.mul(0.5f);
		debug_output().DBG_DrawOBB(M,v,D3DCOLOR_XRGB(0,255,0));
	}
#endif
	VERIFY(m_geom&&m_body);
	CPHObject::activate();
	ph_world->Freeze();
	UnFreeze();
	max_depth=0.f;

	dGeomUserDataSetObjectContactCallback(m_geom,GetMaxDepthCallback)			;
	//ph_world->Step();
	ph_world->StepTouch();	
	u16		num_it =15;
	float	fnum_it=float(num_it);
	float	fnum_steps=float(steps);
	float	fnum_steps_r=1.f/fnum_steps;
	float	resolve_depth=0.01f;
	float	max_vel=max_depth/fnum_it*fnum_steps_r/fixed_step;
	float	limit_l_vel=_max(_max(need_size.x,need_size.y),need_size.z)/fnum_it*fnum_steps_r/fixed_step;

	if(limit_l_vel>default_l_limit)
		limit_l_vel=default_l_limit;

	if(max_vel>limit_l_vel)
		max_vel=limit_l_vel;

	float	max_a_vel=max_rotation/fnum_it*fnum_steps_r/fixed_step;

	if(max_a_vel>default_w_limit)
					max_a_vel=default_w_limit;

	//ph_world->CutVelocity(0.f,0.f);
	dGeomUserDataSetCallbackData(m_geom,this);
	dGeomUserDataSetObjectContactCallback( m_geom, ActivateTestDepthCallback );
	if( m_flags.test( flStaticEnvironment ) )
		dGeomUserDataAddObjectContactCallback(m_geom,StaticEnvironment);
	max_depth=0.f;
	
	Fvector from_size;
	Fvector step_size,size;
	dGeomBoxGetLengths(m_geom,cast_fp(from_size));
	step_size.sub(need_size,from_size);
	step_size.mul(fnum_steps_r);
	size.set(from_size);
	bool ret=false;
	V_PH_WORLD_STATE temp_state;
	ph_world->GetState(temp_state);
	for(int m=0;steps>m;++m)
	{
		//float param =fnum_steps_r*(1+m);
		//InterpolateBox(id,param);
		size.add(step_size);
		dGeomBoxSetLengths(m_geom,size.x,size.y,size.z);
		u16		attempts=10;
		do{
		
			ret=false;
			for(int i=0;num_it>i;++i)
			{
				max_depth=0.f;
				ph_world->Step();
				CHECK_POS(Position(),"pos after ph_world->Step()",false);
				ph_world->CutVelocity(max_vel,max_a_vel);
				CHECK_POS(Position(),"pos after CutVelocity",true);
				//if(m==0&&i==0)ph_world->GetState(temp_state);
				if(max_depth	<	resolve_depth) 
				{
						ret=true;
						break;
				}
			}
			attempts--;
		}while(!ret&&attempts>0);
#ifdef	DEBUG
//		Msg("correction attempts %d",10-attempts);
#endif
	
	}
	RestoreVelocityState(temp_state);
	CHECK_POS(Position(),"pos after RestoreVelocityState(temp_state);",true);
	if(!un_freeze_later)ph_world->UnFreeze();
#ifdef	DEBUG 
	if(debug_output().ph_dbg_draw_mask().test(phDbgDrawDeathActivationBox))
	{
		debug_output().DBG_OpenCashedDraw();
		Fmatrix M;
		PHDynamicData::DMXPStoFMX(dBodyGetRotation(m_body),dBodyGetPosition(m_body),M);
		Fvector v;v.set(need_size);v.mul(0.5f);
		debug_output().DBG_DrawOBB(M,v,D3DCOLOR_XRGB(0,255,255));
		debug_output().DBG_ClosedCashedDraw(30000);
	}
#endif
	return ret;
}