コード例 #1
0
void
AddressTranslator::insert(
        const std::string &_address,
        const service_id_t _service, const instance_id_t _instance,
        major_version_t _major, minor_version_t _minor) {
    if (isValidService(_service) && isValidInstance(_instance)) {
        CommonAPI::Address address(_address);
        Address someipAddress(_service, _instance, _major, _minor);
#ifdef _WIN32
        EnterCriticalSection(&critSec);
#else
        std::lock_guard<std::mutex> itsLock(mutex_);
#endif
        auto fw = forwards_.find(address);
        auto bw = backwards_.find(someipAddress);
        if (fw == forwards_.end() && bw == backwards_.end()) {
            forwards_[address] = someipAddress;
            backwards_[someipAddress] = address;
            COMMONAPI_DEBUG(
                "Added address mapping: ", address, " <--> ", someipAddress);
        } else if(bw != backwards_.end() && bw->second != _address) {
            COMMONAPI_ERROR("Trying to overwrite existing SomeIP address which is "
                    "already mapped to a CommonAPI address: ",
                    someipAddress, " <--> ", _address);
        } else if(fw != forwards_.end() && fw->second != someipAddress) {
            COMMONAPI_ERROR("Trying to overwrite existing CommonAPI address which is "
                    "already mapped to a SomeIP address: ",
                    _address, " <--> ", someipAddress);
        }
#ifdef _WIN32
    LeaveCriticalSection(&critSec);
#endif
    }
}
コード例 #2
0
bool
DBusAddressTranslator::translate(const DBusAddress &_key, CommonAPI::Address &_value) {
    bool result(true);
    std::lock_guard<std::mutex> itsLock(mutex_);

    const auto it = backwards_.find(_key);
    if (it != backwards_.end()) {
        _value = it->second;
    } else if (isDefault_) {
        if (isValid(_key.getObjectPath(), '/', true) && isValid(_key.getInterface(), '.')) {
            std::string interfaceName(_key.getInterface());
            std::string instance(_key.getObjectPath().substr(1));
            std::replace(instance.begin(), instance.end(), '/', '.');

            _value.setDomain(defaultDomain_);
            _value.setInterface(interfaceName);
            _value.setInstance(instance);

            std::string service = _key.getService();
            if(isValid(service, '.',
                       (service.length() > 0 && service[0] == ':'),
                       (service.length() > 0 && service[0] == ':'),
                       true)) {
                forwards_.insert({_value, _key});
                backwards_.insert({_key, _value});
            }
        } else {
            result = false;
        }
    } else {
        result = false;
    }

    return result;
}
コード例 #3
0
bool
AddressTranslator::translate(const Address &_key, CommonAPI::Address &_value) {
    bool result(true);
#ifdef _WIN32
    EnterCriticalSection(&critSec);
#else
    std::lock_guard<std::mutex> itsLock(mutex_);
#endif
    const auto it = backwards_.find(_key);
    if (it != backwards_.end()) {
        _value = it->second;
    } else {
        COMMONAPI_ERROR(
            "Cannot determine CommonAPI address data for "
            "SOME/IP address \"", _key, "\"");
        result = false;
    }
#ifdef _WIN32
    LeaveCriticalSection(&critSec);
#endif
    return result;
}
コード例 #4
0
void
DBusAddressTranslator::insert(
        const std::string &_address,
        const std::string &_service, const std::string &_path, const std::string &_interface, const bool _objPathStartWithDigits) {

    if (isValid(_service, '.',
            (_service.length() > 0 && _service[0] == ':'),
            (_service.length() > 0 && _service[0] == ':'),
            true)
      && isValid(_path, '/', true, _objPathStartWithDigits)
      && isValid(_interface, '.')) {
        CommonAPI::Address address(_address);
        DBusAddress dbusAddress(_service, _path, _interface);

        std::lock_guard<std::mutex> itsLock(mutex_);
        auto fw = forwards_.find(address);
        auto bw = backwards_.find(dbusAddress);
        if (fw == forwards_.end() && bw == backwards_.end()) {
            forwards_[address] = dbusAddress;
            backwards_[dbusAddress] = address;
            COMMONAPI_DEBUG(
                "Added address mapping: ", address, " <--> ", dbusAddress);
            if (!orgFreedesktopDBusPeerMapped_) {
                orgFreedesktopDBusPeerMapped_ = (_interface == "org.freedesktop.DBus.Peer");
                if (orgFreedesktopDBusPeerMapped_) {
                    COMMONAPI_DEBUG("org.freedesktop.DBus.Peer mapped");
                }
            }
        } else if(bw != backwards_.end() && bw->second != address) {
            COMMONAPI_ERROR("Trying to overwrite existing DBus address "
                    "which is already mapped to a CommonAPI address: ",
                    dbusAddress, " <--> ", _address);
        } else if(fw != forwards_.end() && fw->second != dbusAddress) {
            COMMONAPI_ERROR("Trying to overwrite existing CommonAPI address "
                    "which is already mapped to a DBus address: ",
                    _address, " <--> ", dbusAddress);
        }
    }
}
コード例 #5
0
/**
* @test Test broadcast with advanced types
*   - Subscribe to broadcast which contains advanced types
*   - Call function to cause the stub to fire broadcast event with the same content
*   - Check if the values in the callback function are as expected
*/
TEST_F(DTAdvanced, BroadcastReceive) {

    std::mutex m;
    CommonAPI::CallStatus callStatus;
    std::atomic<CommonAPI::CallStatus> subStatus;

    {
        std::lock_guard<std::mutex> itsLock(m);

        arrayTestValue.push_back("Test1");
        arrayTestValue.push_back("Test2");
        arrayTestValue.push_back("Test3");

        enumerationTestValue = v1_0::commonapi::datatypes::advanced::TestInterface::tEnumeration::VALUE2;

        structTestValue.setBooleanMember(true);
        structTestValue.setUint8Member(42);
        structTestValue.setStringMember("Hello World");

        uint8_t u = 53;
        unionTestValue = u;

        mapTestValue[1] = "Hello";
        mapTestValue[2] = "World";

        typedefTestValue = 64;

        enumArrayIn.push_back(enumerationTestValue);
    }

    v1_0::commonapi::datatypes::advanced::TestInterface::tArray arrayResultValue;
    v1_0::commonapi::datatypes::advanced::TestInterface::tEnumeration enumerationResultValue;
    v1_0::commonapi::datatypes::advanced::TestInterface::tStruct structResultValue;
    v1_0::commonapi::datatypes::advanced::TestInterface::tUnion unionResultValue;
    v1_0::commonapi::datatypes::advanced::TestInterface::tMap mapResultValue;
    v1_0::commonapi::datatypes::advanced::TestInterface::tTypedef typedefResultValue;
    std::vector<v1_0::commonapi::datatypes::advanced::TestInterface::tEnumeration> enumArrayOut;

    received_ = false;
    testProxy_->getBTestEvent().subscribe([&](
            const v1_0::commonapi::datatypes::advanced::TestInterface::tArray& arrayResultValue,
            const v1_0::commonapi::datatypes::advanced::TestInterface::tEnumeration& enumerationResultValue,
            const v1_0::commonapi::datatypes::advanced::TestInterface::tStruct& structResultValue,
            const v1_0::commonapi::datatypes::advanced::TestInterface::tUnion& unionResultValue,
            const v1_0::commonapi::datatypes::advanced::TestInterface::tMap& mapResultValue,
            const v1_0::commonapi::datatypes::advanced::TestInterface::tTypedef& typedefResultValue
            ) {
        std::lock_guard<std::mutex> itsLock(m);
        EXPECT_EQ(arrayTestValue, arrayResultValue);
        EXPECT_EQ(enumerationTestValue, enumerationResultValue);
        EXPECT_EQ(structTestValue, structResultValue);
        EXPECT_EQ(unionTestValue, unionResultValue);
        EXPECT_EQ(mapTestValue, mapResultValue);
        EXPECT_EQ(typedefTestValue, typedefResultValue);
        received_ = true;
    },
    [&](
        const CommonAPI::CallStatus &status
    ) {
        subStatus = status;
    });

    // check that subscription has succeeded
    for (int i = 0; i < 100; i++) {
        if (subStatus == CommonAPI::CallStatus::SUCCESS) break;
        std::this_thread::sleep_for(std::chrono::microseconds(tasync));
    }
    EXPECT_EQ(CommonAPI::CallStatus::SUCCESS, subStatus);

    testProxy_->fTest(
            arrayTestValue,
            enumerationTestValue,
            structTestValue,
            unionTestValue,
            mapTestValue,
            typedefTestValue,
            enumArrayIn,
            callStatus,
            arrayResultValue,
            enumerationResultValue,
            structResultValue,
            unionResultValue,
            mapResultValue,
            typedefResultValue,
            enumArrayOut
    );

    for (int i = 0; i < 100; ++i) {
        if (received_) break;
        std::this_thread::sleep_for(std::chrono::microseconds(tasync));
    }
    ASSERT_TRUE(received_);
    received_ = false;

    {
        std::lock_guard<std::mutex> itsLock(m);
        mapTestValue.clear();
        mapTestValue[4] = "Test";
        mapTestValue[5] = "123";
    }

    testProxy_->fTest(
            arrayTestValue,
            enumerationTestValue,
            structTestValue,
            unionTestValue,
            mapTestValue,
            typedefTestValue,
            enumArrayIn,
            callStatus,
            arrayResultValue,
            enumerationResultValue,
            structResultValue,
            unionResultValue,
            mapResultValue,
            typedefResultValue,
            enumArrayOut
    );

    for (int i = 0; i < 100; ++i) {
        if (received_) break;
        std::this_thread::sleep_for(std::chrono::microseconds(tasync));
    }
    ASSERT_TRUE(received_);
    received_ = false;

    {
        std::lock_guard<std::mutex> itsLock(m);
        mapTestValue.clear();
        mapTestValue[11] = "blub";
        mapTestValue[22] = "blah";
    }

    testProxy_->fTest(
            arrayTestValue,
            enumerationTestValue,
            structTestValue,
            unionTestValue,
            mapTestValue,
            typedefTestValue,
            enumArrayIn,
            callStatus,
            arrayResultValue,
            enumerationResultValue,
            structResultValue,
            unionResultValue,
            mapResultValue,
            typedefResultValue,
            enumArrayOut
    );

    for (int i = 0; i < 100; ++i) {
        if (received_) break;
        std::this_thread::sleep_for(std::chrono::microseconds(tasync));
    }
    ASSERT_TRUE(received_);
}