void PushData(bool consume = false, data::File::Writer* pwriter = nullptr) {
        assert(!pwriter || consume);

        if (cache_) {
            // previous PushData() has stored data in cache_
            data::File::Reader reader = cache_->GetReader(consume);
            while (reader.HasNext())
                emitter_.Emit(reader.Next<TableItem>());
            return;
        }

        if (!consume) {
            if (subranges_.empty()) {
                Flush();
            }
            else {
                data::FilePtr cache = ctx_.GetFilePtr(dia_id_);
                data::File::Writer writer = cache_->GetWriter();
                PushData(true, &writer);
                cache_ = cache;
                writer.Close();
            }
            return;
        }

        // close File writers
        for (auto& w : subrange_writers_) {
            w.Close();
        }

        if (pwriter) {
            FlushAndConsume<true>(pwriter);
        }
        else {
            FlushAndConsume();
        }

        for (size_t i = 0; i < subranges_.size(); ++i) {
            ReduceByIndexPostPhase<TableItem, Key, Value, KeyExtractor,
                                   ReduceFunction, Emitter, VolatileKey,
                                   ReduceConfig>
            subtable(ctx_, dia_id_, key_extractor_, reduce_function_,
                     emitter_.emit_, config_, neutral_element_);
            subtable.SetRange(subranges_[i]);
            subtable.Initialize(limit_memory_bytes_);

            {
                // insert items
                auto reader = subrange_files_[i]->GetConsumeReader();
                while (reader.HasNext()) {
                    subtable.Insert(reader.template Next<TableItem>());
                }
            }

            subtable.PushData(consume || pwriter, pwriter);

            // delete File
            subrange_files_[i].reset();
        }
    }
Esempio n. 2
0
void lucy_SetData(const lucy_File *lua_file, const char *name,
                  const lucy_Data *data)
{
    lua_State *state = lua_file->state_;
    PushData(state, data);
    lua_setglobal(state, name);
}
Esempio n. 3
0
void LAYER::BeginPath( int32_t x, int32_t y, int direction )
{
	LAYER_PATH_NODE node;
	LAYER::x = x;
	LAYER::y = y;
	LAYER::min_x = x;
	LAYER::min_y = y;
	LAYER::w = 1;
	LAYER::h = 1;
	EmptyDataStack( &pds_path );
	node.x = 0; // x - LAYER::x
	node.y = 0; // y - LAYER::y
	node.flags.BackDir = NOWHERE;
	if( direction == NOWHERE )
	{
		flags.bForced = 0;
		// there is no real peice which is
		// NOWHERE to NOWHERE, therefore, do not attempt to draw one
		// and instead set the exit direction as valid.
		node.flags.bForced = 0;
		node.flags.ForeDir = NOWHERE;
	}
	else
	{
		flags.bForced = 1;
		node.flags.bForced = 1;
		node.flags.ForeDir = direction;
	}
	{
		PushData( &pds_path, &node );
	}
}
Esempio n. 4
0
 foreach(QByteArray cleartext, cleartexts) {
     QByteArray msg = GetData(cleartext);
     if(msg.isEmpty()) {
         continue;
     }
     qDebug() << "Received a valid message: " << msg.size() << msg.toBase64();
     PushData(msg, this);
 }
Esempio n. 5
0
size_t USBDataFilev2012::readBlock(const string& str, int index)
{
	USBDataBlock* ptrBlock = (USBDataBlock*) (str.data() + index);
	size_t nLength = (size_t) ntohl(ptrBlock->nDataLength);
	TRACE("block length %d, code %d",nLength,ptrBlock->cDataCode);
	if (nLength + index > str.size())
	{
		ERROR("bad block size");
		throw USBDataFileException("bad block size");
	}
	VTDRRecord* ptrRecord = NULL;
	char szBlockName[64] =
	{ 0 };
	VTDRRecord::gb2312toutf8((const char*) ptrBlock->cDataName,
			sizeof(ptrBlock->cDataName), szBlockName, 64);
	TRACE("blockName:%s",szBlockName);
	size_t n = 0;
	if (nLength == 0)
	{
		TRACE("skip block");
		nDataBlockNumber++;
	}

	while (nLength > n)
	{
		ptrRecord = generateRecord((VTDRRecord::DataCode) ptrBlock->cDataCode);

		if (!ptrRecord)
		{
			throw USBDataFileException("generate record fail");
		}

		n += ptrRecord->Read(str.data() + sizeof(USBDataBlock) + index + n);
		TRACE("Read:%d[Def:%d]",n,nLength);

		if (nLength < n)
		{
			ERROR("bad data size");
			//throw USBDataFileException("bad data size");
		}

		string buf;
		ptrRecord->Dump(buf);
		TRACE("\n%s",buf.c_str());
		m_strDecodeText.append(buf);
		PushData(ptrRecord);
	};

	return nLength + sizeof(USBDataBlock);
}
Esempio n. 6
0
    //! Performing push operation. Notifies children and calls actual push
    //! method. Then cleans up the DIA graph by freeing parent references of
    //! children.
    void RunPushData() final {
        for (const Child& child : children_)
            child.node->StartPreOp(child.parent_index);

        if (consume_counter_ > 0 && consume_counter_ != never_consume_)
            --consume_counter_;

        bool consume = context().consume() && consume_counter_ == 0;
        PushData(consume);
        if (consume) Dispose();

        for (const Child& child : children_)
            child.node->StopPreOp(child.parent_index);
    }
Esempio n. 7
0
  void BulkRound::ProcessMessages()
  {
    int size = _descriptors.size();
    int index = 0;

    for(int idx = 0; idx < size; idx++) {
      QByteArray cleartext = ProcessMessage(idx, index);
      _cleartexts.append(cleartext);
      if(!cleartext.isEmpty()) {
        PushData(GetSharedPointer(), cleartext);
      }
      index += _descriptors[idx].Length();
    }
  }
Esempio n. 8
0
int main()
{
    int m, n;    // 行数和列数
    int k, flag; // 判断是否走出了迷宫

    ElemType **MAZE = NULL; // 指向迷宫数组
    ElemType **MARK = NULL; // 记忆数组
    SqStack *s, s1;
    QNode *Q, q;

    srand((unsigned)time(0));
    system("color 17"); // 背景色蓝色,前景色白色

    printf("请输入迷宫的行数和列数:");
    while (scanf("%d %d", &m, &n) != EOF && m && n && m <= MAXSIZE && n <= MAXSIZE)
    {
	CreateMAP(&MAZE, m, n, maze);
	CreateMAP(&MARK, m, n, mark);
	Q = &q;
	s = &s1;
	InitQueue(Q); // 初始化队列
	InitStack(s); // 初始化栈
	printf("\n根据您的输入构造迷宫如下:\n");
	PrintMAZE(m, n, MAZE);
	flag = FindPath(MAZE, MARK, Q, m, n, Directrion); // 寻找路径
	if (flag)
	{ // 可以走出迷宫
	    PushData(q, s);
	    k = s->top;
	    k++;
	    for (int i = 0; i < k; i++)
	    {
		system("cls");
		PrintMAZE(m, n, MAZE);      // 打印迷宫
		PrintPuzzle(MAZE, s, m, n); // 打印迷宫
		num++;
		Sleep(600);
	    }
	    StackTraverse(s1); // 输出坐标
	}
	else
	{
	    PrintMAZE(m, n, MAZE);
	    printf("No Path!\n");
	}
    }
    return 0;
}
Esempio n. 9
0
int CSvrLink::ExtCall(int sourceno, int destno, int funcno, int batchno, int acktime, ST_CPACK *rpack, ST_CPACK *apack, ST_PACK *pArrays)
{
   int rtn;
   char szmsg[256];
   xcdata.sno = sourceno;
   xcdata.dno = destno;
   xcdata.fno = funcno;
   xcdata.bno = batchno;

   rpack->head.userdata = batchno;
   if (acktime<=0)
   {
      acktime = 5;  // 缺省为5秒钟内得到应答,否则作为失败处理。。。以防止业务部分调用错误导致整个BUNIT处理失败或挂起
   }
   rtn = PushData(sourceno,destno,funcno,batchno,rpack,PM_ANSWER,acktime);
   while (rtn==0)
   {
      rtn = RecvMsg(acktime*1000+1000);
      if (rtn>0)
      {
         MSGBUF *pmb = GetRecvMsg();
         if (pmb->head.msgtype==MT_PUSHDATA)
         {
            // 有应答数据返回:
            rtn = 0;
            DecodeBufWithArray((unsigned char *)pmb->data,pmb->head.len,apack,pArrays,&rtn,szmsg);
            memcpy(&xcdata.ahead,&(apack->head),sizeof(ST_PACKHEAD));
            if (apack->head.hook.queuetype>0)
               xcdata.fno = apack->head.hook.queuetype;
            else if (atoi(apack->head.hook.hostname)>0)
               xcdata.fno = atoi(apack->head.hook.hostname);
            return(rtn);
         }
         else
         {
            DEBUG_RUNTIME_MSGOUT("ExtCall中间收到了非MT_PUSHDATA应答包,属于程序错误!");
            rtn = 0; // 继续读取数据,以便接收到正确的MT_PUSHDATA应答包
         }
      }
      else if (rtn==0)
      {
         return(-2);  // 等待应答数据超时,即自从向外发送了请求后,在acktime+1秒内没有接收到应答数据  
      }
   }
   return(-1); // 其他各种通讯方面的错误
}
Esempio n. 10
0
  void BulkRound::HandleAggregatedBulkData(QDataStream &stream, const Id &from)
  {
    if(from == GetLocalId()) {
      return;
    }

    qDebug() << GetGroup().GetIndex(GetLocalId()) << GetLocalId().ToString() <<
      ": received aggregated bulk data from " << GetGroup().GetIndex(from) <<
      from.ToString();

    if(GetGroup().GetLeader() != from) {
      throw QRunTimeError("Received aggregated bulk data from non-leader.");
    }

    if(_state != ReceivingLeaderData) {
      throw QRunTimeError("Not expected at this time.");
    }

    QVector<QByteArray> cleartexts;
    stream >> cleartexts;

    const QVector<Descriptor> &des = GetDescriptors();

    if(cleartexts.count() != des.count()) {
      throw QRunTimeError("Cleartext count does not match descriptor count: " +
          QString::number(cleartexts.count()) + " " +
          QString::number(des.count()));
    }

    Hash hashalgo;

    for(int idx = 0; idx < cleartexts.count(); idx++) {
      QByteArray cleartext = cleartexts[idx];
      QByteArray hash = hashalgo.ComputeHash(cleartext);
      if(hash != des[idx].CleartextHash()) {
        throw QRunTimeError("Cleartext hash does not match descriptor hash.");
      }
      if(!cleartext.isEmpty()) {
        PushData(GetSharedPointer(), cleartext);
      }
    }

    Finish();
  }
Esempio n. 11
0
//------------------------响应按键函数实现----------------------------
//2:响应按键操作并根据情况与用户进行数据交互,并更新显示
//返回值定义为: 正值:进入相应子菜单,-1,不管,-2:返回上层菜单
signed char TMenu_SubMenuKey(const TMenu_t *pMenu,    //指向的菜单系统
                             unsigned char Key,       //送入的键值
                             void *pv)      //已被使用的自由数据缓冲区
{
    unsigned char Flag;
    unsigned char Sel;
    struct _SubMenuData *pSubMenuData = (struct _SubMenuData *)pv;
    pMenu = pMenu;//防止部分编译器警告
    PushMenu(pMenu);
    PushData(pv);
    TListboxEx_Key(&pSubMenuData->ListboxEx,Key);//处理按键

    Flag = pSubMenuData->Flag;

    //数字键后处理:当做快捷键处理
    if((Key >= '1') && (Key <= '9')) {
        //不处理超过项目的按键
        if((Key - '1') >= TListboxEx_GetItems(&pSubMenuData->ListboxEx)) return -1;
        pSubMenuData->User.Sel = TListboxEx_GetSel(&pSubMenuData->ListboxEx);
        Flag |= _FLAG_ENTER;
    }

    //进入指定层菜单后继处理
    if(Flag & _FLAG_ENTER) { //检查进入菜单
        pSubMenuData->Flag &= ~_FLAG_ENTER;

        Sel = pSubMenuData->User.Sel;
        pSubMenuData->User.UserFlag = 0;    //初始化
        if(pMenu->cbNotify) { //有回调函数时执行回调
            TMENU_NOTIFY_RUN(pMenu->cbNotify,TM_NOTIFY_SET_DATA,&pSubMenuData->User);
            pSubMenuData->User.Sel = Sel;//防止用户误选
            if(pSubMenuData->User.UserFlag == 1)
                return -1;//返回1时表示为命令,执行后不进入菜单
        }
        return (signed char)Sel;
    }

    //检查返回上层菜单
    if(Flag & _FLAG_RETURN)
        return -2;
    return -1;
}
Esempio n. 12
0
    //! Performing push operation. Notifies children and calls actual push
    //! method. Then cleans up the DIA graph by freeing parent references of
    //! children.
    void RunPushData() override {
        bool need_callback = false;
        for (const Child& child : children_)
            need_callback = need_callback || (child.callback != nullptr);
        if (!need_callback) {
            LOG0 << "RunPushData(): skip PushData as no callback";
            return;
        }

        for (const Child& child : children_)
            child.node->StartPreOp(child.parent_index);

        if (consume_counter() > 0 && consume_counter() != kNeverConsume)
            DecConsumeCounter(1);

        bool consume = context().consume() && consume_counter() == 0;
        PushData(consume);
        if (consume) Dispose();

        for (const Child& child : children_)
            child.node->StopPreOp(child.parent_index);
    }
Esempio n. 13
0
void Buffer<BUF_NODE_SZ>::PopData(int len) {
    _read_pos += len;
    if (_read_pos > _head->used) 
        _read_pos = _head->used;
    //move empty head node to tail
    if (_read_pos == _head->used && _head != _write_node) {
        BufferNode* cur = _head;
        _head = cur->next;
        cur->next = _tail->next;
        _tail->next = cur;
        _tail = cur;
        cur->used = 0;
        cur->next = NULL;
        if (_head == NULL) {//only one chunk node
            _tail = _head;
            return ;
        }
        //push the _write_node forward, so that next
        //GetSpace will success. Dont leave the to caller!
        PushData(0);
    } // else, Next Get Data will fail
}
Esempio n. 14
0
  void TcpEdge::Read()
  {
    int total_length = _socket->bytesAvailable();

    while(total_length >= 8) {
      QByteArray length_arr = _socket->peek(4);
      if(length_arr.isEmpty()) {
        qCritical() << "Error reading Tcp socket in" << ToString();
        Close("Error reading Tcp socket");
        return;
      }

      int length = Serialization::ReadInt(length_arr, 0);
      if(length + 8 > total_length) {
        break;
      }

      if(length < 0) {
        Close("Error reading Tcp socket");
        return;
      }

      QByteArray msg = _socket->read(length + 8);
      if(msg.isEmpty()) {
        Close("Error reading Tcp socket");
        qCritical() << "Error reading Tcp socket in" << ToString();
        return;
      }

      if(Serialization::ReadInt(msg, length + 4) != 0) {
        qCritical() << "Mismatch on byte array!";
      }

      PushData(msg.mid(4, length), this);
      total_length = _socket->bytesAvailable();
    }
  }
Esempio n. 15
0
bool Disasm::ParsePCL6() {
	uint8 byte;
	while (fStream->ReadUByte(byte)) {
		if (IsOperator(byte)) {
			if (!DecodeOperator(byte)) return false;
		} else if (IsDataType(byte)) {
			if (!PushData(byte)) return false;
		} else if (IsAttribute(byte)) {
			bool ok = DecodeAttribute(byte);
			ClearAttrs();
			if (!ok) return false;
		} else if (IsEmbedData(byte)) {
			if (!DecodeEmbedData(byte)) return false;
		} else if (IsWhiteSpace(byte)) {
			// nothing to do
		} else if (IsEsc(byte)) {
			return true;
		} else {
			Error("Unknown byte in input stream");
			return false;
		}
	}
	return true;
}
Esempio n. 16
0
 void Round::PushData(int uid, const QByteArray &data)
 {
   GetBuddyMonitor()->SetActiveNym(uid);
   PushData(GetSharedPointer(), data);
 }
Esempio n. 17
0
 void IncomingData(const QSharedPointer<ISender> &from,
     const QByteArray &data)
 {
   PushData(from, data);
 }
Esempio n. 18
0
 inline virtual void HandleData(const QSharedPointer<ISender> &,
     const QByteArray &data)
 {
   PushData(GetSharedPointer(), data);
 }
Esempio n. 19
0
void LAYER::LayPath( int32_t wX, int32_t wY )
{
	int DeltaDir;
	LOGICAL bLoop = FALSE, bIsRetry;  // no looping....
	int tx, ty;
	int nPathLayed = 0;
	int nDir, nNewDir;
	LOGICAL bBackTrace = FALSE,
		bFailed = FALSE;

	PLAYER_PATH_NODE node;
	lprintf( WIDE("Laying path %p to %d,%d"), this, wX, wY );
	node = (PLAYER_PATH_NODE)PeekData( &pds_path );
	// sanity validations...
	// being done already, etc...
	wX -= LAYER::x;
	wY -= LAYER::y;
	if( node )
	{
		if( node->x == wX && node->y == wY )
		{
			lprintf( WIDE("Already at this end point, why are you telling me to end where I already did?") );
			return;
		}
		// should range check wX and wY to sane limits
		// but for now we'll trust the programmer...
		if( abs( node->x - wX ) > 100 || abs( node->y - wY ) > 100 )
		{
			DebugBreak();
			lprintf( WIDE("Laying a LONG path - is this okay?!") );
		}
	}

	#ifdef DEBUG_BACKTRACE
		Log( WIDE("Enter...") );
	#endif

		//------------ FORWARD DRAWING NOW .....
	bIsRetry = FALSE;
	DeltaDir = 0;
	{
		PLAYER_PATH_NODE node;
		// get the last node in the path.
		node = (PLAYER_PATH_NODE)PeekData( &pds_path );
		while( node )
		{
			nNewDir = FindDirection( node->x
										  , node->y
										  , wX, wY );
			if( nNewDir == NOWHERE )
			{
				// already have this node at the current spot...
				lprintf( WIDE("Node has ended here...") );
				break;
			}
			nDir = NOWHERE; // intialize this, in case we missed a path below...
			if( node->flags.BackDir == NOWHERE )
			{
				// if it is newdir, we're okay to go ahead with this plan.
				if( node->flags.ForeDir != nNewDir && flags.bForced )
				{
					lprintf( WIDE("Have a forced begin point, and no way to get there from here....") );
					DebugBreak();
					if( NearDir( node->flags.ForeDir, nNewDir ) == 10 )
					{
						lprintf( WIDE("MUST go %d , have to go %d from here.  Go nowhere."), node->flags.ForeDir, nNewDir );
						lprintf( WIDE("Okay - consider a arbitrary jump to go forward... until we can go backward.") );
					}
					else
					{
						lprintf( WIDE("It's just not quite right... return, a less radical assumption may be made.") );
					}
					return;
				}
				// else, just go ahead, we returned above here.
				node->flags.ForeDir = nNewDir;
			}
			else
			{
				// need to determine a valid foredir based on nNewDir desire, and nBackDir given.
				lprintf( WIDE("%d, %d = %d")
						 , Opposite( node->flags.BackDir )
						 , nNewDir
						 , NearDir(Opposite( node->flags.BackDir )
									 , nNewDir ) );
				lprintf( WIDE("newdir = %d backdir = %d"), nNewDir, node->flags.BackDir );
				//pold->TopLayer->ForeDir;
				if( NearDir( nNewDir, Opposite( node->flags.BackDir ) ) != 10 )
				{
					// this is a valid direction to go.
					node->flags.ForeDir = nNewDir;
				}
				else
				{
					lprintf( WIDE("Unlay path cause we can't get there from here.") );
					node = UnlayPath( nPathLayed + 1 );
					// at this point always unlay at least one more than we put down.
					nPathLayed = 1;
					continue;
#if 0
               int nBase = Opposite( node->flags.BackDir );
					nDir = ( node->flags.BackDir + 2 ) & 7;
					if( NearDir( nNewDir, nDir ) != 10 )
					{
						//node->flags.ForeDir = (nBase + 6) &7;
						node->flags.ForeDir = Right( nBase );
					}
					else if( NearDir( nNewDir, Opposite( nDir ) ) != 10 )
					{
						node->flags.ForeDir = Left(nBase);
					}
					else
					{

						// this should be a random chance to go left or right...
						// maybe tend to the lower x or higher x ?
						lprintf( WIDE("Choosing an arbitrary directino of 1, and only on1") );
						//node->flags.ForeDir = Right( nBase + 1 );
						node->flags.bFlopped = 0;
						node->flags.bTry = 1;
						node->flags.bForced = 1;
						node->flags.ForeDir = LeftOrRight( nBase, node->flags.bFlopped );
						// set a flag in this node for which way to go...
						// but a left/right node needs the ability
						// to remain forced for a single unlay, and move in a direction...

					}
#endif
				}
			}
			{
				int  n;
				tx = node->x + DirDeltaMap[node->flags.ForeDir].x;
				ty = node->y + DirDeltaMap[node->flags.ForeDir].y;
				lprintf( WIDE("New coordinate will be %d,%d"), tx, ty );
				if( n = Overlaps( tx, ty ) ) // aleady drew something here...
					// the distance of the overlap is n layers, including Nth layer
					// for( ; n; PopData(&pds_stack), n-- )
					// and some fixups which unlay path does.
				{
					lprintf( WIDE("Unlaying path %d steps to overlap") , n );
					node = UnlayPath( n );
					// at an unlay point of forced, unlay path should be 'smart' and 'wait'
					// otherwise we may unwind to our tail and be confused... specially when moving away
					// and coming back to reside at the center.
					// if the force direction to go from a forced node is excessive, that definatly
					// breaks force, and releases the path node.
					// there may be board conditions which also determine the pathing.
					// okay try this again from the top do {
					// startin laying path again.
					continue;
				}
				// otherwise we're good to go foreward.
				// at least we won't add this node if it would have
				// already been there, heck, other than that via's
				// don't exist, sometimes we'll even get the exact node
				// that this should be....
				{
					LAYER_PATH_NODE newnode;
					// this may be set intrinsically by being an excessive force
					// causing a large direction delta
					newnode.flags.bForced = FALSE;
					newnode.flags.ForeDir = NOWHERE;
					// this of course must start(?) exactly how the other ended(?)...
					newnode.flags.BackDir = Opposite( node->flags.ForeDir );
					newnode.x = tx;
					newnode.y = ty;
					{
						int xx = tx + x;
						int yy = ty + y;
						if( xx < min_x )
						{
							w += min_x - xx;
							min_x = xx;
						}
						if( xx >= ( min_x + (int32_t)w ) )
							w = xx - min_x + 1;
						if( yy < min_y )
						{
							h += min_y - yy;
							min_y = yy;
						}
						if( yy >= ( min_y + (int32_t)h ) )
							h = yy - min_y + 1;

					}
					lprintf( WIDE("Push path %d,%d  min=%d,%d size=%d,%d"), newnode.x, newnode.y, min_x, min_y, w, h );
					PushData( &pds_path, &newnode );
					nPathLayed++;
					node = (PLAYER_PATH_NODE)PeekData( &pds_path ); // okay this is now where we are.
				}
			}
		}
	}
}
Esempio n. 20
0
// result is the last node (if any... which is a peekstack)
PLAYER_PATH_NODE LAYER::UnlayPath( int nLayers )
{
	// unwind to, and including this current spot.
	// this is to handle when the line intersects itself.
	// other conditions of unlaying via pathways may require
	// other functionality.
	int n;
	PLAYER_PATH_NODE node;// = (PLAYER_PATH_NODE)PopData( &pds_path );
	lprintf( WIDE("overlapped self at path segment %d"), nLayers );
	for( n = nLayers; (n && (node = (PLAYER_PATH_NODE)PopData( &pds_path ))), n; n-- )
	{
		lprintf( WIDE("Popped node %d(%p)"), n, node );
		// grab the NEXT node...
		// if it has bForced set... then this node must exist.
		PLAYER_PATH_NODE next = (PLAYER_PATH_NODE)PeekData( &pds_path );
		if( next && next->flags.bForced )
		{
			DebugBreak();
			node->flags.ForeDir = NOWHERE;
			return node;
		}
		if( node && node->flags.bForced )
		{
			DebugBreak();
         // this is SO bad.
		}
		//if( node->x == dest_x && node->y == dest_y )
		{
			//lprintf( WIDE("And then we find the node we overlaped...") );
		}
	}
	lprintf( WIDE("Okay done popping... %d, %p"), n, node );
	if( node )
	{
		PLAYER_PATH_NODE next = (PLAYER_PATH_NODE)PeekData( &pds_path );
		// set this as nowhere, so that we can easily just step forward here..
		if( !next )
		{
			if( !node->flags.bForced )
			{
				node->flags.ForeDir = NOWHERE;
			}
			PushData( &pds_path, node );
			return node;
		}
		if( !nLayers
			&& next->flags.bForced
			&& next->flags.BackDir != NOWHERE )
		{
			// if it was forced, then this MUST be here.  There is a reason.
			// there is also a way to end this reason, and unlay 0 path.  This
			// releases the foredir to anything.  This may be used for error correction path
			// assumptions?
			DebugBreak();
			if( next->flags.bTry )
			{
				node = (PLAYER_PATH_NODE)PopData(&pds_path );
				// this is the second attempt
				if( !node->flags.bFlopped )
				{
					node->flags.bFlopped = 1;
					node->flags.ForeDir = LeftOrRight( Opposite( node->flags.BackDir ), 1 );
               return node;
				}
			}
			next->flags.bForced = 0;
		}
		else
		{
			next->flags.ForeDir = NOWHERE;
         lprintf( WIDE("this node itself is okay...") );
		}
      return next;
	}
   return NULL;
}
Esempio n. 21
0
LAYER::LAYER( PODBC odbc, PLIST peices, INDEX iLoadLayer )
{
	if( !this )
		return;
	if( iLayer && iLayer != INVALID_INDEX )
	{
		lprintf( WIDE("Recovering prior layer") );
		return;
	}
	{
		CTEXTSTR *results;
		if( SQLRecordQueryf( odbc, NULL, &results, NULL
					  , WIDE("select x,y,min_x,min_y,width,height,linked_from_id,linked_from_x,linked_from_y,linked_to_id,linked_to_x,linked_to_y,route,peice_info_id,peice_type from board_layer where board_layer_id=%lu")
					  , iLoadLayer
					  ) && results )
		{
			PIPEICE peice_type = ::GetPeice( peices, results[14] );
			
			pLayerData->psvInstance = peice_type->Load( odbc, atoi( results[13] ) );//, pLayerData->psvInstance );
			pLayerData->SetPeice( peice_type );
			pds_path = CreateDataStack( sizeof( LAYER_PATH_NODE ) );
			x = atoi( results[0] );
			y = atoi( results[1] );
			min_x = atoi( results[2] );
			min_y = atoi( results[3] );
			w = IntCreateFromText( results[4] );
			h = IntCreateFromText( results[5] );
			flags.bRoute = atoi( results[12] );

		    iLayer = iLoadLayer;

			INDEX iStart = IntCreateFromText( results[6] );
			if( iStart != INVALID_INDEX )
			{
				int32_t x, y;
				x = atoi( results[7] );
				y = atoi( results[8] );
				PLAYER loaded_route_start_layer;
				loaded_route_start_layer = FindLayer( iStart );
				if( !loaded_route_start_layer )
					loaded_route_start_layer = GetFromSet( LAYER, pool ); //new(pool,pLayerData->pool) LAYER( odbc, peices, iStart );
				loaded_route_start_layer->pLayerData->peice->methods->ConnectBegin( loaded_route_start_layer->pLayerData->psvInstance
												, x, y // connect x, y
												, pLayerData->peice, pLayerData->psvInstance );
				loaded_route_start_layer->Link( this, LINK_VIA_START, x, y);
			}

			INDEX iEnd = IntCreateFromText( results[9] );
			if( iEnd != INVALID_INDEX )
			{
				int32_t x, y;
				x = atoi( results[10] );
				y = atoi( results[11] );
				PLAYER loaded_route_end_layer;
				loaded_route_end_layer = FindLayer( iEnd );
				if( !loaded_route_end_layer )
					loaded_route_end_layer = GetFromSet( LAYER, pool ); //new(pool,pLayerData->pool) LAYER( odbc, peices, iEnd );
				loaded_route_end_layer->pLayerData->peice->methods->ConnectEnd( loaded_route_end_layer->pLayerData->psvInstance
												, x, y // connect x, y
												, pLayerData->peice, pLayerData->psvInstance );
				loaded_route_end_layer->Link( this, LINK_VIA_END, x, y );
			}



			//}
		}
		SQLEndQuery( odbc );
		for( SQLRecordQueryf( odbc, NULL, &results, NULL, WIDE("select x,y,fore,back from board_layer_path where board_layer_id=%lu order by board_layer_path_id desc"), iLoadLayer );
			results;
			FetchSQLRecord( odbc, &results ) )
		{
			// add path node for a routed type peice
			LAYER_PATH_NODE node;
			node.x = atoi( results[0] );
			node.y = atoi( results[1] );
			node.flags.ForeDir = atoi( results[2] );
			node.flags.BackDir = atoi( results[3] );
			PushData( &pds_path, &node );
		}
	}
   //return iLayer;
}
Esempio n. 22
0
void UART_Write(uint8_t channel, char * data, uint16_t length) {
    if(channel >= NUM_UARTS) return;
    PushData(uart[channel].tx, data, length);
    UART_Tx_Start(channel);
}
Esempio n. 23
0
int CSvrLink::ExtCall(int sourceno, int destno, int funcno, int batchno, int acktime, void *rdata, int rdlen, char *abuf, int &alen)
{
   int rtn;
   char szmsg[256];
   ST_PACKHEAD phead;
   xcdata.sno = sourceno;
   xcdata.dno = destno;
   xcdata.fno = funcno;
   xcdata.bno = batchno;

   DecodeHead((unsigned char *)rdata,rdlen,&phead,szmsg);
   phead.userdata = batchno;
   ModifyHead(&phead,(unsigned char *)rdata);

   if (acktime<=0)
   {
      acktime = 5;  // 缺省为5秒钟内得到应答,否则作为失败处理。。。以防止业务部分调用错误导致整个BUNIT处理失败或挂起
   }
   rtn = PushData(sourceno,destno,funcno,batchno,PM_ANSWER,acktime,rdata,rdlen);
   while (rtn==0)
   {
      rtn = RecvMsg(acktime*1000+1000);
      if (rtn>0)
      {
         MSGBUF *pmb = GetRecvMsg();
         if (pmb->head.msgtype==MT_PUSHDATA)
         {
            // 有应答数据返回:
            alen = pmb->head.len;
            memcpy(abuf,pmb->data,alen);
            DecodeHead((unsigned char *)abuf,alen,&(xcdata.ahead),szmsg);
            // 为了正确提取外调功能的后续包(尤其对BCC能够支持并行多应用服务器架构),则采用
            if (xcdata.ahead.hook.queuename[0]>='0' && xcdata.ahead.hook.queuename[0]<='9'
               && xcdata.ahead.hook.queuetype>0)
            {
               // 属于KSBCC模式的XPACK协议:
               xcdata.fno = xcdata.ahead.hook.queuetype;
               // 包括能够处理被目标点转发后处理的请求
               if (0==xcdata.ahead.hook.hostname[0])
               {
                  int dno = atoi(xcdata.ahead.hook.hostname+1);
                  if (dno>0)
                  {
                     xcdata.dno = dno;
                  }
               }
               // m_bBCCADP:  2006-3-17 17:14:21
               else if (0!=xcdata.ahead.hook.hostname[10])
               {
                  int dno = atoi(xcdata.ahead.hook.hostname+10);
                  if (dno>0)
                  {
                     xcdata.dno = dno;
                  }
               }
               //////////////////////////////////////////////////////////////////////////
               
            }
            return(rtn);
         }
         else
         {
            DEBUG_RUNTIME_MSGOUT("ExtCall中间收到了非MT_PUSHDATA应答包,属于程序错误!");
            rtn = 0; // 继续读取数据,以便接收到正确的MT_PUSHDATA应答包
         }
      }
      else if (rtn==0)
      {
         return(-2);  // 等待应答数据超时,即自从向外发送了请求后,在acktime+1秒内没有接收到应答数据  
      }
   }
   return(-1); // 其他各种通讯方面的错误
}
Esempio n. 24
0
 inline virtual void HandleData(const QByteArray &data, ISender *)
 {
   PushData(data, this);
 }
Esempio n. 25
0
bool CWRequest::SendToServer(string sServerPath, string* pSessionID, string sRequestID, bool bLongPolling, bool bKeepAlive, string* pErrorMessage)
{
    string session_id = *pSessionID;

    if(session_id == "" || !IsServerRunning(session_id, INSTANCE_CHECK_TIMEOUT, pErrorMessage))
    {
        if(bLongPolling || bKeepAlive)
            return false;

        if(!StartServer(sServerPath, INSTANCE_START_TIMEOUT, &session_id, pErrorMessage))
            return false;
    }

    // ---
    // write request to file
    // ---
    string request_filename = TempDir() + sRequestID + ".request";

    int fd = -1;
    if(!FileCreateNonExistingAndLock(request_filename, REQUEST_WRITE_TIMEOUT, &fd, pErrorMessage))
        return false;

    // query
    if(!FileWriteStringList(fd, Query, pErrorMessage))
    {
        FileUnlockAndClose(fd, NULL);
        return false;
    }

    // post
    if(!FileWriteStringList(fd, Post, pErrorMessage))
    {
        FileUnlockAndClose(fd, NULL);
        return false;
    }

    // cookie
    if(!FileWriteStringList(fd, Cookie, pErrorMessage))
    {
        FileUnlockAndClose(fd, NULL);
        return false;
    }

    // env
    if(!FileWriteStringList(fd, Env, pErrorMessage))
    {
        FileUnlockAndClose(fd, NULL);
        return false;
    }

    FileUnlockAndClose(fd, NULL);

    // request type
    string queue_filename = "";
    if(bLongPolling)
        queue_filename = TempDir() + session_id + ".queue_lp";
    else
        queue_filename = TempDir() + session_id + ".queue";

    // ---
    // register request in queue
    // ---
    if(!PushData(queue_filename, (char*)sRequestID.c_str(), sRequestID.size(), REQUEST_SEND_TIMEOUT, pErrorMessage))
        return false;

    *pSessionID = session_id;

    Clear();

    return true;
}
Esempio n. 26
0
File: calc.c Progetto: uning/system
int main(int argc, char **argv)
{
	int FState,LState,GramState,CalcuState;
	double result,TempData;
	char TempOprt;
	STK.data_curp=STK.data_stack;
	STK.oprt_curp=STK.oprt_stack;
	
	if (argc < 2)
	{
		Usage(argv[0]);
		return 1;
	}
	
	for (int i = 1; i < argc; i++)
	{
		strncat (liyx, argv[i], strlen(argv[i]));
	}
	
	strncat(liyx, "\n", strlen("\n"));
	
		
		clear(&STK);
		EXP_INIT=YES;
		BRACKET_COUNT=0;
		LState=100;
		GramState=1;
		CalcuState=1;
		
		do{
			FState=LState;
			if((LState=getexp(&STK.data_in,&STK.oprt_in))<0){
				error(LState);
				break;
			}
			if((GramState=checkgram(FState,LState))<0){
				error(GramState);
				break;
			}
			if(LState==1||LState==2||LState==3||LState==4)
				PushData(&STK);
			if(LState==2||(LState==6&&(FState==3||FState==7))){
				TempOprt=STK.oprt_in;
				STK.oprt_in='*';
			}
			while(priority(*(STK.oprt_curp),STK.oprt_in)>0&& *STK.oprt_curp!='(' && STK.oprt_curp!=STK.oprt_stack)
			{
				PopData(&STK);
				TempData=STK.data_out;
				PopData(&STK);
				PopOprt(&STK);
				CalcuState=calculat(STK.data_out,STK.oprt_out,TempData,&result);
				if(CalcuState<0) break;
				STK.data_in=result;
				PushData(&STK);
			}
			if(*STK.oprt_curp=='(' && (LState==3||LState==7)) PopOprt(&STK);
			if(!(LState==3||LState==4||LState==7||LState==8)) PushOprt(&STK);
			if(LState==2||(LState==6&&(FState==3||FState==7))){
				STK.oprt_in=TempOprt;
				PushOprt(&STK);
			}
			if(CalcuState<0){
				error(CalcuState);
				break;
			}

		}while (LState!=4&&LState!=8);

		if((LState==4||LState==8)&&BRACKET_COUNT!=0) error(-8);


		if((LState==4||LState==8) && BRACKET_COUNT==0 && GramState>0 && CalcuState>0 && FState+LState!=108)
			printf("%f\n",STK.data_in);

	return 0;
}