Exemplo n.º 1
0
local void
checkPrintfCase(int w, const char *txt)
{
	String name = strPrintf("%d-[%s]", w, txt);
	char buf[20];
	sprintf(buf, "%*s", w, txt);
	String s2 = strPrintf("%*s", w, txt);

	testStringEqual(name, buf, s2);
	strFree(name);
}
Exemplo n.º 2
0
void createDirectoryInternal(const std::string &path)
{
#ifndef _WIN32
    static struct stat st;
    if (stat(path.c_str(),&st) == 0) {
        if (S_ISDIR(st.st_mode) && st.st_mode&S_IWUSR && st.st_mode&S_IRUSR && st.st_mode&S_IXUSR)
            return;
    } else if (mkdir(path.c_str(),0777) == 0) return;
    LOG_WARNING(strPrintf("Unable to access or create directory: %s.\n",path.c_str()).c_str());
    exit(-1);
#endif
}
Exemplo n.º 3
0
local SExpr
gliConst(Foam foam)
{
	Foam    decl = gl0GetDecl(foam);
	int     ix   = foam->foamConst.index;
	SExpr   val;

	val =  gl0Id(FOAM_Const, ix, strPrintf("%s-%s", glvFileName,
						 decl->foamDecl.id));
	return val;		

}
Exemplo n.º 4
0
std::shared_ptr<Publication> ClientConductor::findPublication(std::int64_t registrationId)
{
    std::lock_guard<std::recursive_mutex> lock(m_adminLock);

    auto it = std::find_if(m_publications.begin(), m_publications.end(),
        [registrationId](const PublicationStateDefn &entry)
        {
            return (registrationId == entry.m_registrationId);
        });

    if (it == m_publications.end())
    {
        return std::shared_ptr<Publication>();
    }

    PublicationStateDefn& state = (*it);
    std::shared_ptr<Publication> pub(state.m_publication.lock());

    if (!pub)
    {
        switch (state.m_status)
        {
            case RegistrationStatus::AWAITING_MEDIA_DRIVER:
                if (m_epochClock() > (state.m_timeOfRegistration + m_driverTimeoutMs))
                {
                    throw DriverTimeoutException(
                        strPrintf("No response from driver in %d ms", m_driverTimeoutMs), SOURCEINFO);
                }
                break;

            case RegistrationStatus::REGISTERED_MEDIA_DRIVER:
                {
                    UnsafeBufferPosition publicationLimit(m_counterValuesBuffer, state.m_positionLimitCounterId);

                    pub = std::make_shared<Publication>(*this, state.m_channel, state.m_registrationId, state.m_streamId,
                        state.m_sessionId, publicationLimit, *(state.m_buffers));

                    state.m_publication = std::weak_ptr<Publication>(pub);
                }
                break;

            case RegistrationStatus::ERRORED_MEDIA_DRIVER:
                throw RegistrationException(state.m_errorCode, state.m_errorMessage, SOURCEINFO);
        }
    }

    return pub;
}
Exemplo n.º 5
0
local SExpr
gliLex(Foam foam)
{
	int     lv    = foam->foamLex.level;
	int     ix    = foam->foamLex.index;
	int     fi    = glvLexFormats->foamDEnv.argv[lv];
	Foam	ddecl = glvDFmt->foamDFmt.argv[fi];
	Foam    decl  = ddecl->foamDDecl.argv[ix];
	String  buf;
	SExpr   access;

	assert (foamTag(ddecl) == FOAM_DDecl);
	assert (foamTag(decl)  == FOAM_Decl);
	assert (strlen(decl->foamDecl.id) < 180);

	gl0UseEnv(foam);
	buf = strPrintf("Struct-%s-%d-%s-%d", glvFileName,
			fi, decl->foamDecl.id, ix);
	access = lispId(buf);
	return lisp3(GL_Lex, access, sxiFrInteger(ix), gl0VarNum("l", lv));
}
Exemplo n.º 6
0
std::shared_ptr<Subscription> ClientConductor::findSubscription(std::int64_t registrationId)
{
    std::lock_guard<std::recursive_mutex> lock(m_adminLock);

    auto it = std::find_if(m_subscriptions.begin(), m_subscriptions.end(),
        [registrationId](const SubscriptionStateDefn &entry)
        {
            return (registrationId == entry.m_registrationId);
        });

    if (it == m_subscriptions.end())
    {
        return std::shared_ptr<Subscription>();
    }

    SubscriptionStateDefn& state = *it;
    std::shared_ptr<Subscription> sub = state.m_subscription.lock();

    // now remove the cached value
    if (state.m_subscriptionCache)
    {
        state.m_subscriptionCache.reset();
    }

    if (!sub && RegistrationStatus::AWAITING_MEDIA_DRIVER == state.m_status)
    {
        if (m_epochClock() > (state.m_timeOfRegistration + m_driverTimeoutMs))
        {
            throw DriverTimeoutException(
                strPrintf("No response from driver in %d ms", m_driverTimeoutMs), SOURCEINFO);
        }
    }
    else if (!sub && RegistrationStatus::ERRORED_MEDIA_DRIVER == state.m_status)
    {
        throw RegistrationException(state.m_errorCode, state.m_errorMessage, SOURCEINFO);
    }

    return sub;
}
Exemplo n.º 7
0
/*
 * Create the symbol for an identifier, given the level, index and string
 */     
local SExpr
gl0Id(FoamTag tag, int idx, String str)
{
	String    buf;
	
	if (*str) 
		switch (tag) {
		  case FOAM_Glo:   buf = strPrintf("G-%s",        str); break;
		  case FOAM_Const: buf = strPrintf("C%d-%s", idx, str); break;
		  case FOAM_Par:   buf = strPrintf("P%d-%s", idx, str); break;
		  case FOAM_Loc:   buf = strPrintf("T%d-%s", idx, str); break;
		  default:         bugBadCase(tag); NotReached(buf = 0);
		}
	else
		switch (tag) {
		  case FOAM_Glo:   bugBadCase(tag); NotReached(buf = 0); break;
		  case FOAM_Const: buf = strPrintf("C%d", idx); break;
		  case FOAM_Par:   buf = strPrintf("P%d", idx); break;
		  case FOAM_Loc:   buf = strPrintf("T%d", idx); break;
		  default:         bugBadCase(tag); NotReached(buf = 0);
		}
	return sxiFrSymbol(symIntern(buf));
}
Exemplo n.º 8
0
local SExpr
gliExpr(Foam foam)
{
	SExpr     sx = sxNil;

	switch (foamTag(foam)) {
	  case FOAM_Prog:
		bugBadCase(FOAM_Prog);
		break;
		
	  case FOAM_NOp:
	  case FOAM_Nil:
		sx = GL_Nil;
		break;
	  case FOAM_CCall: {
		  sx = gl0ExprOf(GL_CCall, 1, foam);
		  break;
	  }
	  case FOAM_OCall: {
		  sx = gl0OpenCall(foam);
		  break;
	  }
	  case FOAM_BVal: {
		  FoamTag op = foam->foamBVal.builtinTag;
		  sx = gl0ExprOf(foamBValSExpr(op), 1, foam);
		  break;
	  }
	  case FOAM_BCall: {
		  FoamTag op = foam->foamBCall.op;
		  sx = gl0ExprOf(foamBValSExpr(op), 1, foam);
		  break;
	  }
	  case FOAM_PCall:
		sx = gliPCall(foam);
		break;
	  case FOAM_If:
		sx = gliIf(foam);
		break;
	  case FOAM_Set: 
		sx = gliSet(foam);
		break;
	  case FOAM_Def: 
		sx = gliDef(foam);
		break;
	  case FOAM_PushEnv: 
		sx = gliPushEnv(foam);
		break;
	  case FOAM_PopEnv: 
		sx = GL_Nil;
		break;
	  case FOAM_EEnv: 
		sx = gliEEnv(foam);
		break;
	  case FOAM_Seq:
		sx = gl0ExprOf(GL_Progn, int0, foam);
		break;
	  case FOAM_Par:
	  case FOAM_Loc:
	  case FOAM_Glo:
	  case FOAM_Const:
		sx = gliId(foam);
		break;
	  case FOAM_Lex:
		sx = gliLex(foam);
		break;
	  case FOAM_Return:
		sx = lisp2(GL_ReturnBlock, glvFunName,
			   gliExpr(foam->foamReturn.value));
		break;
	  case FOAM_Cast:
		sx = gliExpr(foam->foamCast.expr);
		break;
	  case FOAM_Clos:
		sx = gl0ExprOf(GL_Clos, int0, foam);
		break;
	  case FOAM_Env:
		sx = gliEnv(foam);
		break;
	  case FOAM_EInfo:
		sx = gliEInfo(foam);
		break;
	  case FOAM_PRef:
	  	sx = gliPRef(foam);
		break;
	  case FOAM_Arr:
		sx = gliArr(foam);
		break;
	  case FOAM_CEnv:
		sx = gl0ExprOf(GL_ClosEnv, int0, foam);
		break;
	  case FOAM_CProg:
		sx = gl0ExprOf(GL_ClosFun, int0, foam);
		break;
	  case FOAM_Values:
		if (foamArgc(foam) == 0)
			sx = sxNil;
		else 
			sx = gl0ExprOf(GL_Values, int0, foam);
		break;
	  case FOAM_MFmt:
		sx = gliExpr(foam->foamMFmt.value);
		break;
	  case FOAM_EElt:
		sx = gliEElt(foam);
		break;
	  case FOAM_Char: /* XXX: Should be fixed elsewhere */
		sx = lisp2(GL_The, GL_Char,
			   (foam->foamChar.CharData=='\0')
			   ? GL_NUL	
                           : sxiFrChar(foam->foamChar.CharData));
		break;
	  case FOAM_Bool:
		sx = lisp2(GL_The, GL_Bool, (foam->foamBool.BoolData ?
					    GL_T : GL_Nil));
		break;
	  case FOAM_Byte:
		sx = lisp2(GL_The, GL_Byte,
			   sxiFrInteger(foam->foamByte.ByteData));
		break;
	  case FOAM_SInt:
		sx = lisp2(GL_The, GL_SInt,
			   sxiFrInteger(foam->foamSInt.SIntData));
		break;
	  case FOAM_HInt:
		sx = lisp2(GL_The, GL_HInt,
			   sxiFrInteger(foam->foamHInt.HIntData));
		break;
	  case FOAM_BInt:
		sx = lisp2(GL_The, GL_BInt,
			   sxiFrBigInteger(foam->foamBInt.BIntData));
		break;
	  case FOAM_SFlo:
		sx = lisp2(GL_The, GL_SFlo, sxiFrSFloat(foamToSFlo(foam)));
		break;
	  case FOAM_DFlo:
		sx = lisp2(GL_The, GL_DFlo, sxiFrDFloat(foamToDFlo(foam)));
		break;
	  case FOAM_Goto:
		sx = lisp1(GL_Go,
			   lispId(strPrintf("Lab%d", foam->foamGoto.label)));
		glvHasGoto = 1;
		break;
	  case FOAM_Label:
		sx = lispId(strPrintf("Lab%d", foam->foamGoto.label));
		break;
	  case FOAM_Select:
		sx = gliSelect(foam);
		break;
	  case FOAM_ANew:
		sx = gliANew(foam);
		break;
	  case FOAM_RNew:
		sx = gliRNew(foam);
		break;
	  case FOAM_AElt:
		sx = gliAElt(foam);
		break;
	  case FOAM_RElt:
		sx = gliRElt(foam);
		break;
	  case FOAM_Free:
		sx = lisp1(GL_FoamFree, gliExpr(foam->foamFree.place));
		break;
	  case FOAM_EEnsure:
		sx = lisp1(GL_FoamEEnsure, gliExpr(foam->foamEEnsure.env));
		break;
	  default:
		printf("unhandled foamTag = %s\n",
		       foamInfo(foamTag(foam)).str);
		sx = lispId("unhandled!");
		break;
	}
	return sx;
}