void ContentLayer::replaceTopNode(Layout *node, Transition *enterTransition, Transition *exitTransition) {
	if (!_nodes.empty()) {
		auto back = _nodes.back();
		back->retain();
		_nodes.popBack();
		back->onPopTransitionBegan(this, false);

		auto tit = _exitTransitions.find(back);
		if (tit != _exitTransitions.end()) {
			safe_retain(node);
			safe_retain(enterTransition);
			safe_retain(exitTransition);
			back->runAction(action::callback(tit->second, [this, back, node, enterTransition, exitTransition] {
				eraseNode(back);
				back->onPop(this, false);
				back->release();
				pushNode(node, enterTransition, exitTransition);
				safe_release(node);
				safe_release(enterTransition);
				safe_release(exitTransition);
			}));
		} else {
			eraseNode(back);
			back->onPop(this, false);
			back->release();
			pushNode(node, enterTransition, exitTransition);
		}
	}
}
Exemple #2
0
Node *buildExpressionTree(char *expression) {

	NodeStack *operands = createNodeStack();
	NodeStack *result = createNodeStack();
	
	char *start = expression;
	char *end; // = expression;	
	char *beginning = expression;

	Stack *target;
	Node *node;
	Node *operand1;
	Node *operand2;
	
	while((start - beginning) < strlen(expression)) {
		if(start[0] - 0 == 39) {
			end = strstr(start + 1, "'") + 1;
		} else {
			end = strstr(start, " ");	
			if(!end) {
				end = start;
				while(end[0] != '\0')
					++end;
			}
		}
		
		char *token = malloc((end - start) + 1);
		strlcpy(token, start, (end - start) + 1);
		start = end + 1;	

		node = createNode(token);

		if(isBinaryOperator(token)) {
			target = result;
		} else if(isLogicalOperator(token)) { 
			target = operands;
		} else { 
			pushNode(operands, node);		
			continue;
		}		
	
		operand1 = popNode(target);
		operand2 = popNode(target);		
		node->right = operand1;
		node->left = operand2;

		// add this to stack
		pushNode(result, node);
	}

	// return the first node in the list (not the top)
    	return rootNode(result);
}
Exemple #3
0
// - A ripple nodes output issuer must be the node's account or the next node's
//   account.
// - Offers can only go directly to another offer if the currency and issuer are
//   an exact match.
// - Real issuers must be specified for non-XRP.
TER PathState::pushImpliedNodes (
    AccountID const& account,    // --> Delivering to this account.
    Currency const& currency,  // --> Delivering this currency.
    AccountID const& issuer)    // --> Delivering this issuer.
{
    TER resultCode = tesSUCCESS;

     JLOG (j_.trace) << "pushImpliedNodes>" <<
         " " << account <<
         " " << currency <<
         " " << issuer;

    if (nodes_.back ().issue_.currency != currency)
    {
        // Currency is different, need to convert via an offer from an order
        // book.  xrpAccount() does double duty as signaling "this is an order
        // book".

        // Corresponds to "Implies an offer directory" in the diagram, currently
        // at http://goo.gl/Uj3HAB.

        auto type = isXRP(currency) ? STPathElement::typeCurrency
            : STPathElement::typeCurrency | STPathElement::typeIssuer;

        // The offer's output is what is now wanted.
        // xrpAccount() is a placeholder for offers.
        resultCode = pushNode (type, xrpAccount(), currency, issuer);
    }


    // For ripple, non-XRP, ensure the issuer is on at least one side of the
    // transaction.
    if (resultCode == tesSUCCESS
        && !isXRP(currency)
        && nodes_.back ().account_ != issuer
        // Previous is not issuing own IOUs.
        && account != issuer)
        // Current is not receiving own IOUs.
    {
        // Need to ripple through issuer's account.
        // Case "Implies an another node: (pushImpliedNodes)" in the document.
        // Intermediate account is the needed issuer.
        resultCode = pushNode (
            STPathElement::typeAll, issuer, currency, issuer);
    }

    JLOG (j_.trace)
        << "pushImpliedNodes< : " << transToken (resultCode);

    return resultCode;
}
Exemple #4
0
void dumpEverything(std::ostream& out, VMState& vm) {

    // Stacks are printed from bottom to top, so the rightmost element
    // is the top stack element

    out << "%ptr  : " <<      DebugObject{ vm.trans.ptr } << std::endl;
    out << "%slf  : " <<      DebugObject{ vm.trans.slf } << std::endl;
    out << "%ret  : " <<      DebugObject{ vm.trans.ret } << std::endl;

    out << "%lex  : " << DebugStackObject{ vm.state.lex  } << std::endl;
    out << "%dyn  : " << DebugStackObject{ vm.state.dyn  } << std::endl;
    out << "%arg  : " << DebugStackObject{ vm.state.arg  } << std::endl;
    out << "%sto  : " << DebugStackObject{ vm.state.sto  } << std::endl;
    out << "%hand : " << DebugStackObject{ vm.state.hand } << std::endl;

    out << "%err0 : " << vm.trans.err0 << std::endl;
    out << "%err1 : " << vm.trans.err1 << std::endl;

    out << "%sym  : " << Symbols::get()[vm.trans.sym] << std::endl;
    out << "%num0 : " << vm.trans.num0.asString() << std::endl;
    out << "%num1 : " << vm.trans.num1.asString() << std::endl;

    out << "%str0 : " << vm.trans.str0 << std::endl;
    out << "%str1 : " << vm.trans.str1 << std::endl;

    out << "%flag : " << vm.trans.flag << std::endl;
    out << "%trace:";
    dumpBT(out, pushNode(vm.state.trace, std::make_tuple(vm.state.line, vm.state.file)));
    out << std::endl;

}
void CreateScene::visit(ColladaNode* colladaNode) {
	Node* newNode = product->createNode();

	concatNode(newNode);

	pushNode(newNode);

	for(ColladaTransformation* transformation : colladaNode->getTransformations())
		transformation->accept(this);

	for(ColladaNode* child : colladaNode->getNodes())
		child->accept(this);

	for(ColladaInstanceNode* instanceNode : colladaNode->getInstanceNodes()) {
		ColladaNode* node = document->findNode(instanceNode->getUrl());

		if(node)
			node->accept(this);
	}

	for(ColladaInstanceGeometry* instanceGeometry : colladaNode->getInstanceGeometries())
		instanceGeometry->accept(this);

	popNode();
}
Exemple #6
0
// Make sure last path node delivers to uAccountID: uCurrencyID from uIssuerID.
//
// If the unadded next node as specified by arguments would not work as is, then add the necessary nodes so it would work.
//
// Rules:
// - Currencies must be converted via an offer.
// - A node names it's output.
// - A ripple nodes output issuer must be the node's account or the next node's account.
// - Offers can only go directly to another offer if the currency and issuer are an exact match.
// - Real issuers must be specified for non-STR.
TER PathState::pushImply (
    const uint160& uAccountID,  // --> Delivering to this account.
    const uint160& uCurrencyID, // --> Delivering this currency.
    const uint160& uIssuerID)   // --> Delivering this issuer.
{
    const Node&  pnPrv       = vpnNodes.back ();
    TER          terResult   = tesSUCCESS;

    WriteLog (lsTRACE, RippleCalc) << "pushImply>" <<
        " " << RippleAddress::createHumanAccountID (uAccountID) <<
        " " << STAmount::createHumanCurrency (uCurrencyID) <<
        " " << RippleAddress::createHumanAccountID (uIssuerID);

    if (pnPrv.uCurrencyID != uCurrencyID)
    {
        // Currency is different, need to convert via an offer.

        terResult   = pushNode ( // Offer.
                          !!uCurrencyID
                          ? STPathElement::typeCurrency | STPathElement::typeIssuer
                          : STPathElement::typeCurrency,
                          ACCOUNT_STR,                    // Placeholder for offers.
                          uCurrencyID,                    // The offer's output is what is now wanted.
                          uIssuerID);
    }

    const Node&  pnBck       = vpnNodes.back ();

    // For ripple, non-STR, ensure the issuer is on at least one side of the transaction.
    if (tesSUCCESS == terResult
            && !!uCurrencyID                                // Not STR.
            && (pnBck.uAccountID != uIssuerID               // Previous is not issuing own IOUs.
                && uAccountID != uIssuerID))                // Current is not receiving own IOUs.
    {
        // Need to ripple through uIssuerID's account.

        terResult   = pushNode (
                          STPathElement::typeAccount | STPathElement::typeCurrency | STPathElement::typeIssuer,
                          uIssuerID,                      // Intermediate account is the needed issuer.
                          uCurrencyID,
                          uIssuerID);
    }

    WriteLog (lsTRACE, RippleCalc) << "pushImply< : " << transToken (terResult);

    return terResult;
}
Exemple #7
0
void qore_queue_private::pushIntern(AbstractQoreNode* v) {
   pushNode(v);
   //printd(5, "qore_queue_private::push_internal(%p) this=%p head=%p (%p) tail=%p (%p) waiting=%d len=%d\n", v, this, head, head->node, tail, tail->node, waiting, len);

   // signal waiting thread to wakeup and process event
   if (read_waiting)
      read_cond.signal();
}
Exemple #8
0
//formatstring wrapper
void TagTree::pushNode(const char* format, ...)
{
	char buffer[XMPQE_BUFFERSIZE];
	va_list args;
	va_start(args, format);
		vsprintf(buffer, format, args);
	va_end(args);

	pushNode( std::string(buffer) );
}
int main(int argc, char *argv[])
{
    QCoreApplication a(argc, argv);
    /*
    struct node *a=NULL;
    struct node *b=NULL;
    struct node *c=NULL;
    a=(struct node *)malloc(sizeof(struct node));
    b=(struct node *)malloc(sizeof(struct node));
    c=(struct node *)malloc(sizeof(struct node));
    a->data=1;
    a->next=b;
    b->data=2;
    b->next=c;
    c->data=3;
    c->next=NULL;
    printNode(a);
    */
    node *head=NULL;
    //append(&head,1);
    //push(&head,2);
    /*
    insertNodeAt(&head,0,2);
    insertNodeAt(&head,1,3);
    insertNodeAt(&head,2,4);
    insertNodeAt(&head,3,5);
    printNode(head);
    deleteNode(&head,0);
    printNode(head);
    */
    pushNode(&head, 1);
    pushNode(&head, 2);
    pushNode(&head, 3);
    pushNode(&head, 4);
    pushNode(&head, 5);
    printNode(head);
    //deleteNode(&head, 4);
    //swapNode(&head,5,4);
    //swapNodes(&head,7,1);
    invertNode(&head);
    printNode(head);
}
void ContentLayer::replaceNode(Layout *node, Transition *enterTransition) {
	if (node && !node->isRunning()) {
		if (_nodes.empty()) {
			pushNode(node, enterTransition);
			return;
		}

		int zIndex = -(int)_nodes.size();
		for (auto node : _nodes) {
			node->setLocalZOrder(zIndex);
			zIndex ++;
		}

		_nodes.pushBack(node);

		node->ignoreAnchorPointForPosition(false);
		node->setAnchorPoint(Vec2(0.5f, 0.5f));
		node->setPosition(_contentSize.width / 2.0f, _contentSize.height / 2.0f);
		node->setContentSize(_contentSize);
		addChild(node, 1);

		for (auto &it : _nodes) {
			if (it != node) {
				it->onPopTransitionBegan(this, true);
			} else {
				it->onPush(this, true);
			}
		}

		if (enterTransition) {
			node->runAction(action::callback(enterTransition, [this, node] {
				for (auto &it : _nodes) {
					if (it != node) {
						it->onPop(this, true);
					} else {
						it->onPushTransitionEnded(this, true);
					}
				}
				replaceNodes();
			}));
		} else {
			for (auto &it : _nodes) {
				if (it != node) {
					it->onPop(this, true);
				} else {
					it->onPushTransitionEnded(this, true);
				}
			}
			replaceNodes();
		}

		_listener->setEnabled(true);
	}
}
void CreateScene::visit(ColladaScene* scene) {
	ColladaInstanceVisualScene* instanceVisualScene = scene->getInstanceVisualScene();

	ColladaVisualScene* visualScene = document->findVisualScene(instanceVisualScene->getUrl());

	if(!visualScene)
		return;

	product = new Scene(visualScene->getId(), manager);

	pushNode(product->getRoot());

	for(ColladaNode* node : visualScene->getNodes()) {
		if(!node->getInstanceControllers().empty()) //TODO animation
			continue;

		node->accept(this);
	}

	popNode();
}
ListNode* Solution::mergeKLists(vector<ListNode*> &A) {
    priority_queue < pair <int, ListNode*>, vector< pair <int, ListNode* > >, greater <pair<int, ListNode*> > > q;
    
    vector<ListNode*>::iterator x;
    
    for(x=A.begin(); x!=A.end(); x++){
        q.push(make_pair ( (*x)->val, *x));
    }
    
    ListNode* ans = NULL;
    
    while(q.empty()!=true){
        pushNode((q.top()).first, &ans);
        ListNode* forNext = q.top().second->next;
        q.pop();
        
        if(forNext)
            q.push(make_pair ( forNext->val, forNext));
    }
    
    return ans;
}
Exemple #13
0
// Adds a new key, value pair to the table 
void add(hash_t *hashTable, void *key, void *value) {
    printf("Adding (%s, %s)\n", key, value);
    // Make sure adding the node isn't going to push the hash table over the max load factor
    if ((hashTable->keys + 1.0) / hashTable->capacity > MAX_LOAD_FACTOR) {
        // Doubles the number of buckets in the table and rehashes all of the keys
        resize(hashTable);
    }

    // Hash the key
    unsigned long hKey = hash(hashTable->capacity, key); 
    list_t *bucket;

    // The buckets are lazy initialized
    if (hashTable->buckets[hKey] == NULL) { 
       hashTable->buckets[hKey] = newList(); 
    }

    bucket = hashTable->buckets[hKey];
    pushNode(bucket, key, value); 

    hashTable->keys++;
    printf("Added %s to bucket %ld size: %zu\n", key, hKey, bucket->size);
}
Exemple #14
0
bool OpenDDLParser::parse() {
    if( m_buffer.empty() ) {
        return false;
    }

    normalizeBuffer( m_buffer );

    m_context = new Context;
    m_context->m_root = DDLNode::create( "root", "", ddl_nullptr );
    pushNode( m_context->m_root );

    // do the main parsing
    char *current( &m_buffer[ 0 ] );
    char *end( &m_buffer[m_buffer.size() - 1 ] + 1 );
    size_t pos( current - &m_buffer[ 0 ] );
    while( pos < m_buffer.size() ) {
        current = parseNextNode( current, end );
        if ( current == ddl_nullptr ) {
            return false;
        }
        pos = current - &m_buffer[ 0 ];
    }
    return true;
}
Exemple #15
0
// Set to an expanded path.
//
// terStatus = tesSUCCESS, temBAD_PATH, terNO_LINE, terNO_ACCOUNT, terNO_AUTH, or temBAD_PATH_LOOP
void PathState::setExpanded (
    const LedgerEntrySet&   lesSource,
    const STPath&           spSourcePath,
    const uint160&          uReceiverID,
    const uint160&          uSenderID
)
{
    uQuality    = 1;            // Mark path as active.

    const uint160   uMaxCurrencyID  = saInReq.getCurrency ();
    const uint160   uMaxIssuerID    = saInReq.getIssuer ();

    const uint160   uOutCurrencyID  = saOutReq.getCurrency ();
    const uint160   uOutIssuerID    = saOutReq.getIssuer ();
    const uint160   uSenderIssuerID = !!uMaxCurrencyID ? uSenderID : ACCOUNT_STR;   // Sender is always issuer for non-STR.

    WriteLog (lsTRACE, RippleCalc) << "setExpanded> " << spSourcePath.getJson (0);

    lesEntries  = lesSource.duplicate ();

    terStatus   = tesSUCCESS;

    // STR with issuer is malformed.
    if ((!uMaxCurrencyID && !!uMaxIssuerID) || (!uOutCurrencyID && !!uOutIssuerID))
        terStatus   = temBAD_PATH;

    // Push sending node.
    // For non-STR, issuer is always sending account.
    // - Trying to expand, not-compact.
    // - Every issuer will be traversed through.
    if (tesSUCCESS == terStatus)
        terStatus   = pushNode (
                          !!uMaxCurrencyID
                          ? STPathElement::typeAccount | STPathElement::typeCurrency | STPathElement::typeIssuer
                          : STPathElement::typeAccount | STPathElement::typeCurrency,
                          uSenderID,
                          uMaxCurrencyID,                                 // Max specifies the currency.
                          uSenderIssuerID);

    WriteLog (lsDEBUG, RippleCalc) << "setExpanded: pushed:" <<
        " account=" << RippleAddress::createHumanAccountID (uSenderID) <<
        " currency=" << STAmount::createHumanCurrency (uMaxCurrencyID) <<
        " issuer=" << RippleAddress::createHumanAccountID (uSenderIssuerID);

    if (tesSUCCESS == terStatus
            && uMaxIssuerID != uSenderIssuerID)                 // Issuer was not same as sender.
    {
        // May have an implied account node.
        // - If it was STR, then issuers would have matched.

        // Figure out next node properties for implied node.
        const uint160   uNxtCurrencyID  = spSourcePath.size ()
                                          ? spSourcePath.getElement (0).getCurrency () // Use next node.
                                          : uOutCurrencyID;                           // Use send.
        const uint160   uNxtAccountID   = spSourcePath.size ()
                                          ? spSourcePath.getElement (0).getAccountID ()
                                          : !!uOutCurrencyID
                                          ? uOutIssuerID == uReceiverID
                                          ? uReceiverID
                                          : uOutIssuerID                      // Use implied node.
                                  : ACCOUNT_STR;

        WriteLog (lsDEBUG, RippleCalc) << "setExpanded: implied check:" <<
            " uMaxIssuerID=" << RippleAddress::createHumanAccountID (uMaxIssuerID) <<
            " uSenderIssuerID=" << RippleAddress::createHumanAccountID (uSenderIssuerID) <<
            " uNxtCurrencyID=" << STAmount::createHumanCurrency (uNxtCurrencyID) <<
            " uNxtAccountID=" << RippleAddress::createHumanAccountID (uNxtAccountID);

        // Can't just use push implied, because it can't compensate for next account.
        if (!uNxtCurrencyID                         // Next is STR, offer next. Must go through issuer.
                || uMaxCurrencyID != uNxtCurrencyID // Next is different currency, offer next...
                || uMaxIssuerID != uNxtAccountID)   // Next is not implied issuer
        {
            WriteLog (lsDEBUG, RippleCalc) << "setExpanded: sender implied:" <<
                " account=" << RippleAddress::createHumanAccountID (uMaxIssuerID) <<
                " currency=" << STAmount::createHumanCurrency (uMaxCurrencyID) <<
                " issuer=" << RippleAddress::createHumanAccountID (uMaxIssuerID);

            // Add account implied by SendMax.
            terStatus   = pushNode (
                !!uMaxCurrencyID
                    ? STPathElement::typeAccount | STPathElement::typeCurrency | STPathElement::typeIssuer
                    : STPathElement::typeAccount | STPathElement::typeCurrency,
                uMaxIssuerID,
                uMaxCurrencyID,
                uMaxIssuerID);
        }
    }

    BOOST_FOREACH (const STPathElement & speElement, spSourcePath)
    {
        if (tesSUCCESS == terStatus)
        {
            WriteLog (lsTRACE, RippleCalc) << "setExpanded: element in path";
            terStatus   = pushNode (
                speElement.getNodeType (), speElement.getAccountID (), 
                speElement.getCurrency (), speElement.getIssuerID ());
        }
    }

    const Node&  pnPrv           = vpnNodes.back ();

    if (tesSUCCESS == terStatus
            && !!uOutCurrencyID                         // Next is not STR
            && uOutIssuerID != uReceiverID              // Out issuer is not receiver
            && (pnPrv.uCurrencyID != uOutCurrencyID     // Previous will be an offer.
                || pnPrv.uAccountID != uOutIssuerID))   // Need the implied issuer.
    {
        // Add implied account.
        WriteLog (lsDEBUG, RippleCalc) << "setExpanded: receiver implied:" <<
            " account=" << RippleAddress::createHumanAccountID (uOutIssuerID) <<
            " currency=" << STAmount::createHumanCurrency (uOutCurrencyID) <<
            " issuer=" << RippleAddress::createHumanAccountID (uOutIssuerID);

        terStatus   = pushNode (
            !!uOutCurrencyID
                ? STPathElement::typeAccount | STPathElement::typeCurrency | STPathElement::typeIssuer
                : STPathElement::typeAccount | STPathElement::typeCurrency,
            uOutIssuerID,
            uOutCurrencyID,
            uOutIssuerID);
    }

    if (tesSUCCESS == terStatus)
    {
        // Create receiver node.
        // Last node is always an account.

        terStatus   = pushNode (
            !!uOutCurrencyID
                ? STPathElement::typeAccount | STPathElement::typeCurrency | STPathElement::typeIssuer
                : STPathElement::typeAccount | STPathElement::typeCurrency,
            uReceiverID,                                    // Receive to output
            uOutCurrencyID,                                 // Desired currency
            uReceiverID);
    }

    if (tesSUCCESS == terStatus)
    {
        // Look for first mention of source in nodes and detect loops.
        // Note: The output is not allowed to be a source.

        const unsigned int  uNodes  = vpnNodes.size ();

        for (unsigned int uNode = 0; tesSUCCESS == terStatus && uNode != uNodes; ++uNode)
        {
            const Node&  pnCur   = vpnNodes[uNode];

            if (!umForward.insert (std::make_pair (std::make_tuple (pnCur.uAccountID, pnCur.uCurrencyID, pnCur.uIssuerID), uNode)).second)
            {
                // Failed to insert. Have a loop.
                WriteLog (lsDEBUG, RippleCalc) <<
                    "setExpanded: loop detected: " << getJson ();

                terStatus   = temBAD_PATH_LOOP;
            }
        }
    }

    WriteLog (lsDEBUG, RippleCalc) << "setExpanded:" <<
        " in=" << STAmount::createHumanCurrency (uMaxCurrencyID) <<
        "/" << RippleAddress::createHumanAccountID (uMaxIssuerID) <<
        " out=" << STAmount::createHumanCurrency (uOutCurrencyID) <<
        "/" << RippleAddress::createHumanAccountID (uOutIssuerID) <<
        ": " << getJson ();
}
Exemple #16
0
static int two(global **contain){
	/*load stack*/
	global *container = *contain;
	FILE *stream;/*file reading from*/
	char *inp;
        long long perc = 0; /*percentage complete*/
	long long length = 0;/*length of import file*/
	int a,b,c,d,t,co;
	char *line = calloc(sizeof(int),MAXLEN);
	int j=0;/*used to check EOF*/
	printf("\nPlease select file\n>");
	co=True;/*repeat version check once*/
	inp = getInput();
	stream=fopen(inp,"r");
	if(!stream){/*cannot read from*/
	   free(inp);
	   inp=NULL;
	   free(line);
	   line = NULL;
	   return False;
	}
	struct stat statbuf;
        stat(inp, &statbuf);
        length=statbuf.st_size;
	free(inp);
	inp=NULL;
	/*check if this is a wellformed file*/
	a=fgetc(stream);
	b=fgetc(stream);
	c=fgetc(stream);
	d=fgetc(stream);
	if(a!=0x5A  || b!=0xB1 || c!=0xF0 || d!=0x0A){/*does it have the header?*/
	   fprintf(stderr,"Error: Invalid header\n");
	   fclose(stream);
	   stream=NULL;
	   return False;/*not a valid file*/
	}
	/*begin import*/
	destroyContainer(&container);/*purge results*/
	resetContainer(&container);/*reset use*/
	/*scan document, and rebuild statistics for NEW file*/
	for(container ->total=0;j!= -1;container->total = container ->total+1){
	   j=get_line(line, stream);/*get line from file, is being given length of line*/
	   if(j==-1){/*breakouttahere!*/
	       break;
	   }
	   if(co==True){/*check this once*/
	      co=False;
		  t = checkForm(line);/*check if older type True if current, False if older*/
	   }
	   int le = 0;/*length of line*/
	   /*there are four items in this line*/
	   /*long name|unsigned int type|char *fil|long long address*/
	   char *tmp=NULL;/*ensure we have space*/
	   tmp=strTok(line,&le,'|');
	   if(tmp ==NULL){
	     break;
	   }
	   long name =atol(tmp);
	   free(tmp);
	   tmp=NULL;
	   
	   tmp=strTok(line,&le,'|');
	   if(tmp ==NULL){
	     break;
	   }
	   unsigned int type=atoi(tmp);
	   free(tmp);
	   tmp=NULL;
	   
       
	   unsigned int misc;
	   if(t==True){
	      tmp=strTok(line,&le,'|');
	      if(tmp ==NULL){
	        break;
	      }
	      misc=atoi(tmp);
	      free(tmp);
	      tmp=NULL;
	   }
	   else{
	      misc = 0x0000;
	   }
	   
	   char *fil =strTok(line,&le,'|');
	   if(fil ==NULL){
	     break;
	   }
	   tmp = strTok(line,&le,'\n');
	   if(tmp ==NULL){
	     break;
	   }
	   
	   long long addr = atoll(tmp);
	   free(tmp);
	   tmp=NULL;
	   /*add this thing to the stack*/
	  pushNode(createNode(name,fil,type, misc, addr),&container->head,&container->tail);
	  /*add type to collection*/
	  if((type & Po)==Po){/*picture*/
         container->picCount=container->picCount+1;
	  }
	  if((type & Eo)==Eo){/*executable*/
         container->exeCount=container->exeCount+1;
	  }
	  if((type & Wo)==Wo){/*audio*/
         container->wavCount=container->wavCount+1;
	  }
	  if((type & Vo)==Vo){/*video*/
         container->aviCount=container->aviCount+1;
	  }
	  if((type & To)==To){/*text*/
         container->docCount=container->docCount+1;
	  }
	  /*end add type to collection*/
	  free(fil);
	  fil=NULL;
	  perc = (ftell(stream)*100)/length;
	  fprintf(stderr,"Import %lld %% complete\r",perc);
	}/*end the importing*/
	fprintf(stderr,"\n");
	free(line);
	line = NULL;
	fclose(stream);
	stream=NULL;
	return True;
}
/*! \internal */
void SocialNetworkInterfacePrivate::pushPlaceHolderNode()
{
    pushNode(placeHolderNode);
}
 void push(const T &t) {
     pushNode(new TStackNode(t));
 }
 void push(T &&t) {
     pushNode(new TStackNode(std::move(t)));
 }
Exemple #20
0
int CScatteredManage::processJobs()
{
	SCNode nd;
	SCJob sj;
	tcps_Array<PCC_ModuleFile> moudleFiles;
	PCC_ModuleIndex index;
	//bool b_rest = true,b_r2 = false;
	int pre_node_num =-1;
	while (1)
	{
		if(pre_node_num != getNodeCounts())
		{
			printf("##当前可调度节点数:%d,待处理作业数:%d\n",pre_node_num = getNodeCounts(),getJobsCounts());
			
		}
		
		//检测job队列
		if(popJob(sj))
		{
			
			printf("当前可调度节点数:%d,待处理作业数:%d\n",getNodeCounts(),getJobsCounts()+1);

			//先判断jobkey对应的会话是否有效 //这一步看需求,是否支持不要回调通知的作业提交,这里标志以回调有效的方式处理
            if(!isValidJobRequest(sj.jobKey))
				continue;//忽略

			while(1)//轮询等待有空余节点可做scattered计算
			{
				
				if(popNode(nd))// 注意节点要在作业处理完后收回
				{
				    
					//nd.ps->m_ss = sj.ss;//回调senssion句柄 要是m_ss的servece_s的客户端断开了连接,这个指针会失效//jobkey
					
                    
					nd.ps->m_jobkey = sj.jobKey;
					printf("节点%p处理作业:%lld\n",nd.ps,sj.jobKey);
					index.moduleKey = sj.moduleKey;
					//确保节点端存在 moduleKey指定的模块
					moudleFiles.Release();
				    BOOL isFound = false;
					if(TCPS_OK ==nd.ps->FindModule(sj.moduleKey,isFound) )// 节点端没有,同步此模块
					{
						if(!isFound)
						{
							//读取模块 填充 index,moudleFiles
							if(getModules(index,moudleFiles))
							{
								//再次调用接口
								if(nd.ps->AddModule(sj.moduleKey,moudleFiles) != TCPS_OK)
								{
									nd.ps->m_ss = NULL;//for mark
									pushNode(nd.key,nd.ps);
									NPLogError(("模块更新失败,作业无法调度\n"));
									break;
								}
							}
							else
							{
								nd.ps->m_ss = NULL;//for mark
								pushNode(nd.key,nd.ps);
								NPLogError(("模块读取失败,作业无法调度\n"));
								break;
							}
						}
					}
					else
					{
						pushNode(nd.key,nd.ps);
						NPLogError(("无法获取模块状态!\n"));
						break;
					}
					//节点暂时分离出去了
					//这里应当添加节点处理超时
					nd.ps->Compute(sj.moduleKey,
					sj.jobKey,
					sj.info.dataInputUrl,
					sj.info.dataOutputUrl,
					sj.info.programParam);
					//nd.ps->AddMoudle(index,moudleFiles);
					//nd.ps->RemoveModule(0);
				
					break;
				}
				Sleep(1);
			}
		}
		
		Sleep(1);
	}
	return 0;
}
Exemple #21
0
// Set this object to be an expanded path from spSourcePath - take the implied
// nodes and makes them explicit.  It also sanitizes the path.
//
// There are only two types of nodes: account nodes and order books nodes.
//
// You can infer some nodes automatically.  If you're paying me bitstamp USD,
// then there must be an intermediate bitstamp node.
//
// If you have accounts A and B, and they're delivery currency issued by C, then
// there must be a node with account C in the middle.
//
// If you're paying USD and getting bitcoins, there has to be an order book in
// between.
//
// terStatus = tesSUCCESS, temBAD_PATH, terNO_LINE, terNO_ACCOUNT, terNO_AUTH,
// or temBAD_PATH_LOOP
TER PathState::expandPath (
    STPath const& spSourcePath,
    AccountID const& uReceiverID,
    AccountID const& uSenderID)
{
    uQuality = 1;            // Mark path as active.

    Currency const& uMaxCurrencyID = saInReq.getCurrency ();
    AccountID const& uMaxIssuerID = saInReq.getIssuer ();

    Currency const& currencyOutID = saOutReq.getCurrency ();
    AccountID const& issuerOutID = saOutReq.getIssuer ();
    AccountID const& uSenderIssuerID
        = isXRP(uMaxCurrencyID) ? xrpAccount() : uSenderID;
    // Sender is always issuer for non-XRP.

    JLOG (j_.trace)
        << "expandPath> " << spSourcePath.getJson (0);

    terStatus = tesSUCCESS;

    // XRP with issuer is malformed.
    if ((isXRP (uMaxCurrencyID) && !isXRP (uMaxIssuerID))
        || (isXRP (currencyOutID) && !isXRP (issuerOutID)))
    {
        JLOG (j_.debug)
            << "expandPath> issuer with XRP";
        terStatus   = temBAD_PATH;
    }

    // Push sending node.
    // For non-XRP, issuer is always sending account.
    // - Trying to expand, not-compact.
    // - Every issuer will be traversed through.
    if (terStatus == tesSUCCESS)
    {
        terStatus   = pushNode (
            !isXRP(uMaxCurrencyID)
            ? STPathElement::typeAccount | STPathElement::typeCurrency |
              STPathElement::typeIssuer
            : STPathElement::typeAccount | STPathElement::typeCurrency,
            uSenderID,
            uMaxCurrencyID, // Max specifies the currency.
            uSenderIssuerID);
    }

    JLOG (j_.debug)
        << "expandPath: pushed:"
        << " account=" << uSenderID
        << " currency=" << uMaxCurrencyID
        << " issuer=" << uSenderIssuerID;

    // Issuer was not same as sender.
    if (tesSUCCESS == terStatus && uMaxIssuerID != uSenderIssuerID)
    {
        // May have an implied account node.
        // - If it was XRP, then issuers would have matched.

        // Figure out next node properties for implied node.
        const auto uNxtCurrencyID  = spSourcePath.size ()
                ? Currency(spSourcePath.front ().getCurrency ())
                // Use next node.
                : currencyOutID;
                // Use send.

        // TODO(tom): complexify this next logic further in case someone
        // understands it.
        const auto nextAccountID   = spSourcePath.size ()
                ? AccountID(spSourcePath. front ().getAccountID ())
                : !isXRP(currencyOutID)
                ? (issuerOutID == uReceiverID)
                ? AccountID(uReceiverID)
                : AccountID(issuerOutID)                      // Use implied node.
                : xrpAccount();

        JLOG (j_.debug)
            << "expandPath: implied check:"
            << " uMaxIssuerID=" << uMaxIssuerID
            << " uSenderIssuerID=" << uSenderIssuerID
            << " uNxtCurrencyID=" << uNxtCurrencyID
            << " nextAccountID=" << nextAccountID;

        // Can't just use push implied, because it can't compensate for next
        // account.
        if (!uNxtCurrencyID
            // Next is XRP, offer next. Must go through issuer.
            || uMaxCurrencyID != uNxtCurrencyID
            // Next is different currency, offer next...
            || uMaxIssuerID != nextAccountID)
            // Next is not implied issuer
        {
            JLOG (j_.debug)
                << "expandPath: sender implied:"
                << " account=" << uMaxIssuerID
                << " currency=" << uMaxCurrencyID
                << " issuer=" << uMaxIssuerID;

            // Add account implied by SendMax.
            terStatus = pushNode (
                !isXRP(uMaxCurrencyID)
                    ? STPathElement::typeAccount | STPathElement::typeCurrency |
                      STPathElement::typeIssuer
                    : STPathElement::typeAccount | STPathElement::typeCurrency,
                uMaxIssuerID,
                uMaxCurrencyID,
                uMaxIssuerID);
        }
    }

    for (auto & speElement: spSourcePath)
    {
        if (terStatus == tesSUCCESS)
        {
            JLOG (j_.trace) << "expandPath: element in path";
            terStatus = pushNode (
                speElement.getNodeType (), speElement.getAccountID (),
                speElement.getCurrency (), speElement.getIssuerID ());
        }
    }

    if (terStatus == tesSUCCESS
        && !isXRP(currencyOutID)               // Next is not XRP
        && issuerOutID != uReceiverID)         // Out issuer is not receiver
    {
        assert (!nodes_.empty ());

        auto const& backNode = nodes_.back ();

        if (backNode.issue_.currency != currencyOutID  // Previous will be offer
            || backNode.account_ != issuerOutID)       // Need implied issuer
        {
            // Add implied account.
            JLOG (j_.debug)
                << "expandPath: receiver implied:"
                << " account=" << issuerOutID
                << " currency=" << currencyOutID
                << " issuer=" << issuerOutID;

            terStatus   = pushNode (
                !isXRP(currencyOutID)
                    ? STPathElement::typeAccount | STPathElement::typeCurrency |
                      STPathElement::typeIssuer
                    : STPathElement::typeAccount | STPathElement::typeCurrency,
                issuerOutID,
                currencyOutID,
                issuerOutID);
        }
    }

    if (terStatus == tesSUCCESS)
    {
        // Create receiver node.
        // Last node is always an account.

        terStatus   = pushNode (
            !isXRP(currencyOutID)
                ? STPathElement::typeAccount | STPathElement::typeCurrency |
                   STPathElement::typeIssuer
               : STPathElement::typeAccount | STPathElement::typeCurrency,
            uReceiverID,                                    // Receive to output
            currencyOutID,                                 // Desired currency
            uReceiverID);
    }

    if (terStatus == tesSUCCESS)
    {
        // Look for first mention of source in nodes and detect loops.
        // Note: The output is not allowed to be a source.
        unsigned int index = 0;
        for (auto& node: nodes_)
        {
            AccountIssue accountIssue (node.account_, node.issue_);
            if (!umForward.insert ({accountIssue, index++}).second)
            {
                // Failed to insert. Have a loop.
                JLOG (j_.debug) <<
                    "expandPath: loop detected: " << getJson ();

                terStatus = temBAD_PATH_LOOP;
                break;
            }
        }
    }

    JLOG (j_.debug)
        << "expandPath:"
        << " in=" << uMaxCurrencyID
        << "/" << uMaxIssuerID
        << " out=" << currencyOutID
        << "/" << issuerOutID
        << ": " << getJson ();
    return terStatus;
}
Exemple #22
0
char *OpenDDLParser::parseHeader( char *in, char *end ) {
    if( ddl_nullptr == in || in == end ) {
        return in;
    }

    Text *id( ddl_nullptr );
    in = OpenDDLParser::parseIdentifier( in, end, &id );

#ifdef DEBUG_HEADER_NAME
    dumpId( id );
#endif // DEBUG_HEADER_NAME

    in = lookForNextToken( in, end );
    if( ddl_nullptr != id ) {
        // store the node
        DDLNode *node( createDDLNode( id, this ) );
        if( ddl_nullptr != node ) {
            pushNode( node );
        } else {
            std::cerr << "nullptr returned by creating DDLNode." << std::endl;
        }
        delete id;

		Name *name_(ddl_nullptr);
		in = OpenDDLParser::parseName(in, end, &name_);
		std::unique_ptr<Name> name(name_);
        if( ddl_nullptr != name && ddl_nullptr != node ) {
            const std::string nodeName( name->m_id->m_buffer );
            node->setName( nodeName );
        }


		std::unique_ptr<Property> first;
		in = lookForNextToken(in, end);
		if (*in == Grammar::OpenPropertyToken[0]) {
			in++;
			std::unique_ptr<Property> prop, prev;
			while (*in != Grammar::ClosePropertyToken[0] && in != end) {
				Property *prop_(ddl_nullptr);
				in = OpenDDLParser::parseProperty(in, end, &prop_);
				prop.reset(prop_);
				in = lookForNextToken(in, end);

				if (*in != Grammar::CommaSeparator[0] && *in != Grammar::ClosePropertyToken[0]) {
					logInvalidTokenError(in, Grammar::ClosePropertyToken, m_logCallback);
					return ddl_nullptr;
				}

				if (ddl_nullptr != prop && *in != Grammar::CommaSeparator[0]) {
					if (ddl_nullptr == first) {
						first = std::move(prop);
					}
					if (ddl_nullptr != prev) {
						prev->m_next = prop.release();
					}
					prev = std::move(prop);
				}
			}
			++in;
		}

		// set the properties
		if (first && ddl_nullptr != node) {
			node->setProperties(first.release());
		}
    }

    return in;
}