예제 #1
0
Variant NEVER_INLINE c_SplObjectStorage::ifa_detach(MethodCallPackage &mcp, int count, INVOKE_FEW_ARGS_IMPL_ARGS) {
  if (UNLIKELY(mcp.obj == 0)) {
    return ObjectData::ifa_dummy(mcp, count, INVOKE_FEW_ARGS_PASS_ARGS, ifa_detach, coo_SplObjectStorage);
  }
  c_SplObjectStorage *self ATTRIBUTE_UNUSED (static_cast<c_SplObjectStorage*>(mcp.obj));
  if (UNLIKELY(count != 1)) return throw_wrong_arguments("SplObjectStorage::detach", count, 1, 1, 1);
  CVarRef arg0(a0);
  return (self->t_detach(arg0), null);
}
예제 #2
0
Variant NEVER_INLINE c_DirectoryIterator::ifa_seek(MethodCallPackage &mcp, int count, INVOKE_FEW_ARGS_IMPL_ARGS) {
  if (UNLIKELY(mcp.obj == 0)) {
    return ObjectData::ifa_dummy(mcp, count, INVOKE_FEW_ARGS_PASS_ARGS, ifa_seek, coo_DirectoryIterator);
  }
  c_DirectoryIterator *self ATTRIBUTE_UNUSED (static_cast<c_DirectoryIterator*>(mcp.obj));
  if (UNLIKELY(count != 1)) return throw_wrong_arguments("DirectoryIterator::seek", count, 1, 1, 1);
  CVarRef arg0(a0);
  return (self->t_seek(arg0), null);
}
예제 #3
0
Variant c_Directory::ifa___construct(MethodCallPackage &mcp, int count, INVOKE_FEW_ARGS_IMPL_ARGS) {
  if (UNLIKELY(mcp.obj == 0)) {
    return ObjectData::ifa_dummy(mcp, count, INVOKE_FEW_ARGS_PASS_ARGS, ifa___construct, coo_Directory);
  }
  c_Directory *self ATTRIBUTE_UNUSED (static_cast<c_Directory*>(mcp.obj));
  if (UNLIKELY(count != 1)) return throw_wrong_arguments("Directory::__construct", count, 1, 1, 2);
  CVarRef arg0(a0);
  return (self->t___construct(arg0), null);
}
예제 #4
0
/* SRC: ../../util/helper.php line 3 */
void f_print_arr(CVarRef v_the_arr) {
    FUNCTION_INJECTION(print_arr);
    INTERCEPT_INJECTION("print_arr", (Array(ArrayInit(1, true).set(0, v_the_arr).create())), r);
    String v_to_print;
    Variant v_element;

    v_to_print = NAMSTR(s_ss00000000, "");
    {
        LOOP_COUNTER(1);
        for (ArrayIterPtr iter3 = v_the_arr.begin(null_string, true); !iter3->end(); iter3->next()) {
            LOOP_COUNTER_CHECK(1);
            iter3->second(v_element);
            {
                v_to_print = concat3(v_to_print, toString(v_element), NAMSTR(s_ss00000000_1, " "));
            }
        }
    }
    v_to_print = concat(v_to_print, NAMSTR(s_ss66d2232c, "\n"));
    print(v_to_print);
} /* function */
Variant i_print_arr(void *extra, CArrRef params) {
    int count __attribute__((__unused__)) = params.size();
    if (count < 1) throw_missing_arguments("print_arr", count+1);
    {
        ArrayData *ad(params.get());
        ssize_t pos = ad ? ad->iter_begin() : ArrayData::invalid_index;
        CVarRef arg0(count <= 0 ? null_variant : (ad->getValue(pos)));
        return (f_print_arr(arg0), null);
    }
}
예제 #5
0
void Alcatraz::rmdir_entry()
{
    CString arg0(getArgRep(0)) ;
    pid_t pid = mp->pid() ;
    ArchDep *arch = mp->getArch() ;

    char normpath[PATH_MAX], buf[PATH_MAX] ;

    normalizePath(arg0.get().c_str(), normpath) ;
    int maptype = translatePath(normpath, buf, false, tempname);
    switch(maptype) {
    case PATH_NOTALLOWED:
	arch->abortCall(pid, -1, ENOENT);
	break ;
    case PATH_DELETED:{
	arch->abortCall(pid, -1, ENOENT);
	break ;
    }		   
    case PATH_CREATED: 
    case PATH_MODIFIED:{
	int retval = rmdir(buf) ;
	if (0 == retval) {
	    mt.delMapping(tempname) ;
	    arch->abortCall(pid, 0, 0) ;
#ifdef INSTALL_SHIELD
	    pid_t ppid = mp->ppid() ;
	    mod_log("D", normpath, "N/A", "DE", pid, ppid) ;
#endif
	} else {
	    arch->abortCall(pid, -1, errno) ;
	}
	break ;
    }
    case PATH_NEW:{
	int retval = rmdir_failure(buf) ;
	if (retval != 0) {
	    arch->abortCall(pid, -1, retval) ;
	} else {
	    mt.newDelete(TYPE_DIRECTORY, buf) ;
	    arch->abortCall(pid, 0, 0) ;
#ifdef INSTALL_SHIELD
	    pid_t ppid = mp->ppid() ;
	    mod_log("D", buf, "N/A", "DE", pid, ppid) ;
#endif
	}
	break ;
    }
    default:
	break; 
    }

}
예제 #6
0
Variant c_Directory::i___construct(MethodCallPackage &mcp, CArrRef params) {
  if (UNLIKELY(mcp.obj == 0)) {
    return ObjectData::i_dummy(mcp, params, i___construct, coo_Directory);
  }
  c_Directory *self ATTRIBUTE_UNUSED (static_cast<c_Directory*>(mcp.obj));
  int count ATTRIBUTE_UNUSED = params.size();
  if (UNLIKELY(count != 1)) return throw_wrong_arguments("Directory::__construct", count, 1, 1, 2);
  {
    ArrayData *ad(params.get());
    ssize_t pos = ad ? ad->iter_begin() : ArrayData::invalid_index;
    CVarRef arg0((ad->getValue(pos)));
    return (self->t___construct(arg0), null);
  }
}
예제 #7
0
Variant c_Exception::ifa___construct(MethodCallPackage &mcp, int count, INVOKE_FEW_ARGS_IMPL_ARGS) {
  if (UNLIKELY(mcp.obj == 0)) {
    return ObjectData::ifa_dummy(mcp, count, INVOKE_FEW_ARGS_PASS_ARGS, ifa___construct, coo_Exception);
  }
  c_Exception *self ATTRIBUTE_UNUSED (static_cast<c_Exception*>(mcp.obj));
  if (UNLIKELY(count > 3)) return throw_toomany_arguments("Exception::__construct", 3, 2);
  if (count <= 0) return (self->t___construct(), null);
  CVarRef arg0(a0);
  if (count <= 1) return (self->t___construct(arg0), null);
  CVarRef arg1(a1);
  if (count <= 2) return (self->t___construct(arg0, arg1), null);
  CVarRef arg2(a2);
  return (self->t___construct(arg0, arg1, arg2), null);
}
void qtregexp(sqlite3_context* ctx, int argc, sqlite3_value** argv)
{
    Q_UNUSED(argc)
    QRegExp regex;
    QString arg0((const char*)sqlite3_value_text(argv[0]));
    QString arg1((const char*)sqlite3_value_text(argv[1]));

    regex.setPattern(arg0);
    //regex.setCaseSensitivity(Qt::CaseInsensitive);

    if(arg1.contains(regex))
        sqlite3_result_int(ctx, 1);
    else
        sqlite3_result_int(ctx, 0);
}
예제 #9
0
void Alcatraz::mknod_entry()
{
    CString arg0(getArgRep(0)) ;
    pid_t pid = mp->pid() ;
    ArchDep *arch = mp->getArch() ;

    char normpath[PATH_MAX], buf[PATH_MAX] ;
	    
    normalizePath(arg0.get().c_str(), normpath) ;
    int maptype = translatePath(normpath, buf, false, tempname);
    switch (maptype) {
    case PATH_NOTALLOWED:
	arch->abortCall(pid, -1, ENOENT);
	break; 
    case PATH_DELETED:{
	mt.delMapping(tempname) ;
	char tempfile[PATH_MAX] ;
	mt.newEntry(TYPE_FILE, PATH_MODIFIED, tempname, tempfile) ;
#ifdef INSTALL_SHIELD
	pid_t ppid = mp->ppid() ;
	mod_log("F", normpath, tempfile, "CR", pid, ppid) ;
#endif
	arg0.set(tempfile) ;
	break ;
    }		    
    case PATH_CREATED:
    case PATH_MODIFIED:
	arg0.set(buf) ;
	break ;
    case PATH_NEW :{
	int retval = mknod_failure(buf) ;
	if (retval != 0) {
	    arch->abortCall(pid, -1, retval) ;
	} else {
	    char tempfile[PATH_MAX] ;
	    mt.newEntry(TYPE_FILE, PATH_CREATED, buf, tempfile) ;
	    arg0.set(tempfile) ;
#ifdef INSTALL_SHIELD
	    pid_t ppid = mp->ppid() ;
	    mod_log("F", normpath, tempfile, "CR", pid, ppid) ;
#endif
	}
    }
    }
}
예제 #10
0
void Alcatraz::truncate_entry()
{
    CString arg0(getArgRep(0)) ;
    pid_t pid = mp->pid() ;
    ArchDep *arch = mp->getArch() ;

    char normpath[PATH_MAX], buf[PATH_MAX] ;
    /* first get the real path of the file */

    normalizePath(arg0.get().c_str(), normpath) ;
    int maptype = translatePath(normpath, buf, true);
    switch (maptype) {
    case PATH_NOTALLOWED:
	arch->abortCall(pid, -1, ENOENT) ;
	break ;
    case PATH_DELETED:
	arch->abortCall(pid, -1, ENOENT) ;
	break ;
    case PATH_CREATED:
    case PATH_MODIFIED:{
#ifdef INSTALL_SHIELD
	pid_t ppid = mp->ppid() ;
	mod_log("F", normpath, buf, "MD", pid, ppid) ;
#endif
	arg0.set(buf) ;
	break ;
    }
    case PATH_NEW: {
	int retval = truncate_failure(buf) ;
	if (retval != 0) {
	    arch->abortCall(pid, -1, retval) ;
	}
	else {
	    char tempfile[PATH_MAX] ;
	    mt.isolate(buf, tempfile, false) ;
#ifdef INSTALL_SHIELD
	    pid_t ppid = mp->ppid() ;
	    mod_log("F", normpath, tempfile, "MD", pid, ppid) ;
#endif
	    arg0.set(tempfile) ;
	}
	break ;
    }
    }
}
예제 #11
0
Variant NEVER_INLINE c_SoapFault::ifa___construct(MethodCallPackage &mcp, int count, INVOKE_FEW_ARGS_IMPL_ARGS) {
  if (UNLIKELY(mcp.obj == 0)) {
    return ObjectData::ifa_dummy(mcp, count, INVOKE_FEW_ARGS_PASS_ARGS, ifa___construct, coo_SoapFault);
  }
  c_SoapFault *self ATTRIBUTE_UNUSED (static_cast<c_SoapFault*>(mcp.obj));
  if (UNLIKELY(count < 2)) return throw_wrong_arguments("SoapFault::__construct", count, 2, 6, 2);
  CVarRef arg0(a0);
  CVarRef arg1(a1);
  if (count <= 2) return (self->t___construct(arg0, arg1), null);
  CVarRef arg2(a2);
  if (count <= 3) return (self->t___construct(arg0, arg1, arg2), null);
  CVarRef arg3(a3);
  if (count <= 4) return (self->t___construct(arg0, arg1, arg2, arg3), null);
  CVarRef arg4(a4);
  if (count <= 5) return (self->t___construct(arg0, arg1, arg2, arg3, arg4), null);
  CVarRef arg5(a5);
  return (self->t___construct(arg0, arg1, arg2, arg3, arg4, arg5), null);
}
예제 #12
0
DEFINE_FUNCTION_DHLX_2(bool_t, bcmp)
{
	T arg0(parse<T>(sc));
	sc.get(SourceTokenDHLX::TT_OP_COMMA);
	std::string arg1(sc.get(SourceTokenDHLX::TT_IDENTIFIER).getData());
	sc.get(SourceTokenDHLX::TT_OP_COMMA);
	T arg2(parse<T>(sc));

	int cmpResult(cmp(arg0, arg2));

	if (arg1 == cmp_name_eq()) return cmpResult == 0;
	if (arg1 == cmp_name_ne()) return cmpResult != 0;
	if (arg1 == cmp_name_gt()) return cmpResult >  0;
	if (arg1 == cmp_name_ge()) return cmpResult >= 0;
	if (arg1 == cmp_name_lt()) return cmpResult <  0;
	if (arg1 == cmp_name_le()) return cmpResult <= 0;

	throw FunctionException("unknown cmp:" + arg1);
}
예제 #13
0
void
CodeExpander::functor(Class* clazz) {
    // Generate the @call method for the functor, which contains a switch on
    // the type of the arugment passed to @call method.
    Function::Ptr func = clazz->function(env_->name("@call"));
    Location loc = clazz->location();
    String::Ptr fn = func->formals()->next()->name();
    IdentifierRef::Ptr guard(new IdentifierRef(loc, env_->name(""), fn));

    Expression::Ptr stmt;
    for (Feature::Ptr feat = clazz->features(); feat; feat = feat->next()) {
        if (Function* func = dynamic_cast<Function*>(feat.pointer())) {
            String* nm = func->name();
            if (nm->string().find("@case") == 0) {
                // This is a functor case, so generate a branch for it.  Each 
                // branch looks like this: self.@case_Type(obj)
                Type::Ptr type = func->formals()->next()->type();
                Expression::Ptr arg0(new IdentifierRef(loc, env_->name(""), env_->name("__self")));
                Expression::Ptr arg1(new Cast(loc, type, new IdentifierRef(loc, env_->name(""), fn)));
                arg0->type(func->formals()->type());
                arg1->type(func->formals()->next()->type());
                
                Expression::Ptr arg;
                arg = append(arg.pointer(), arg0.pointer());
                arg = append(arg.pointer(), arg1.pointer());
                IdentifierRef::Ptr id(new IdentifierRef(loc, env_->name(""), nm));
                Call::Ptr expr(new Call(loc, id, arg));
                expr->function(func);
                Is::Ptr is(new Is(loc, guard, type));
                stmt = new Conditional(loc, is, expr, stmt);
            }
        }
    }
    Block::Ptr block = new Block(loc, env_->string(""), stmt);
    func->block(block);  
    func->is_checked(false);
    semant_->operator()(func);
}
/**
 *  @brief implementation for call java static method
 */
JS_BINDED_FUNC_IMPL(JavascriptJavaBridge, callStaticMethod)
{
    JS::CallArgs argv = JS::CallArgsFromVp(argc, vp);
    if (argc == 3) {
        JSStringWrapper arg0(argv[0]);
        JSStringWrapper arg1(argv[1]);
        JSStringWrapper arg2(argv[2]);

        CallInfo call(arg0.get(), arg1.get(), arg2.get());
        if(call.isValid()){
            bool success = call.execute();
            int errorCode = call.getErrorCode();
            if(errorCode < 0)
                JS_ReportError(cx, "js_cocos2dx_JSJavaBridge : call result code: %d", errorCode);
            argv.rval().set(convertReturnValue(cx, call.getReturnValue(), call.getReturnValueType()));
            return success;	
        }
    }
    else if(argc > 3){
        JSStringWrapper arg0(argv[0]);
        JSStringWrapper arg1(argv[1]);
        JSStringWrapper arg2(argv[2]);
        
        CallInfo call(arg0.get(), arg1.get(), arg2.get());
        if(call.isValid() && call.getArgumentsCount() == (argc - 3)){
            int count = argc - 3;
            jvalue *args = new jvalue[count];
            for (int i = 0; i < count; ++i){
                int index = i + 3;
                switch (call.argumentTypeAtIndex(i))
                {
                    case TypeInteger:
                        double interger;
                        JS::ToNumber(cx, argv.get(index), &interger);
                        args[i].i = (int)interger;
                        break;

                    case TypeFloat:
                        double floatNumber;
                        JS::ToNumber(cx, argv.get(index), &floatNumber);
                        args[i].f = (float)floatNumber;
                        break;

                    case TypeBoolean:
                        args[i].z = JS::ToBoolean(argv.get(index)) ? JNI_TRUE : JNI_FALSE;
                        break;

                    case TypeString:
                    default:
                        JSStringWrapper arg(argv.get(index));
                        args[i].l = call.getEnv()->NewStringUTF(arg.get());
                        break;
                }
            }
            bool success = call.executeWithArgs(args);
            if (args) delete []args;
            int errorCode = call.getErrorCode();
            if(errorCode < 0)
                JS_ReportError(cx, "js_cocos2dx_JSJavaBridge : call result code: %d", errorCode);
            argv.rval().set(convertReturnValue(cx, call.getReturnValue(), call.getReturnValueType()));
            return success;
        }
                
    }else{
    	JS_ReportError(cx, "js_cocos2dx_JSJavaBridge : wrong number of arguments: %d, was expecting more than 3", argc);	
    }
    
    return false;
}
예제 #15
0
Variant c_Exception::ifa_settraceoptions(MethodCallPackage &mcp, int count, INVOKE_FEW_ARGS_IMPL_ARGS) {
  if (UNLIKELY(count != 1)) return throw_wrong_arguments("Exception::setTraceOptions", count, 1, 1, 1);
  CVarRef arg0(a0);
  return (c_Exception::t_settraceoptions(arg0), null);
}
void dDAGExpressionNodeAssigment::CompileCIL(dCIL& cil)  
{
	m_expression->CompileCIL(cil); 
	if (m_leftVariable->m_dimExpressions.GetCount()) {
		
		dDAGDimensionNode* const dim = m_leftVariable->m_dimExpressions.GetFirst()->GetInfo();
		dim->CompileCIL(cil);

		dString result = dim->m_result.m_label;
		for (dList<dDAGDimensionNode*>::dListNode* node = m_leftVariable->m_dimExpressions.GetFirst()->GetNext(); node; node = node->GetNext()) {
			dAssert (0);
			dDAGDimensionNode* const dim = node->GetInfo();
			dim->CompileCIL(cil);
#if 0			
			dCILInstr& stmtMul = cil.NewStatement()->GetInfo();
			stmtMul.m_instruction = dCILInstr::m_assigment;
			stmtMul.m_operator = dCILInstr::m_mul;
			stmtMul.m_arg0.m_label = cil.NewTemp();
			stmtMul.m_arg1.m_label = result;
			stmtMul.m_arg2.m_label = dim->m_arraySize;

			DTRACE_INTRUCTION (&stmtMul);

			dCILInstr& stmtAdd = cil.NewStatement()->GetInfo();
			stmtAdd.m_instruction = dCILInstr::m_assigment;
			stmtAdd.m_operator = dCILInstr::m_add;
			stmtAdd.m_arg0.m_label = cil.NewTemp();
			stmtAdd.m_arg1.m_label = stmtMul.m_arg0.m_label;
			stmtAdd.m_arg2 = dim->m_result;

			result = stmtAdd.m_arg0.m_label;

			DTRACE_INTRUCTION (&stmtAdd);
#endif
		}

		dAssert (m_leftVariable->m_parent);
		dTree<dCILInstr::dArg, dString>::dTreeNode* const variable = dDAG::FindLocalVariable(m_leftVariable->m_name);
		dAssert (variable);

		dCILInstr::dArg arg0 (LoadLocalVariable(cil, m_expression->m_result));
		dCILInstr::dArg arg1 (LoadLocalVariable(cil, variable->GetInfo()));

		int size = arg0.GetSizeInByte();
		dCILInstrIntergerLogical* const mulOffset = new dCILInstrIntergerLogical(cil, dCILThreeArgInstr::m_mul,cil.NewTemp(), dCILInstr::dArgType(dCILInstr::m_int), result, dCILInstr::dArgType(dCILInstr::m_int), dString(size), dCILInstr::m_constInt);
		mulOffset->Trace();

		dCILInstrIntergerLogical* const address = new dCILInstrIntergerLogical(cil, dCILThreeArgInstr::m_add, cil.NewTemp(), arg1.GetType(), arg1.m_label, arg1.GetType(), mulOffset->GetArg0().m_label, mulOffset->GetArg0().GetType());
		address->Trace();

		dCILInstrStore* const store = new dCILInstrStore(cil, address->GetArg0().m_label, address->GetArg0().GetType(), arg0.m_label, arg0.GetType());
		store->Trace();
		m_result = arg0;
		
	} else {
		m_leftVariable->CompileCIL(cil); 
		dCILInstr::dArg arg1 (LoadLocalVariable(cil, m_expression->m_result));
		dCILInstrMove* const move = new dCILInstrMove (cil, m_leftVariable->m_result.m_label, m_leftVariable->m_result.GetType(), arg1.m_label, arg1.GetType());
		move->Trace();
	}
}
예제 #17
0
TInt ClientThread(TAny* aTestMode)
//
// Passed as the first client thread - signals the server to do several tests
//
	{
	// Create the message arguments to be pinned.  Should be one of each type of
	// descriptor to test that the pinning code can correctly pin each type 
	// descriptor data.  Each descriptor's data should in a separate page in 
	// thread's stack to ensure that access to each argument will cause a 
	// separate page fault.

	TUint8 argBufs[KPageSize*(6+2)]; // enough for 6 whole pages
	TUint8* argBuf0 = (TUint8*)(TUintPtr(argBufs+gPageMask)&~gPageMask);
	TUint8* argBuf1 = argBuf0+KPageSize;
	TUint8* argBuf2 = argBuf1+KPageSize;
	TUint8* argBuf3 = argBuf2+KPageSize;
	TUint8* argBuf4 = argBuf3+KPageSize;
	TUint8* argBuf5 = argBuf4+KPageSize;

	argBuf0[0]='a'; argBuf0[1]='r'; argBuf0[2]='g'; argBuf0[3]='0'; argBuf0[4]='\0';
	TPtr8 arg0(argBuf0, 5, 20);

	TBufC8<5>& arg1 = *(TBufC8<5>*)argBuf1;
	new (&arg1) TBufC8<5>((const TUint8*)"arg1");

	argBuf2[0]='a'; argBuf2[1]='r'; argBuf2[2]='g'; argBuf2[3]='1'; argBuf2[4]='\0';
	TPtrC8 arg2((const TUint8*)argBuf2);

	TBuf8<50>& arg3 = *(TBuf8<50>*)argBuf3;
	new (&arg3) TBuf8<50>((const TUint8*)"arg3");

	// For some tests use this 5th and final type of descriptor.
	HBufC8* argTmp = HBufC8::New(7);
	*argTmp = (const TUint8*)"argTmp";
	RBuf8 argTmpBuf(argTmp);

	// Need a couple of extra writable argments
	argBuf4[0]='a'; argBuf4[1]='r'; argBuf4[2]='g'; argBuf4[3]='4'; argBuf4[4]='\0';
	TPtr8 arg4(argBuf4, 5, 20);
	argBuf5[0]='a'; argBuf5[1]='r'; argBuf5[2]='g'; argBuf5[3]='5'; argBuf5[4]='\0';
	TPtr8 arg5(argBuf5, 5, 20);

	RTest test(_L("T_SVRPINNING...client"));
	RSession session;
	TInt r = session.PublicCreateSession(_L("CTestServer"),5);
	if (r != KErrNone)
		{
		gSem.Signal();
		test(0);
		}

	switch((TInt)aTestMode)
		{
		case CTestSession::ETestRdPinAll:
			test.Printf(_L("Test pinning all args\n"));
			r = session.PublicSendReceive(CTestSession::ETestRdPinAll, TIpcArgs(&arg0, &arg1, &arg2, &arg3).PinArgs());
			break;

		case CTestSession::ETestRdUnpin3:
			test.Printf(_L("Read Arg3 unpinned\n"));
			r = session.PublicSendReceive(CTestSession::ETestRdUnpin3, TIpcArgs(&arg0, argTmp, &argTmpBuf, &arg3).PinArgs(ETrue, ETrue, ETrue, EFalse));
			break;

		case CTestSession::ETestRdUnpin2:
			test.Printf(_L("Read Arg2 unpinned\n"));
			r = session.PublicSendReceive(CTestSession::ETestRdUnpin2, TIpcArgs(argTmp, &arg1, &arg2, &arg3).PinArgs(ETrue, ETrue, EFalse,  ETrue));
			break;

		case CTestSession::ETestRdUnpin1:
			test.Printf(_L("Read Arg1 unpinned\n"));
			r = session.PublicSendReceive(CTestSession::ETestRdUnpin1, TIpcArgs(&argTmpBuf, &arg1, &arg2, &arg3).PinArgs(ETrue, EFalse,  ETrue,  ETrue));
			break;

		case CTestSession::ETestRdUnpin0:
			test.Printf(_L("Read Arg0 unpinned\n"));
			r = session.PublicSendReceive(CTestSession::ETestRdUnpin0, TIpcArgs(&arg0, &arg1, &arg2, &arg3).PinArgs(EFalse, ETrue, ETrue, ETrue));
			break;

		case CTestSession::ETestPinDefault:
			test.Printf(_L("Test the default pinning policy of this server\n"));
			r = session.PublicSendReceive(CTestSession::ETestPinDefault, TIpcArgs(&arg0, &arg1, &arg2, argTmp));
			break;

		case CTestSession::ETestWrPinAll:
			test.Printf(_L("Test writing to pinned descriptors\n"));
			r = session.PublicSendReceive(CTestSession::ETestWrPinAll, TIpcArgs(&arg0, &arg3, &arg4, &arg5).PinArgs(ETrue, ETrue, ETrue, ETrue));
			// Verify the index of each argument has been written to each descriptor.
			{
			TUint maxLength = arg0.MaxLength();
			test_Equal(maxLength, arg0.Length());
			TUint j = 0;
			for (; j < maxLength; j++)
				test_Equal(0, arg0[j]);
			maxLength = arg3.MaxLength();
			test_Equal(maxLength, arg3.Length());
			for (j = 0; j < maxLength; j++)
				test_Equal(1, arg3[j]);
			maxLength = arg4.MaxLength();
			test_Equal(maxLength, arg4.Length());
			for (j = 0; j < maxLength; j++)
				test_Equal(2, arg4[j]);
			maxLength = arg5.MaxLength();
			test_Equal(maxLength, arg5.Length());
			for (j = 0; j < maxLength; j++)
				test_Equal(3, arg5[j]);
			}
			break;

		case CTestSession::ETestWrPinNone:
			test.Printf(_L("Test writing to unpinned descriptors\n"));
			r = session.PublicSendReceive(CTestSession::ETestWrPinNone, TIpcArgs(&arg0, &arg3, &arg4, &arg5).PinArgs(EFalse, EFalse, EFalse, EFalse));
			// Verify the index of each argument has been written to each descriptor.
			// Unless this is a pinnning server than the thread will be panicked before we reach there.
			{
			TUint maxLength = arg0.MaxLength();
			test_Equal(maxLength, arg0.Length());
			TUint j = 0;
			for (j = 0; j < maxLength; j++)
				test_Equal(0, arg0[j]);
			maxLength = arg3.MaxLength();
			test_Equal(maxLength, arg3.Length());
			for (j = 0; j < maxLength; j++)
				test_Equal(1, arg3[j]);
			maxLength = arg4.MaxLength();
			test_Equal(maxLength, arg4.Length());
			for (j = 0; j < maxLength; j++)
				test_Equal(2, arg4[j]);
			maxLength = arg5.MaxLength();
			test_Equal(maxLength, arg5.Length());
			for (j = 0; j < maxLength; j++)
				test_Equal(3, arg5[j]);
			}
			break;

		case CTestSession::ETestDeadServer:
			test.Printf(_L("Test pinning to dead server\n"));
			gSem.Signal();
			gSem1.Wait();
			r = session.PublicSendReceive(CTestSession::ETestRdPinAll, TIpcArgs(&arg0, &arg1, &arg2, &arg3).PinArgs());
			break;

		case CTestSession::ETestPinOOM:
			test.Printf(_L("Pinning OOM tests\n"));
			__KHEAP_MARK;
			const TUint KMaxKernelAllocations = 1024;
			TUint i;
			r = KErrNoMemory;
			for (i = 0; i < KMaxKernelAllocations && r == KErrNoMemory; i++)
				{
				__KHEAP_FAILNEXT(i);
				r = session.PublicSendReceive(CTestSession::ETestRdPinAll, TIpcArgs(&arg0, &arg1, &arg2, &arg3).PinArgs());
				__KHEAP_RESET;
				}
			test.Printf(_L("SendReceive took %d tries\n"),i);
			test_KErrNone(r);

			__KHEAP_MARKEND;
			break;
		}

	session.Close();
	test.Close();
	return r;
	}
예제 #18
0
void Alcatraz::unlink_entry()
{
    CString arg0(getArgRep(0)) ;
    pid_t pid = mp->pid() ;
    ArchDep *arch = mp->getArch() ;

    state = -1 ;

    char normpath[PATH_MAX], buf[PATH_MAX];

    if (strlen(arg0.get().c_str()) == 0)
	arch->abortCall(pid, 0, 0) ;

    normalizePath(arg0.get().c_str(), normpath) ;
    int maptype = translatePath(normpath, buf, false, tempname);
    switch (maptype) {
    case PATH_NOTALLOWED:
	arch->abortCall(pid, -1, ENOENT);
	break;
    case PATH_DELETED:{
	arch->abortCall(pid, -1, ENOENT) ;
	break ;
    }		 
    case PATH_CREATED: {
	state = 0 ;
	arg0.set(buf) ;
#ifdef INSTALL_SHIELD
	pid_t ppid = mp->ppid() ;
	mod_log("F", normpath, "N/A", "DE", pid, ppid) ;
#endif
	break ;
    }
    case PATH_MODIFIED:{
	state = 1 ;
	arg0.set(buf) ;
#ifdef INSTALL_SHIELD
	pid_t ppid = mp->ppid() ;
	mod_log("F", normpath, "N/A", "DE", pid, ppid) ;
#endif
	break ;
    }
    case PATH_NEW:{
	int retval ;
	retval = unlink_failure(buf) ;
	if (retval != 0) {
	    arch->abortCall(pid, -1, retval) ;
	} 
	else {
	    mt.newDelete(TYPE_FILE, buf) ;
	    arch->abortCall(pid, 0, 0) ;
#ifdef INSTALL_SHIELD
	    pid_t ppid = mp->ppid() ;
	    mod_log("F", buf, "N/A", "DE", pid, ppid) ;
#endif
	}
	break ;
    }
    default:
	break; 
    }
}
예제 #19
0
파일: nog.c 프로젝트: berke/aurochs
static nog_instruction_t *run(nog_closure_t *c, construction current, nog_instruction_t *ip_next, tree *result_tree) {
  nog_instruction_t *ip;

  /*printf("run pc=%ld i=%ld c->sp=%ld c->fail=%d c->memo=%d\n", ip_next - pg->np_program, c->head - c->bof, c->sp - c->cx->cx_stack, c->fail, c->memo);*/
  if(!ip_next) return 0;

  for(;;) {
    ip = ip_next;

    assert(c->pg->np_program <= ip && ip < c->pg->np_program + c->pg->np_count);
    assert(c->bof <= c->head && c->head <= c->eof);
    /*printf("pc=%ld i=%ld c->sp=%ld c->fail=%d c->memo=%d\n", ip - c->pg->np_program, c->head - c->bof, c->sp - c->cx->cx_stack, c->fail, c->memo);*/
    DEBUGIF(NOG_DEBUG,"%ld %ld %d\n", (long) (ip - c->pg->np_program), (long) (c->head - c->bof), c->fail);

    ip_next = ip + 1;

    switch(ip->ni_opcode) {
      case NOG_BRA:
        jump();
        break;

      case NOG_BEOF:
        if(c->head == c->eof) jump();
        break;

      case NOG_BNEOF:
        if(c->head < c->eof) jump();
        break;

      case NOG_BFC:
        if(!c->fail) jump();
        break;

      case NOG_BFS:
        if(c->fail) jump();
        break;

      case NOG_BMB:
        if(c->memo == R_BUSY) jump();
        break;

      case NOG_BMBF:
        if(c->memo == R_BUSY || c->memo == R_FAIL) jump();
        break;

      case NOG_BMK:
        if(c->memo != R_UNKNOWN) jump();
        break;

      case NOG_BMUK:
        if(c->memo == R_UNKNOWN) jump();
        break;

      case NOG_BMF:
        if(c->memo == R_FAIL) jump();
        break;

      case NOG_BBRC:
        if(!boolean_pop(c)) jump();
        break;
        
      case NOG_BBRS:
        if(boolean_pop(c)) jump();
        break;

      case NOG_JSR:
        (void) run(c, current, c->pg->np_program + arg0(), result_tree);
        break;

      case NOG_SBNS:
        if(c->head < c->eof && *c->head == arg1()) {
          c->head ++;
        } else {
          jump();
        }
        break;

      case NOG_BSLLT:
        if(c->eof - c->head < arg1()) jump(); /* XXX */
        break;

      case NOG_BNBOF:
        if(c->head != c->bof) jump();
        break;

      case NOG_SSEQ:
        boolean_push(c, c->head < c->eof && *c->head == arg0());
        break;

      case NOG_TSSEQ:
        boolean_push(c, c->head < c->eof &&
              c->pg->np_tables[arg0()].nt_entries[*c->head] == (letter_t) arg1());
        break;

      case NOG_SSIR:
        boolean_push(c, c->head < c->eof && arg0() <= *c->head && *c->head <= arg1());
        break;

      case NOG_BTRUE:
        boolean_push(c, true);
        break;

      case NOG_BFALSE:
        boolean_push(c, false);
        break;

      case NOG_BAND:
        {
          bool b1, b2;

          b1 = boolean_pop(c);
          b2 = boolean_pop(c);
          boolean_push(c, b1 && b2);
        }
        break;

      case NOG_BOR:
        {
          bool b1, b2;

          b1 = boolean_pop(c);
          b2 = boolean_pop(c);
          boolean_push(c, b1 || b2);
        }
        break;

      case NOG_BNOT:
        boolean_push(c, !boolean_pop(c));
        break;

      case NOG_SETF:
        c->fail = true;
        break;

      case NOG_CLRF:
        c->fail = false;
        break;

      case NOG_RIGHT:
        c->head += arg0();
        break;

      case NOG_PUSHP:
        stack_push(c, c->head - c->bof);
        break;

      case NOG_POPP:
        c->head = c->bof + stack_pop(c);
        break;

      case NOG_RESTP:
        c->head = c->bof + stack_top(c);
        break;

      case NOG_DROPP:
        (void) stack_pop(c);
        break;

      case NOG_LDMEM:
        assert(0 <= arg0() && arg0() < c->cx->cx_num_productions);
        c->memo = get_result(c->cx, c->head - c->bof, arg0());
        break;

      case NOG_LDCH:
        assert(0 <= arg0() && arg0() < c->cx->cx_num_alternatives);
        c->choice = get_choice(c->cx, c->head - c->bof, arg0());
        break;

      case NOG_POPSTMEMJ:
        {
          int position;

          position = stack_pop(c);
          assert(0 <= arg0() && arg0() < c->cx->cx_num_productions);
          set_result(c->cx, position, arg0(), c->head - c->bof);
        }
        break;

      case NOG_STMEMB:
        assert(0 <= arg0() && arg0() < c->cx->cx_num_productions);
        set_result(c->cx, c->head - c->bof, arg0(), R_BUSY);
        break;

      case NOG_STMEMF:
        assert(0 <= arg0() && arg0() < c->cx->cx_num_productions);
        set_result(c->cx, c->head - c->bof, arg0(), R_FAIL);
        break;

      case NOG_TOPSTCH:
        {
          int position;

          position = stack_top(c);
          assert(0 <= arg0() && arg0() < c->cx->cx_num_alternatives);
          set_choice(c->cx, position, arg0(), arg1());
        }
        break;

      case NOG_JMEM:
        c->head = c->bof + c->memo;
        break;

      case NOG_RTS:
        return ip_next;

      case NOG_SWCH:
        assert(c->choice < ip->ni_arg[0].na_table.nt_length);
        jump_to(ip->ni_arg[0].na_table.nt_elements[c->choice]);
        break;

      case NOG_LABEL:
        break;

      /* Construction */
      case NOG_SNODE:
        {
          int id;
          unsigned char *name;
          construction new_cons;
          tree new_tree;

          id = arg0();
          name = c->pg->np_constructors[id].ns_chars;
          new_cons = c->bd->pb_start_construction(c->bi, id, name, c->head - c->bof);
          ip_next = run(c, new_cons, ip_next, &new_tree);
          if(!ip_next) {
            return 0;
          }
          /* new_tree = c->bd->pb_finish_construction(c->bi, new_cons); */
          if(!c->bd->pb_add_children(c->bi, current, new_tree)) return 0;
        }
        break;

      case NOG_FNODE:
        if(result_tree) {
          *result_tree = c->bd->pb_finish_construction(c->bi, current, c->head - c->bof);
        }
        return ip_next;

      case NOG_ATTR:
        {
          int id;
          unsigned char *name;

          id = arg0();
          name = c->pg->np_attributes[id].ns_chars;

          if(!c->bd->pb_add_attribute(c->bi, current, id, name, c->head - c->bof, c->memo)) return 0;
        }
        break;

      case NOG_STRATTR:
        {
          int id;
          unsigned char *name;

          id = arg0();
          name = c->pg->np_attributes[id].ns_chars;

          if(!c->bd->pb_add_constant_attribute(c->bi, current, id, name, ip->ni_arg[1].na_string.ns_chars, ip->ni_arg[1].na_string.ns_length)) return 0;
        }
        break;

      case NOG_POSATTR:
        {
          int id;
          unsigned char *name;

          id = arg0();
          name = c->pg->np_attributes[id].ns_chars;

          if(!c->bd->pb_add_attribute(c->bi, current, id, name, c->head - c->bof, c->head - c->bof - 1)) return 0;
        }
        break;

      case NOG_TOKEN:
        if(!c->bd->pb_add_token(c->bi, current, c->head - c->bof, c->memo)) return 0;
        break;

    }
  }
}
예제 #20
0
void Alcatraz::open_entry()
{
    CString arg0(getArgRep(0)) ;
    Integer arg1(getArgRep(1)) ;
    pid_t pid = mp->pid() ;
    ArchDep *arch = mp->getArch() ;

    char normpath[PATH_MAX], buf[PATH_MAX] ;
    int maptype ;

    if (strncmp("/.a_to_GUI", arg0.get().c_str(), 10) == 0) {
	mt.mapping.sendtoGUI(false) ;
	arch->abortCall(pid, -1, EPERM) ;
	return ;
    }

    if (strncmp("/.alcatraz", arg0.get().c_str(), 10) == 0) {
	arg0.set(arg0.get().c_str()+10) ;
	arg1.set(0) ;
	return ;
    }

    // check open modes
    int flag = arg1.get() ;
    bool readonly = true ;
    if (flag&O_WRONLY || flag&O_RDWR || flag&O_CREAT)
	readonly = false ;
    bool trunc = false ;
    if (!readonly && flag&O_TRUNC)
	trunc = true ;

    normalizePath(arg0.get().c_str(), normpath) ;
    maptype = translatePath(normpath, buf, true, tempname);
    // Remember the association between file descriptors and path names
    // It remembers the canonized name
    char *tmp ;
    if (PATH_NEW == maptype)
	tmp = buf ;
    else tmp = normpath ;
    size_t strsize = strlen(tmp) + 1 ;
    char *duppath = new char[strsize] ;
    if (0 != duppath) {
	memcpy(duppath, tmp, strsize) ;
    }
    ProcData *pData = processData.lookUp(pid) ;
    if (0 == pData) {
	pData = new ProcData() ;
	processData.insert(pid, pData) ;
    }
    pData->storeOpenName(duppath) ;

    switch(maptype) {
    case PATH_NOTALLOWED:
	arch->abortCall(pid, -1, ENOENT);
	break; 
    case PATH_CREATED:
    case PATH_MODIFIED:
#ifdef INSTALL_SHIELD
	if (!readonly) {
	    pid_t ppid = mp->ppid() ;
	    mt.mapping.appendTime(normpath, pid, ppid) ;
	    if (access(buf, F_OK) == 0)
		mod_log("F", normpath, buf, "MD", pid, ppid) ;
	    else 
		mod_log("F", normpath, buf, "CR", pid, ppid) ;
	}
#endif
	arg0.set(buf) ;
	break ;
    case PATH_DELETED: {
	if (readonly)
	    arch->abortCall(pid, -1, ENOENT) ;
	else {
	    /* create a new file, delete previous entry and
	       generate a new temp file */
	    char tempfile[PATH_MAX] ;
	    mt.delMapping(tempname) ;
	    mt.newEntry(TYPE_FILE, PATH_MODIFIED, tempname, tempfile) ;
	    arg0.set(tempfile) ;
#ifdef INSTALL_SHIELD
	    pid_t ppid = mp->ppid() ;
	    mod_log("F", normpath, tempfile, "CR", pid, ppid) ;
#endif
	}
	break ;
    }
    case PATH_NEW: {
	if (!readonly){
	    if (access(buf, F_OK)==0) { /* File exists */
		struct stat statbuf ;
		if (stat(buf, &statbuf) == 0){/*success*/
		    if (!S_ISREG(statbuf.st_mode)) break ;
		}

		if (access(buf, W_OK) == 0) {
		    /* can write, isolate file */
		    char tempfile[PATH_MAX] ;
		    mt.isolate(buf, tempfile, trunc) ;
		    arg0.set(tempfile) ;
#ifdef INSTALL_SHIELD
	            pid_t ppid = mp->ppid() ;
		    mod_log("F", normpath, tempfile, "MD", pid, ppid) ;
#endif

		}
	    }
	    else { /* File Not Exists */
		if (parent_writable(buf)) {
		    char tempfile[PATH_MAX] ;
		    mt.newEntry(TYPE_FILE, PATH_CREATED, buf, tempfile) ;
		    //		    mt.getStatus(normpath, buf) ;
		    arg0.set(tempfile) ;
#ifdef INSTALL_SHIELD
	            pid_t ppid = mp->ppid() ;
		    mod_log("F", normpath, tempfile, "CR", pid, ppid) ;
#endif
		}
	    }
	}
	else {
	    arg0.set(buf) ;
	}
	break ;
    }
    default:
	break ;
    }
    
}
예제 #21
0
// 'Main program' equivalent: the program execution "starts" here
bool moDirectorApp::OnInit()
{

	//(*AppInitialize
	bool wxsOK = true;
	//*)
	wxInitAllImageHandlers();
//  Check next line: Gustavo 05/20/2009
//	return wxsOK;


    guint major, minor, micro, nano;
    cout << "Gstreamer initializing..." << endl;
    gst_init(NULL,NULL);
    gst_version (&major, &minor, &micro, &nano);
    cout << "Gstreamer initialized" << " version: " << major << "." << minor << "." << micro << "." << nano << endl;


    //** SET WORKING PATH CORRECTLY **/
    #if wxMAJOR_VERSION<3
    wxStandardPaths StdPaths;
    #else
	wxStandardPaths StdPaths = wxStandardPaths::Get();
	#endif

	wxFileName exename(StdPaths.GetExecutablePath());
	exename.MakeAbsolute();

    //wxMessageBox(wxString("appdir:")+wxString(exename.GetPath()));
    wxSetWorkingDirectory( wxString(exename.GetPath()) );

    //** EVERYTHING OK!!!**//




	moDirectorCore*			m_pDirectorCore = NULL;
	moDirectorFrame*		m_pDirectorFrame = NULL;

	SetAppName(wxString(_("Moldeo Director "))  + moText2Wx(moGetVersionStr()) );

// Check only one instance running

  m_checker = NULL;
/*
	const wxString name = wxString::Format(wxT("MoldeoDirector-%s"),
            wxGetUserId().c_str()); // Use mb_str()
    m_checker = new wxSingleInstanceChecker(name);
    if (m_checker->IsAnotherRunning())
        {
            wxLogError(_("Program already running, aborting."));
            return false;
        }
*/


    // Check configuration file
    /*
    wxString str;
    wxFileConfig configuration(wxT("MoldeoDirector"),wxT("Moldeo"),wxT(wxGetCwd()));

    configuration.Read(wxT("General/File1"), &str);
    wxMessageBox(wxT(str),wxT("Moldeo Director"));
    */
    // created initially)
   cout << "Image Handlers..." << endl;
#if wxUSE_SYSTEM_OPTIONS
    //wxSystemOptions::SetOption(wxT("no-maskblt"), 1);
#endif

    wxInitAllImageHandlers();
#if wxUSE_FS_INET && wxUSE_STREAMS && wxUSE_SOCKETS
    //wxFileSystem::AddHandler(new wxInternetFSHandler);
#endif

   wxImageHandler* hndPNG = wxImage::FindHandler((long)wxBITMAP_TYPE_PNG);
   if (!hndPNG)
    cout << "Warning: PNG Image handler not loaded..." << endl;

   wxImageHandler* hndJPEG = wxImage::FindHandler((long)wxBITMAP_TYPE_JPEG);
   if (!hndJPEG)
    cout << "Warning: JPEG Image handler not loaded..." << endl;

   wxImageHandler* hndTGA = wxImage::FindHandler((long)wxBITMAP_TYPE_TGA);
   if (!hndTGA)
    cout << "Warning: TGA Image handler not loaded..." << endl;

    // create the main application window

    cout << "Director Frame..." << endl;
		m_pDirectorFrame = new moDirectorFrame(wxString(_("Moldeo Director "))  + moText2Wx(moGetVersionStr()));
		if (m_pDirectorFrame) {
			m_pDirectorFrame->SetIcon( wxIcon( wxIconLocation(wxT(MOLDEODATADIR "/icons/Moldeo32.ico")) ) );
    	m_pDirectorFrame->SetForegroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_CAPTIONTEXT));
	    m_pDirectorFrame->SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE));
		} else {
			exit(1);
		}
    cout << "m_pDirectorFrame:" << (m_pDirectorFrame!=NULL) << endl;

    cout << "Director Core..." << endl;
	m_pDirectorCore = new moDirectorCore();
	cout << "m_pDirectorCore:" << (m_pDirectorCore!=NULL) << endl;

	cout << "Director Frame UI to Core..." << endl;
	m_pDirectorCore->SetUserInterface( m_pDirectorFrame );



	m_pDirectorCore->SetPaths(  moWx2Text(exename.GetPath()),
                                moWx2Text(StdPaths.GetUserDataDir()),
                                moWx2Text(wxString(wxT(MODULESDIR))),
                                moWx2Text(wxString(wxT(MOLDEODATADIR)))
                                );
	m_pDirectorCore->Init();



   //wxList   ImageHandlerList = wxImage::GetHandlers();
   cout << "appdir:" << moWx2Text( wxGetCwd() ) << endl;
   cout << "userdir:" << moWx2Text( StdPaths.GetUserDataDir() ) << endl;
   cout << "datadir:" << moWx2Text(wxString(_(MOLDEODATADIR))) << endl;
   cout << "modulesdir:" << moWx2Text(wxString(_(MODULESDIR))) << endl;

   cout << "Showing Frame..." << endl;
   m_pDirectorFrame->Show(true);
   cout << "Setting Top Window..." << endl;
   SetTopWindow(m_pDirectorFrame);

	m_pDirectorFrame->Maximize();
	m_pDirectorFrame->Init();
    cout << "Success!!! rock and roll!!" << endl;

    moText config;

    cout << "argc: " << argc << endl;

    /*minimo 2*/
   	while( argc >= 2 ) {
		--argc;

        wxString  arglast(argv[argc]);
        wxString  argprev;

        if (argc>0) argprev = argv[argc-1];

        wxString  arg0(argv[0]);

		cout <<  "Argument id" << (argc) << " : " << moWx2Text(arglast) << endl;

		if( argprev == wxString( _("-mol") ) )  {
		    config = moWx2Text( arglast );
		    cout << "Argument -mol found! : " << config << endl;
			--argc;
        } else if (  arglast == wxString(_("--help")) ) {
            cout << "Usage: " << moWx2Text(arg0) << " [-mol]" << endl;
		} else {
			cout << "Usage: " << moWx2Text(arg0) << " [-mol]" << endl;

			/*wxMessageBox(   wxString(wxT("Error opening:")) +
                            wxString(wxT(" argc:")) + // wxString(IntToStr(argc)) +
                            wxString(wxT(" argv[argc-1]:")) + argv[argc-1] +
                            wxString(wxT(" argv[0]:")) + wxString(argv[0]) +
                            wxString(wxT(" argv[1]:")) + wxString(argv[1]) +
                            wxString(wxT(" argv[2]:")) + wxString(argv[2]) );
            */


			//exit(0);
		}
    }


    if (config!=moText("")) {
        moProjectDescriptor ProjectDescriptor;
        wxFileName	FileName( moText2Wx(config) );
        wxString path = FileName.GetPath();
        #ifdef MO_WIN32
            path+= _T("\\");
        #else
            path+= _T("/");
        #endif
        wxString name = FileName.GetFullName();
        ProjectDescriptor.Set( moWx2Text(path), moWx2Text(name) );
        moDirectorStatus mStatus = m_pDirectorFrame->OpenProject( ProjectDescriptor );
    }



    // success: wxApp::OnRun() will be called which will enter the main message
    // loop and the application will run. If we returned false here, the
    // application would exit immediately.
    return true;
}
예제 #22
0
파일: main.cpp 프로젝트: Zhonghua/hermes2d
int main (int argc, char* argv[]) {

    bool adaptive = false;
    if (argc > 1) {
        std::string arg0(argv[1]);
        if (USE_ADAPTIVE.compare(arg0) == 0) {
            adaptive = true;
            info("Using adaptive solution");
        } else {
            error("Illegal argument %s", argv[1]);
            return -1;
        }
    } else {
        info("Using NON-adaptive solution");
    }

    // load the mesh file
    Mesh Cmesh, phimesh, basemesh;

    H2DReader mloader;
    mloader.load("small.mesh", &basemesh);
    basemesh.refine_towards_boundary(TOP_MARKER, REF_INIT);
    basemesh.refine_towards_boundary(BOT_MARKER, REF_INIT - 1);
    Cmesh.copy(&basemesh);
    phimesh.copy(&basemesh);

    // create the shapeset
    H1Shapeset shapeset;
    PrecalcShapeset Cpss(&shapeset);
    PrecalcShapeset phipss(&shapeset);

    // Spaces for concentration and the voltage
    H1Space C(&Cmesh, &shapeset);
    H1Space phi(MULTIMESH ? &phimesh : &Cmesh, &shapeset);

    // Initialize boundary conditions
    C.set_bc_types(C_bc_types);
    phi.set_bc_types(phi_bc_types);
    phi.set_bc_values(phi_bc_values);
    //C.set_bc_values(C_bc_values);

    // set polynomial degrees
    C.set_uniform_order(P_INIT);
    phi.set_uniform_order(P_INIT);


    // assign degrees of freedom
    int ndofs = 0;
    ndofs += C.assign_dofs(ndofs);
    ndofs += phi.assign_dofs(ndofs);
    info("ndofs: %d", ndofs);

    // The weak form for 2 equations
    WeakForm wf(2);

    Solution Cp,    // prveious time step solution, for the time integration
             Ci,   // solution convergin during the Newton's iteration
             phip,
             phii;

    // Add the bilinear and linear forms
    // generally, the equation system is described:
    // a11(u1, v1) + a12(u2, v1) + a1n(un, v1) = l1(v1)
    // a21(u1, v2) + a22(u2, v2) + a2n(un, v2) = l2(v2)
    // an1(u1, vn) + an2(u2, vn) + ann(un, vn) = ln(vn)
    wf.add_biform(0, 0, callback(J_euler_DFcDYc), UNSYM, ANY, 1, &phii);
    wf.add_biform(1, 1, callback(J_euler_DFphiDYphi), UNSYM);
    wf.add_biform(0, 1, callback(J_euler_DFcDYphi), UNSYM, ANY, 1, &Ci);
    wf.add_biform(1, 0, callback(J_euler_DFphiDYc), UNSYM);

    wf.add_liform(0, callback(Fc_euler), ANY, 3, &Cp, &Ci, &phii);
    wf.add_liform(1, callback(Fphi_euler), ANY, 2, &Ci, &phii);

    wf.add_liform_surf(1, callback(linear_form_surf_top), TOP_MARKER);

    // Nonlinear solver
    UmfpackSolver umfpack;
    NonlinSystem nls(&wf, &umfpack);
    nls.set_spaces(2, &C, &phi);
    if (MULTIMESH) {
        nls.set_pss(2, &Cpss, &phipss);
    } else {
        nls.set_pss(1, &Cpss);
    }

    info("UmfpackSolver initialized");


    //Cp.set_dirichlet_lift(&C, &Cpss);
    //phip.set_dirichlet_lift(&phi, MULTIMESH ? &phipss : &Cpss);
    Cp.set_const(&Cmesh, C_CONC);
    phip.set_const(MULTIMESH ? &phimesh : &Cmesh, 0);

    Ci.copy(&Cp);
    phii.copy(&phip);

    nls.set_ic(&Ci, &phii, &Ci, &phii);

    if (adaptive) {
        solveAdaptive(Cmesh, phimesh, basemesh, nls, C, phi, Cp, Ci, phip, phii);
    } else {
        solveNonadaptive(Cmesh, nls, Cp, Ci, phip, phii);
    }

    return 0;
}