void PerformOSCBundle(int inSize, char* inData, PyrObject *replyObj, int inPortNum) { // convert all data to arrays int64 oscTime = OSCtime(inData + 8); double seconds = OSCToElapsedTime(oscTime); VMGlobals *g = gMainVMGlobals; char *data = inData + 16; char* dataEnd = inData + inSize; while (data < dataEnd) { int32 msgSize = OSCint(data); data += sizeof(int32); if (IsBundle(data)) { PerformOSCBundle(msgSize, data, replyObj, inPortNum); } else // is a message { ++g->sp; SetObject(g->sp, g->process); ++g->sp; SetFloat(g->sp, seconds); ++g->sp; SetObject(g->sp, replyObj); ++g->sp; SetInt(g->sp, inPortNum); PyrObject *arrayObj = ConvertOSCMessage(msgSize, data); ++g->sp; SetObject(g->sp, arrayObj); runInterpreter(g, s_recvoscmsg, 5); } data += msgSize; } }
static void SendBundle(TCircularQueue<std::pair<FName, TArray<FOscDataElemStruct>>> & _pendingMessages, const osc::ReceivedBundle & bundle) { const auto begin = bundle.ElementsBegin(); const auto end = bundle.ElementsEnd(); for(auto it = begin; it != end; ++it) { if(it->IsBundle()) { SendBundle(_pendingMessages, osc::ReceivedBundle(*it)); } else { SendMessage(_pendingMessages, osc::ReceivedMessage(*it)); } } }
void localServerReplyFunc(struct ReplyAddress *inReplyAddr, char* inBuf, int inSize) { bool isBundle = IsBundle(inBuf); pthread_mutex_lock (&gLangMutex); if (compiledOK) { PyrObject *replyObj = ConvertReplyAddress(inReplyAddr); if (isBundle) { PerformOSCBundle(inSize, inBuf, replyObj); } else { PerformOSCMessage(inSize, inBuf, replyObj); } } pthread_mutex_unlock (&gLangMutex); }
void localServerReplyFunc(struct ReplyAddress *inReplyAddr, char* inBuf, int inSize) { bool isBundle = IsBundle(inBuf); gLangMutex.lock(); if (compiledOK) { PyrObject *replyObj = ConvertReplyAddress(inReplyAddr); if (isBundle) { PerformOSCBundle(inSize, inBuf, replyObj, gUDPport->RealPortNum()); } else { PerformOSCMessage(inSize, inBuf, replyObj, gUDPport->RealPortNum()); } } gLangMutex.unlock(); }
void ProcessOSCPacket(OSC_Packet* inPacket) { //post("recv '%s' %d\n", inPacket->mData, inPacket->mSize); inPacket->mIsBundle = IsBundle(inPacket->mData); pthread_mutex_lock (&gLangMutex); if (compiledOK) { PyrObject *replyObj = ConvertReplyAddress(&inPacket->mReplyAddr); if (compiledOK) { if (inPacket->mIsBundle) { PerformOSCBundle(inPacket->mSize, inPacket->mData, replyObj); } else { PerformOSCMessage(inPacket->mSize, inPacket->mData, replyObj); } } } pthread_mutex_unlock (&gLangMutex); FreeOSCPacket(inPacket); }
// takes ownership of inPacket void ProcessOSCPacket(OSC_Packet* inPacket, int inPortNum) { //post("recv '%s' %d\n", inPacket->mData, inPacket->mSize); inPacket->mIsBundle = IsBundle(inPacket->mData); gLangMutex.lock(); if (compiledOK) { PyrObject *replyObj = ConvertReplyAddress(&inPacket->mReplyAddr); if (compiledOK) { if (inPacket->mIsBundle) { PerformOSCBundle(inPacket->mSize, inPacket->mData, replyObj, inPortNum); } else { PerformOSCMessage(inPacket->mSize, inPacket->mData, replyObj, inPortNum); } } } gLangMutex.unlock(); FreeOSCPacket(inPacket); }
Promise *DeRefCopyPromise(EvalContext *ctx, const Promise *pp) { Promise *pcopy; Rval returnval; pcopy = xcalloc(1, sizeof(Promise)); if (pp->promiser) { pcopy->promiser = xstrdup(pp->promiser); } if (pp->promisee.item) { pcopy->promisee = RvalCopy(pp->promisee); if (pcopy->promisee.type == RVAL_TYPE_LIST) { Rlist *rval_list = RvalRlistValue(pcopy->promisee); RlistFlatten(ctx, &rval_list); pcopy->promisee.item = rval_list; } } if (pp->classes) { pcopy->classes = xstrdup(pp->classes); } /* FIXME: may it happen? */ if ((pp->promisee.item != NULL && pcopy->promisee.item == NULL)) { ProgrammingError("Unable to copy promise"); } pcopy->parent_promise_type = pp->parent_promise_type; pcopy->offset.line = pp->offset.line; pcopy->comment = pp->comment ? xstrdup(pp->comment) : NULL; pcopy->has_subbundles = pp->has_subbundles; pcopy->conlist = SeqNew(10, ConstraintDestroy); pcopy->org_pp = pp->org_pp; pcopy->offset = pp->offset; /* No further type checking should be necessary here, already done by CheckConstraintTypeMatch */ for (size_t i = 0; i < SeqLength(pp->conlist); i++) { Constraint *cp = SeqAt(pp->conlist, i); Body *bp = NULL; FnCall *fp = NULL; /* A body template reference could look like a scalar or fn to the parser w/w () */ const Policy *policy = PolicyFromPromise(pp); Seq *bodies = policy ? policy->bodies : NULL; char body_ns[CF_MAXVARSIZE] = ""; char body_name[CF_MAXVARSIZE] = ""; switch (cp->rval.type) { case RVAL_TYPE_SCALAR: if (cp->references_body) { SplitScopeName(RvalScalarValue(cp->rval), body_ns, body_name); if (EmptyString(body_ns)) { strncpy(body_ns, PromiseGetNamespace(pp), CF_MAXVARSIZE); } bp = IsBody(bodies, body_ns, body_name); } fp = NULL; break; case RVAL_TYPE_FNCALL: fp = RvalFnCallValue(cp->rval); SplitScopeName(fp->name, body_ns, body_name); if (EmptyString(body_ns)) { strncpy(body_ns, PromiseGetNamespace(pp), CF_MAXVARSIZE); } bp = IsBody(bodies, body_ns, body_name); break; default: bp = NULL; fp = NULL; break; } /* First case is: we have a body template to expand lval = body(args), .. */ if (bp) { EvalContextStackPushBodyFrame(ctx, pcopy, bp, fp ? fp->args : NULL); if (strcmp(bp->type, cp->lval) != 0) { Log(LOG_LEVEL_ERR, "Body type mismatch for body reference '%s' in promise at line %zu of file '%s', '%s' does not equal '%s'", body_name, pp->offset.line, PromiseGetBundle(pp)->source_path, bp->type, cp->lval); } /* Keep the referent body type as a boolean for convenience when checking later */ if (IsDefinedClass(ctx, cp->classes, PromiseGetNamespace(pcopy))) { Constraint *cp_copy = PromiseAppendConstraint(pcopy, cp->lval, (Rval) {xstrdup("true"), RVAL_TYPE_SCALAR }, false); cp_copy->offset = cp->offset; } if (bp->args != NULL) { /* There are arguments to insert */ if (fp == NULL || fp->args == NULL) { Log(LOG_LEVEL_ERR, "Argument mismatch for body reference '%s' in promise at line %zu of file '%s'", body_name, pp->offset.line, PromiseGetBundle(pp)->source_path); } for (size_t k = 0; k < SeqLength(bp->conlist); k++) { Constraint *scp = SeqAt(bp->conlist, k); returnval = ExpandPrivateRval(ctx, NULL, "body", scp->rval.item, scp->rval.type); if (IsDefinedClass(ctx, scp->classes, PromiseGetNamespace(pcopy))) { Constraint *scp_copy = PromiseAppendConstraint(pcopy, scp->lval, returnval, false); scp_copy->offset = scp->offset; } } } else { /* No arguments to deal with or body undeclared */ if (fp != NULL) { Log(LOG_LEVEL_ERR, "An apparent body \"%s()\" was undeclared or could have incorrect args, but used in a promise near line %zu of %s (possible unquoted literal value)", body_name, pp->offset.line, PromiseGetBundle(pp)->source_path); } else { for (size_t k = 0; k < SeqLength(bp->conlist); k++) { Constraint *scp = SeqAt(bp->conlist, k); Rval newrv = RvalCopy(scp->rval); if (newrv.type == RVAL_TYPE_LIST) { Rlist *new_list = RvalRlistValue(newrv); RlistFlatten(ctx, &new_list); newrv.item = new_list; } if (IsDefinedClass(ctx, scp->classes, PromiseGetNamespace(pcopy))) { Constraint *scp_copy = PromiseAppendConstraint(pcopy, scp->lval, newrv, false); scp_copy->offset = scp->offset; } } } } EvalContextStackPopFrame(ctx); } else { const Policy *policy = PolicyFromPromise(pp); if (cp->references_body && !IsBundle(policy->bundles, EmptyString(body_ns) ? NULL : body_ns, body_name)) { Log(LOG_LEVEL_ERR, "Apparent body \"%s()\" was undeclared, but used in a promise near line %zu of %s (possible unquoted literal value)", body_name, pp->offset.line, PromiseGetBundle(pp)->source_path); } Rval newrv = RvalCopy(cp->rval); if (newrv.type == RVAL_TYPE_LIST) { Rlist *new_list = RvalRlistValue(newrv); RlistFlatten(ctx, &new_list); newrv.item = new_list; } if (IsDefinedClass(ctx, cp->classes, PromiseGetNamespace(pcopy))) { Constraint *cp_copy = PromiseAppendConstraint(pcopy, cp->lval, newrv, false); cp_copy->offset = cp->offset; } } } return pcopy; }
static void VerifyPromises(enum cfagenttype agent) { struct Bundle *bp; struct SubType *sp; struct Promise *pp; struct Body *bdp; struct Rlist *rp; struct FnCall *fp; char *scope; if (REQUIRE_COMMENTS == CF_UNDEFINED) { for (bdp = BODIES; bdp != NULL; bdp = bdp->next) /* get schedule */ { if ((strcmp(bdp->name,"control") == 0) && (strcmp(bdp->type,"common") == 0)) { REQUIRE_COMMENTS = GetRawBooleanConstraint("require_comments",bdp->conlist); break; } } } for (rp = BODYPARTS; rp != NULL; rp=rp->next) { switch (rp->type) { case CF_SCALAR: if (!IsBody(BODIES,(char *)rp->item)) { CfOut(cf_error,"","Undeclared promise body \"%s()\" was referenced in a promise\n",(char *)rp->item); ERRORCOUNT++; } break; case CF_FNCALL: fp = (struct FnCall *)rp->item; if (!IsBody(BODIES,fp->name)) { CfOut(cf_error,"","Undeclared promise body \"%s()\" was referenced in a promise\n",fp->name); ERRORCOUNT++; } break; } } /* Check for undefined subbundles */ for (rp = SUBBUNDLES; rp != NULL; rp=rp->next) { switch (rp->type) { case CF_SCALAR: if (!IGNORE_MISSING_BUNDLES && !IsCf3VarString(rp->item) && !IsBundle(BUNDLES,(char *)rp->item)) { CfOut(cf_error,"","Undeclared promise bundle \"%s()\" was referenced in a promise\n",(char *)rp->item); ERRORCOUNT++; } break; case CF_FNCALL: fp = (struct FnCall *)rp->item; if (!IGNORE_MISSING_BUNDLES && !IsCf3VarString(fp->name) && !IsBundle(BUNDLES,fp->name)) { CfOut(cf_error,"","Undeclared promise bundle \"%s()\" was referenced in a promise\n",fp->name); ERRORCOUNT++; } break; } } /* Now look once through ALL the bundles themselves */ for (bp = BUNDLES; bp != NULL; bp = bp->next) /* get schedule */ { scope = bp->name; THIS_BUNDLE = bp->name; for (sp = bp->subtypes; sp != NULL; sp = sp->next) /* get schedule */ { if (strcmp(sp->name,"classes") == 0) { /* these should not be evaluated here */ if (agent != cf_common) { continue; } } for (pp = sp->promiselist; pp != NULL; pp=pp->next) { ExpandPromise(agent,scope,pp,NULL); } } } HashVariables(NULL); HashControls(); /* Now look once through the sequences bundles themselves */ if (VerifyBundleSequence(agent) == false) { FatalError("Errors in promise bundles"); } }
Promise *DeRefCopyPromise(EvalContext *ctx, const Promise *pp) { Promise *pcopy; Rval returnval; if (pp->promisee.item) { CfDebug("CopyPromise(%s->", pp->promiser); if (DEBUG) { RvalShow(stdout, pp->promisee); } CfDebug("\n"); } else { CfDebug("CopyPromise(%s->)\n", pp->promiser); } pcopy = xcalloc(1, sizeof(Promise)); if (pp->promiser) { pcopy->promiser = xstrdup(pp->promiser); } if (pp->promisee.item) { pcopy->promisee = RvalCopy(pp->promisee); if (pcopy->promisee.type == RVAL_TYPE_LIST) { Rlist *rval_list = RvalRlistValue(pcopy->promisee); RlistFlatten(ctx, &rval_list); pcopy->promisee.item = rval_list; } } if (pp->classes) { pcopy->classes = xstrdup(pp->classes); } /* FIXME: may it happen? */ if ((pp->promisee.item != NULL && pcopy->promisee.item == NULL)) { ProgrammingError("Unable to copy promise"); } pcopy->parent_promise_type = pp->parent_promise_type; pcopy->offset.line = pp->offset.line; pcopy->comment = pp->comment ? xstrdup(pp->comment) : NULL; pcopy->has_subbundles = pp->has_subbundles; pcopy->conlist = SeqNew(10, ConstraintDestroy); pcopy->org_pp = pp->org_pp; pcopy->offset = pp->offset; CfDebug("Copying promise constraints\n\n"); /* No further type checking should be necessary here, already done by CheckConstraintTypeMatch */ for (size_t i = 0; i < SeqLength(pp->conlist); i++) { Constraint *cp = SeqAt(pp->conlist, i); Body *bp = NULL; FnCall *fp = NULL; char *bodyname = NULL; /* A body template reference could look like a scalar or fn to the parser w/w () */ Policy *policy = PolicyFromPromise(pp); Seq *bodies = policy ? policy->bodies : NULL; switch (cp->rval.type) { case RVAL_TYPE_SCALAR: bodyname = (char *) cp->rval.item; if (cp->references_body) { bp = IsBody(bodies, PromiseGetNamespace(pp), bodyname); } fp = NULL; break; case RVAL_TYPE_FNCALL: fp = (FnCall *) cp->rval.item; bodyname = fp->name; bp = IsBody(bodies, PromiseGetNamespace(pp), bodyname); break; default: bp = NULL; fp = NULL; bodyname = NULL; break; } /* First case is: we have a body template to expand lval = body(args), .. */ if (bp) { EvalContextStackPushBodyFrame(ctx, bp); if (strcmp(bp->type, cp->lval) != 0) { Log(LOG_LEVEL_ERR, "Body type mismatch for body reference \"%s\" in promise at line %zu of %s (%s != %s)\n", bodyname, pp->offset.line, PromiseGetBundle(pp)->source_path, bp->type, cp->lval); } /* Keep the referent body type as a boolean for convenience when checking later */ { Constraint *cp_copy = PromiseAppendConstraint(pcopy, cp->lval, (Rval) {xstrdup("true"), RVAL_TYPE_SCALAR }, cp->classes, false); cp_copy->offset = cp->offset; } CfDebug("Handling body-lval \"%s\"\n", cp->lval); if (bp->args != NULL) { /* There are arguments to insert */ if (fp == NULL || fp->args == NULL) { Log(LOG_LEVEL_ERR, "Argument mismatch for body reference \"%s\" in promise at line %zu of %s", bodyname, pp->offset.line, PromiseGetBundle(pp)->source_path); } if (fp && bp && fp->args && bp->args && !ScopeMapBodyArgs(ctx, "body", fp->args, bp->args)) { Log(LOG_LEVEL_ERR, "Number of arguments does not match for body reference \"%s\" in promise at line %zu of %s\n", bodyname, pp->offset.line, PromiseGetBundle(pp)->source_path); } for (size_t k = 0; k < SeqLength(bp->conlist); k++) { Constraint *scp = SeqAt(bp->conlist, k); CfDebug("Doing arg-mapped sublval = %s (promises.c)\n", scp->lval); returnval = ExpandPrivateRval(ctx, "body", scp->rval); { Constraint *scp_copy = PromiseAppendConstraint(pcopy, scp->lval, returnval, scp->classes, false); scp_copy->offset = scp->offset; } } ScopeClear("body"); } else { /* No arguments to deal with or body undeclared */ if (fp != NULL) { Log(LOG_LEVEL_ERR, "An apparent body \"%s()\" was undeclared or could have incorrect args, but used in a promise near line %zu of %s (possible unquoted literal value)", bodyname, pp->offset.line, PromiseGetBundle(pp)->source_path); } else { for (size_t k = 0; k < SeqLength(bp->conlist); k++) { Constraint *scp = SeqAt(bp->conlist, k); CfDebug("Doing sublval = %s (promises.c)\n", scp->lval); Rval newrv = RvalCopy(scp->rval); if (newrv.type == RVAL_TYPE_LIST) { Rlist *new_list = RvalRlistValue(newrv); RlistFlatten(ctx, &new_list); newrv.item = new_list; } { Constraint *scp_copy = PromiseAppendConstraint(pcopy, scp->lval, newrv, scp->classes, false); scp_copy->offset = scp->offset; } } } } EvalContextStackPopFrame(ctx); } else { Policy *policy = PolicyFromPromise(pp); if (cp->references_body && !IsBundle(policy->bundles, bodyname)) { Log(LOG_LEVEL_ERR, "Apparent body \"%s()\" was undeclared, but used in a promise near line %zu of %s (possible unquoted literal value)", bodyname, pp->offset.line, PromiseGetBundle(pp)->source_path); } Rval newrv = RvalCopy(cp->rval); if (newrv.type == RVAL_TYPE_LIST) { Rlist *new_list = RvalRlistValue(newrv); RlistFlatten(ctx, &new_list); newrv.item = new_list; } { Constraint *cp_copy = PromiseAppendConstraint(pcopy, cp->lval, newrv, cp->classes, false); cp_copy->offset = cp->offset; } } } return pcopy; }