Exemplo n.º 1
0
    // Resolve some addresses
    //==============================================================================================
    Status Resolver::resolve(
            const vector<Address>&  addresses,
            vector<ExpandedNodeId>& expandedNodeIds,
            vector<Status>&         statuses)
    {
        // ToDo add session and security settings!

        // declare the status object to return
        Status ret;

        // declare the number of addresses
        size_t noOfAddresses = addresses.size();

        // log a nice message
        logger_->debug("Resolving the following addresses:");
        for (size_t i=0; i<noOfAddresses; i++)
        {
            logger_->debug(" - Address %d", i);
            logger_->debug(addresses[i].toString("   ", 28));
        }

        // prepare the output parameters by resizing them
        expandedNodeIds.resize(noOfAddresses);
        statuses.resize(noOfAddresses);

        // first use the cache to resolve the addresses, and to create masks for the remaining
        // addresses
        Mask expandedNodeIdMask;
        Mask relativePathMask;
        ret = resolveCached(addresses,
                            expandedNodeIds,
                            statuses,
                            expandedNodeIdMask,
                            relativePathMask);

        // log the current status
        if (expandedNodeIdMask.setCount() == 0 && relativePathMask.setCount() == 0)
        {
            logger_->debug("All addresses were cached, so the resolution is finished");
        }
        else
        {
            if (expandedNodeIdMask.setCount() != 0)
                ret = verifyExpandedNodeIds(addresses,
                                            expandedNodeIdMask,
                                            expandedNodeIds,
                                            statuses);

            if (ret.isGood() && relativePathMask.setCount() != 0)
                ret = resolveRelativePaths(addresses,
                                           relativePathMask,
                                           expandedNodeIds,
                                           statuses);
        }

        return ret;
    }
Exemplo n.º 2
0
    // Resolve a relative path (which may span over multiple server address spaces!)
    //==============================================================================================
    Status Resolver::resolveBrowsePaths(
            vector<BrowsePath>&       browsePaths,
            Mask&                     mask,
            vector<ExpandedNodeId>&   results,
            vector<Status>&           statuses)
    {
        logger_->debug("Resolving %d browse paths", browsePaths.size());

        // declare the return status
        Status ret;

        // declare the number of browsePaths
        size_t noOfBrowsePaths = browsePaths.size();

        // resize the output arguments
        results.resize(noOfBrowsePaths);
        statuses.resize(noOfBrowsePaths);

        // check if the mask has the correct size
        if (mask.size() != noOfBrowsePaths)
        {
            ret = UnexpectedError("Mask does not have the correct size!");
        }
        else if (mask.setCount() == 0)
        {
            logger_->debug("Nothing to do, no browse paths are marked with the mask");
        }
        else
        {
            // create a request and a result
            TranslateBrowsePathsToNodeIdsRequest request;
            TranslateBrowsePathsToNodeIdsResult  result;

            for (size_t i = 0; i < noOfBrowsePaths; i++)
            {
                if (mask.isSet(i))
                    request.targets.push_back(
                            TranslateBrowsePathsToNodeIdsRequestTarget(browsePaths[i]));
            }

            ret = sessionFactory_->invokeRequest<TranslateBrowsePathsToNodeIdsService>(
                    request,
                    Mask(request.targets.size(), true),
                    result);

            if (ret.isGood())
            {
                // fill the remainingBrowsePaths and remainingMask
                for (size_t i = 0, j = 0; i < noOfBrowsePaths; i++)
                {
                    if (mask.isSet(i))
                    {
                        processBrowsePathsResolutionResultTarget(
                                result.targets[j], i, browsePaths, mask, results, statuses);

                        // increment the counter for the 'set' results
                        j++;
                    }
                }

                // check if we need to perform another (recursive!) translation
                if (mask.setCount() > 0)
                    ret = resolveBrowsePaths(browsePaths, mask, results, statuses);
            }
        }

        return ret;
    }