Пример #1
0
ReturnType ProvidedServicePort::callService(std::string &name,
		std::string &invalue, std::string &outvalue) {
	Method *p = getMethod(name);

	if (p == NULL)
		return OPROS_UNSUPPORTED_METHOD;

	return p->call(invalue, outvalue);
}
Пример #2
0
WarHammer::util::SmartPointer<WarHammer::binding::java::Object> WarHammer::binding::java::Object::callObjectMethod(WarHammer::util::String methodName, WarHammer::binding::java::MethodParameterList methodParameterList)
{
	if(!this->_class->isMethodLoaded(methodName))
	{
		methodParameterList.setReturnType(new WarHammer::binding::java::lang::Object());
		this->_class->loadMethod(methodName, methodParameterList);
	}

	Method<jobject>* method = static_cast<Method<jobject>*>(this->_class->getMethod(methodName).getContent());
	jobject JNIresult = method->call(this->_JNIEnvironmentObject, methodParameterList);
	WarHammer::util::String className = this->_class->getMethod(methodName)->getJNIEnvironmentReturnType().replace("/", ".");
	className = className.substring(1, className.length() - 2);

	return new Object(JNIresult, this->_JNIEnvironment, Environment::Instance()->getClass(className).getContent());
}
Пример #3
0
//-----------------------------------------------------------------------------
void WizardLensControl::ApplyMotorMovement( const int eventID, Method& meth )
//-----------------------------------------------------------------------------
{
    try
    {
        lc_.mvDriveSelector.writeS( std::string( EventID2DriveSelectorValue( eventID ) ) );
        int64_type fullDuration = 0;
        switch( eventID )
        {
        case widSBFocus:
            fullDuration = static_cast<int64_type>( pSLFocusDuration_->GetValue() );
            break;
        case widSBZoom:
            fullDuration = static_cast<int64_type>( pSLZoomDuration_->GetValue() );
            break;
        case widSBIris:
            fullDuration = static_cast<int64_type>( pSLIrisDuration_->GetValue() );
            break;
        default:
            break;
        }
        if( fullDuration > 0 )
        {
            const int64_type maxDurationPerPulse = lc_.mvDriveDuration.getMaxValue();
            int64_type durationApplied = 0;
            while( durationApplied < fullDuration )
            {
                const int64_type duration = ( ( fullDuration - durationApplied ) >= maxDurationPerPulse ) ? maxDurationPerPulse : fullDuration - durationApplied;
                lc_.mvDriveDuration.write( duration );
                meth.call();
                durationApplied += duration;
            }
        }
    }
    catch( const ImpactAcquireException& e )
    {
        wxMessageBox( wxString::Format( wxT( "Failed to apply motor movement(Error: %s(%s))" ), ConvertedString( e.getErrorString() ).c_str(), ConvertedString( e.getErrorCodeAsString() ).c_str() ), wxT( "Error" ), wxOK | wxICON_INFORMATION, this );
    }
}
Пример #4
0
void ClassTestSuite::testClass()
{
	//Class test = ClassOf<Test1>();

	Class test = Class::lookup("ClassTest::Test1");

	TS_ASSERT_EQUALS(test.simpleName(), "Test1");

#ifndef NO_RTTI
	TS_ASSERT(test.describes<ClassTest::Test1>())

	Class test2 = Class::lookup(typeid(ClassTest::Test1));
	TS_ASSERT_EQUALS(test2.simpleName(), "Test1");
	TS_ASSERT_EQUALS(test, test2);
#endif

	Class::ClassList superClasses = test.superclasses();

	TS_ASSERT_EQUALS(superClasses.size(), 2);

	Class base1;
	Class base2;

	TS_ASSERT_THROWS(base1.simpleName(), std::runtime_error); // uninitialized handle

	for(const Class& c: superClasses) {
		if (c.fullyQualifiedName() == "ClassTest::TestBase1") {
			base1 = c;
		} else if (c.fullyQualifiedName() == "ClassTest::TestBase2") {
			base2 = c;
		}
	}

	TS_ASSERT_EQUALS(base1.fullyQualifiedName(), "ClassTest::TestBase1");
	TS_ASSERT_EQUALS(base1.simpleName(), "TestBase1");
	TS_ASSERT_EQUALS(base2.fullyQualifiedName(), "ClassTest::TestBase2");
	TS_ASSERT_EQUALS(base2.simpleName(), "TestBase2");

	TS_ASSERT(inheritanceRelation(test, base1));
	TS_ASSERT(inherits(test, base1));
	TS_ASSERT(inheritedBy(base1, test));

	TS_ASSERT(inheritanceRelation(test, base2));
	TS_ASSERT(inherits(test, base2));
	TS_ASSERT(inheritedBy(base2, test));

	TS_ASSERT(!inheritanceRelation(base1, base2));

	Class::ConstructorList base1Constructors = base1.constructors();
	TS_ASSERT_EQUALS(base1.constructors().size(), 1);

	Constructor base1Constructor = base1Constructors.front();

	TS_ASSERT_EQUALS(base1Constructor.numberOfArguments(), 0);
	TS_ASSERT_THROWS(base1Constructor.call(), std::runtime_error); // abstract class


	Class::ConstructorList base2Constructors = base2.constructors();
	TS_ASSERT_EQUALS(base2.constructors().size(), 1);

	Constructor base2Constructor = base2Constructors.front();

	TS_ASSERT_EQUALS(base2Constructor.numberOfArguments(), 0);

	VariantValue b2Inst = base2Constructor.call();
	TS_ASSERT(b2Inst.isValid());

	TS_ASSERT_EQUALS(base2.attributes().size(), 0);
	Class::MethodList base2Methods = base2.methods();
	TS_ASSERT_EQUALS(base2Methods.size(), 1);

	Method base2Method1 = base2Methods.front();

	TS_ASSERT_EQUALS(base2Method1.name(), "base2Method1");
	TS_ASSERT(base2Method1.isConst());
	TS_ASSERT(!base2Method1.isVolatile());
	TS_ASSERT(!base2Method1.isStatic());
	TS_ASSERT_EQUALS(base2Method1.numberOfArguments(), 0);
	TS_ASSERT_EQUALS(base2Method1.call(b2Inst).value<int>(), 6);


	Class::ConstructorList testConstructors = test.constructors();
	Class::AttributeList   attributes       = test.attributes();

	TS_ASSERT_EQUALS(attributes.size(), 2);
	Attribute attr = attributes.front();

	WITH_RTTI(TS_ASSERT(attr.type() == typeid(int)));

	TS_ASSERT_EQUALS(testConstructors.size(), 3);

	Constructor defaultConstr;
	Constructor intConstr;

	TS_ASSERT_THROWS(defaultConstr.argumentSpellings(), std::runtime_error);

	for (const Constructor& c: testConstructors) {
		if (c.numberOfArguments() == 0) {
			defaultConstr = c;
		} else if (c.numberOfArguments() == 1  && c.argumentSpellings()[0] == "int"){
			intConstr = c;
		}
	}


	TS_ASSERT_EQUALS(defaultConstr.numberOfArguments(), 0);
	TS_ASSERT_EQUALS(intConstr.numberOfArguments(), 1);

	VariantValue testInst1 = defaultConstr.call();

	TS_ASSERT(testInst1.isA<Test1>());


#ifndef NO_RTTI
	Class test3 = Class::lookup(testInst1.typeId());
	TS_ASSERT_EQUALS(test3.simpleName(), "Test1");
	TS_ASSERT_EQUALS(test, test3);
#endif

    TS_ASSERT_EQUALS(attr.get(testInst1).value<const int&>(), 3);


	VariantValue testInst2 = intConstr.call(77);

	TS_ASSERT(testInst2.isA<Test1>());
    TS_ASSERT_EQUALS(attr.get(testInst2).value<const int&>(), 77);

	Class::MethodList methods = test.methods();

	TS_ASSERT_EQUALS(methods.size(), 9);

	Method base1Method1;
	Method method1;
	Method method2;
	Method staticMethod;


	for (const Method& m: methods) {
		if (m.name() == "base1Method1") {
			base1Method1 = m;
		} else if (m.name() == "base2Method1") {
			base2Method1 = m;
		} else if (m.name() == "method1") {
			method1 = m;
		} else if (m.name() == "method2") {
			method2 = m;
		} else if (m.name() == "staticMethod") {
			staticMethod = m;
		}
	}

	TS_ASSERT_EQUALS(base1Method1.name(), "base1Method1");
	TS_ASSERT(!base1Method1.isConst());
	TS_ASSERT(!base1Method1.isStatic());
	TS_ASSERT(!base1Method1.isVolatile());
	WITH_RTTI(TS_ASSERT(base1Method1.returnType() == typeid(int)));
	TS_ASSERT_EQUALS(base1Method1.numberOfArguments(), 0);
	TS_ASSERT_EQUALS(base1Method1.call(testInst2).value<int>(), 5);

	TS_ASSERT_EQUALS(base2Method1.name(), "base2Method1");
	TS_ASSERT(base2Method1.isConst());
	TS_ASSERT(!base2Method1.isStatic());
	TS_ASSERT(!base2Method1.isVolatile());
	WITH_RTTI(TS_ASSERT(base2Method1.returnType() == typeid(int)));
	TS_ASSERT_EQUALS(base2Method1.numberOfArguments(), 0);
	TS_ASSERT_EQUALS(base2Method1.call(testInst2).value<int>(), 6);

	TS_ASSERT_EQUALS(method2.name(), "method2");
	TS_ASSERT(!method2.isConst());
	TS_ASSERT(!method2.isStatic());
	TS_ASSERT(!method2.isVolatile());
	WITH_RTTI(TS_ASSERT(method2.returnType() == typeid(double)));
	TS_ASSERT_EQUALS(method2.numberOfArguments(), 1);
	WITH_RTTI(TS_ASSERT(*method2.argumentTypes()[0] == typeid(double)));
	TS_ASSERT_EQUALS(method2.call(testInst2, 2).value<double>(), 6.28);

	TS_ASSERT_EQUALS(staticMethod.name(), "staticMethod");
	TS_ASSERT(!staticMethod.isConst());
	TS_ASSERT(staticMethod.isStatic());
	TS_ASSERT(!staticMethod.isVolatile());
	WITH_RTTI(TS_ASSERT(staticMethod.returnType() == typeid(double)));
	TS_ASSERT_EQUALS(staticMethod.numberOfArguments(), 0);
	TS_ASSERT_EQUALS(staticMethod.call().value<double>(), 3.14);

    ClassTest::Test1 t(666);
    VariantValue inst3;
    inst3.construct<ClassTest::TestBase1&>(t);
    TS_ASSERT_THROWS_ANYTHING(method1.call(inst3).value<string>());

    VariantValue inst4 = test.castUp(inst3, base1);
    TS_ASSERT(inst4.isValid());
    bool success = false;
    ClassTest::Test1& derivedRef = inst4.convertTo<ClassTest::Test1&>(&success);
    TS_ASSERT(success);
    TS_ASSERT_EQUALS(derivedRef.attribute1, 666);
    TS_ASSERT_EQUALS(method1.call(inst4).value<string>(), "this is a test");

    Class test_3 = Class::lookup("ClassTest::Test3");

    ClassTest::Test3 t2(666);
    TS_ASSERT_EQUALS(t2.attribute1, 333);
    TS_ASSERT_EQUALS(t2.attribute3, 666);
    VariantValue inst5;
    inst5.construct<ClassTest::TestBase1&>(t2);
    VariantValue inst6 = test_3.castUp(inst5, base1);
    TS_ASSERT(inst6.isValid());
    success = false;
    ClassTest::Test3& derivedRef2 = inst6.convertTo<ClassTest::Test3&>(&success);
    TS_ASSERT(success);
    TS_ASSERT_EQUALS(derivedRef2.attribute1, 333);
    TS_ASSERT_EQUALS(derivedRef2.attribute3, 666);

    t2.attribute1 = 787;
    t2.attribute3 = 13;
    TS_ASSERT_EQUALS(derivedRef2.attribute1, 787);
    TS_ASSERT_EQUALS(derivedRef2.attribute3, 13);

    ClassTest::Test1 t3(666);
    VariantValue inst7;
    inst7.construct<ClassTest::TestBase1&>(t3);
    VariantValue inst8 = test_3.castUp(inst7, base1);
    TS_ASSERT(!inst8.isValid());

    Class test_2 = Class::lookup("ClassTest::Test2");
    VariantValue inst9 = test_2.castUp(inst7, base1);
    TS_ASSERT(!inst9.isValid());
}
Пример #5
0
void ClassTestSuite::testClass()
{
    //Class test = ClassOf<Test1>();

    Class test = Class::lookup("ClassTest::Test1");

    TS_ASSERT_EQUALS(test.simpleName(), "Test1");

    Class::ClassList superClasses = test.superclasses();

    TS_ASSERT_EQUALS(superClasses.size(), 2);

    Class base1;
    Class base2;

    TS_ASSERT_THROWS(base1.simpleName(), std::runtime_error); // uninitialized handle

    for(const Class& c: superClasses) {
        if (c.fullyQualifiedName() == "ClassTest::TestBase1") {
            base1 = c;
        } else if (c.fullyQualifiedName() == "ClassTest::TestBase2") {
            base2 = c;
        }
    }

    TS_ASSERT_EQUALS(base1.fullyQualifiedName(), "ClassTest::TestBase1");
    TS_ASSERT_EQUALS(base1.simpleName(), "TestBase1");
    TS_ASSERT_EQUALS(base2.fullyQualifiedName(), "ClassTest::TestBase2");
    TS_ASSERT_EQUALS(base2.simpleName(), "TestBase2");

    Class::ConstructorList base1Constructors = base1.constructors();
    TS_ASSERT_EQUALS(base1.constructors().size(), 1);

    Constructor base1Constructor = base1Constructors.front();

    TS_ASSERT_EQUALS(base1Constructor.numberOfArguments(), 0);
    TS_ASSERT_THROWS(base1Constructor.call(), std::runtime_error); // abstract class


    Class::ConstructorList base2Constructors = base2.constructors();
    TS_ASSERT_EQUALS(base2.constructors().size(), 1);

    Constructor base2Constructor = base2Constructors.front();

    TS_ASSERT_EQUALS(base2Constructor.numberOfArguments(), 0);

    VariantValue b2Inst = base2Constructor.call();
    TS_ASSERT(b2Inst.isValid());

    TS_ASSERT_EQUALS(base2.attributes().size(), 0);
    Class::MethodList base2Methods = base2.methods();
    TS_ASSERT_EQUALS(base2Methods.size(), 1);

    Method base2Method1 = base2Methods.front();

    TS_ASSERT_EQUALS(base2Method1.name(), "base2Method1");
    TS_ASSERT(base2Method1.isConst());
    TS_ASSERT(!base2Method1.isVolatile());
    TS_ASSERT(!base2Method1.isStatic());
    TS_ASSERT_EQUALS(base2Method1.numberOfArguments(), 0);
    TS_ASSERT_EQUALS(base2Method1.call(b2Inst).value<int>(), 6);


    Class::ConstructorList testConstructors = test.constructors();
    Class::AttributeList   attributes       = test.attributes();

    TS_ASSERT_EQUALS(attributes.size(), 2);
    Attribute attr = attributes.front();

    WITH_RTTI(TS_ASSERT(attr.type() == typeid(int)));

    TS_ASSERT_EQUALS(testConstructors.size(), 3);

    Constructor defaultConstr;
    Constructor intConstr;

    TS_ASSERT_THROWS(defaultConstr.argumentSpellings(), std::runtime_error);

    for (const Constructor& c: testConstructors) {
        if (c.numberOfArguments() == 0) {
            defaultConstr = c;
        } else if (c.numberOfArguments() == 1  && c.argumentSpellings()[0] == "int") {
            intConstr = c;
        }
    }


    TS_ASSERT_EQUALS(defaultConstr.numberOfArguments(), 0);
    TS_ASSERT_EQUALS(intConstr.numberOfArguments(), 1);

    VariantValue testInst1 = defaultConstr.call();

    TS_ASSERT(testInst1.isA<Test1>());

    TS_ASSERT_EQUALS(attr.get(testInst1).value<int>(), 3);


    VariantValue testInst2 = intConstr.call(77);

    TS_ASSERT(testInst2.isA<Test1>());
    TS_ASSERT_EQUALS(attr.get(testInst2).value<int>(), 77);

    Class::MethodList methods = test.methods();

    TS_ASSERT_EQUALS(methods.size(), 7);

    Method base1Method1;
    Method method1;
    Method method2;
    Method staticMethod;


    for (const Method& m: methods) {
        if (m.name() == "base1Method1") {
            base1Method1 = m;
        } else if (m.name() == "base2Method1") {
            base2Method1 = m;
        } else if (m.name() == "method1") {
            method1 = m;
        } else if (m.name() == "method2") {
            method2 = m;
        } else if (m.name() == "staticMethod") {
            staticMethod = m;
        }
    }

    TS_ASSERT_EQUALS(base1Method1.name(), "base1Method1");
    TS_ASSERT(!base1Method1.isConst());
    TS_ASSERT(!base1Method1.isStatic());
    TS_ASSERT(!base1Method1.isVolatile());
    WITH_RTTI(TS_ASSERT(base1Method1.returnType() == typeid(int)));
    TS_ASSERT_EQUALS(base1Method1.numberOfArguments(), 0);
    TS_ASSERT_EQUALS(base1Method1.call(testInst2).value<int>(), 5);

    TS_ASSERT_EQUALS(base2Method1.name(), "base2Method1");
    TS_ASSERT(base2Method1.isConst());
    TS_ASSERT(!base2Method1.isStatic());
    TS_ASSERT(!base2Method1.isVolatile());
    WITH_RTTI(TS_ASSERT(base2Method1.returnType() == typeid(int)));
    TS_ASSERT_EQUALS(base2Method1.numberOfArguments(), 0);
    TS_ASSERT_EQUALS(base2Method1.call(testInst2).value<int>(), 6);

    TS_ASSERT_EQUALS(method2.name(), "method2");
    TS_ASSERT(!method2.isConst());
    TS_ASSERT(!method2.isStatic());
    TS_ASSERT(!method2.isVolatile());
    WITH_RTTI(TS_ASSERT(method2.returnType() == typeid(double)));
    TS_ASSERT_EQUALS(method2.numberOfArguments(), 1);
    WITH_RTTI(TS_ASSERT(*method2.argumentTypes()[0] == typeid(double)));
    TS_ASSERT_EQUALS(method2.call(testInst2, 2).value<double>(), 6.28);

    TS_ASSERT_EQUALS(staticMethod.name(), "staticMethod");
    TS_ASSERT(!staticMethod.isConst());
    TS_ASSERT(staticMethod.isStatic());
    TS_ASSERT(!staticMethod.isVolatile());
    WITH_RTTI(TS_ASSERT(staticMethod.returnType() == typeid(double)));
    TS_ASSERT_EQUALS(staticMethod.numberOfArguments(), 0);
    TS_ASSERT_EQUALS(staticMethod.call().value<double>(), 3.14);
}