Ejemplo n.º 1
0
void onPost(const HeaderOptions& headerOptions, const OCRepresentation& rep, const int eCode)
{
    printf("\nonPost\n");

    std::vector< OCRepresentation > children = rep.getChildren();

    cout << "\n\n\nCHILD RESOURCE OF GROUP" << endl;
    for (auto iter = children.begin(); iter != children.end(); ++iter)
    {
        std::string power;
        (*iter).getValue("power", power);

        cout << "\tURI :: " << (*iter).getUri() << endl;
        cout << "\t\tpower :: " << power << endl;
    }

    if (rep.hasAttribute("ActionSet"))
    {
        std::string plainText;

        rep.getValue("ActionSet", plainText);

        printf("\tPlain Text :: %s\n", plainText.c_str());
    }
    else
    {
        printf("Not found ActionSet\n");
    }
}
Ejemplo n.º 2
0
/*
* Class:     org_iotivity_base_OcRepresentation
* Method:    getChildrenArray
* Signature: ()[Lorg/iotivity/base/OcRepresentation;
*/
JNIEXPORT jobjectArray JNICALL Java_org_iotivity_base_OcRepresentation_getChildrenArray
(JNIEnv *env, jobject thiz)
{
    LOGD("OcRepresentation_getChildrenArray");
    OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz);
    if (!rep) return nullptr;

    return JniUtils::convertRepresentationVectorToJavaArray(env, rep->getChildren());
}
void onPut(const OCRepresentation& rep , const int eCode)
{
    if(eCode == SUCCESS_RESPONSE)
    {
        std::cout << "PUT request was successful" << std::endl;

        AttributeMap attributeMap = rep.getAttributeMap();

        for(auto it = attributeMap.begin() ; it != attributeMap.end() ; ++it)
        {
            std::cout << "\tAttribute name: " << it->first << " value: ";
            for(auto valueItr = it->second.begin() ; valueItr != it->second.end() ; ++valueItr)
            {
                std::cout << "\t" << *valueItr << " ";
            }

            std::cout << std::endl;
        }

        std::vector< OCRepresentation > children = rep.getChildren();

        for(auto oit = children.begin() ; oit != children.end() ; ++oit)
        {
            attributeMap = oit->getAttributeMap();

            for(auto it = attributeMap.begin() ; it != attributeMap.end() ; ++it)
            {
                std::cout << "\tAttribute name: " << it->first << " value: ";
                for(auto valueItr = it->second.begin() ; valueItr != it->second.end() ; ++valueItr)
                {
                    std::cout << "\t" << *valueItr << " ";
                }

                std::cout << std::endl;
            }
        }

        if(OBSERVE_TYPE_TO_USE == ObserveType::Observe)
            std::cout << std::endl << "Observe is used." << std::endl << std::endl;
        else if(OBSERVE_TYPE_TO_USE == ObserveType::ObserveAll)
            std::cout << std::endl << "ObserveAll is used." << std::endl << std::endl;

        QueryParamsMap test;

        g_curResource->observe(ObserveType::Observe , test , &onObserve);

    }
    else
    {
        std::cout << "onPut Response error: " << eCode << std::endl;
        std::exit(-1);
    }
}
Ejemplo n.º 4
0
void onGet(const HeaderOptions& opt, const OCRepresentation &rep, const int eCode)
{
    // printf("onGet\n");

    std::vector< OCRepresentation > children = rep.getChildren();

    cout << "\n\n\nCHILD RESOURCE OF GROUP" << endl;
    for (auto iter = children.begin(); iter != children.end(); ++iter)
    {
        lights.push_back((*iter).getUri());
        cout << "\tURI :: " << (*iter).getUri() << endl;
    }

    isReady = true;
    cv.notify_one();
}
// callback handler on GET request
void onGet(const HeaderOptions &headerOption , const OCRepresentation& rep , const int eCode)
{
    if(eCode == SUCCESS_RESPONSE)
    {
        std::cout << "GET request was successful" << std::endl;

        AttributeMap attributeMap = rep.getAttributeMap();

        std::cout << "Resource URI: " << rep.getUri() << std::endl;

        for(auto it = attributeMap.begin() ; it != attributeMap.end() ; ++it)
        {
            std::cout << "\tAttribute name: " << it->first << " value: ";
            for(auto valueItr = it->second.begin() ; valueItr != it->second.end() ; ++valueItr)
            {
                std::cout << "\t" << *valueItr << " ";
            }

            std::cout << std::endl;
        }

        std::vector< OCRepresentation > children = rep.getChildren();

        for(auto oit = children.begin() ; oit != children.end() ; ++oit)
        {
            std::cout << "Child Resource URI: " << oit->getUri() << std::endl;

            attributeMap = oit->getAttributeMap();

            for(auto it = attributeMap.begin() ; it != attributeMap.end() ; ++it)
            {
                std::cout << "\tAttribute name: " << it->first << " value: ";
                for(auto valueItr = it->second.begin() ; valueItr != it->second.end() ; ++valueItr)
                {
                    std::cout << "\t" << *valueItr << " ";
                }

                std::cout << std::endl;
            }
        }
    }
    else
    {
        std::cout << "onGET Response error: " << eCode << std::endl;
        std::exit(-1);
    }
}
Ejemplo n.º 6
0
void GroupManager::checkCollectionRepresentation(const OCRepresentation& rep,
        CollectionPresenceCallback callback)
{
    std::cout << "\tResource URI: " << rep.getUri() << std::endl;

    std::vector< OCRepresentation > children = rep.getChildren();
    if(children.size() == 0 )
    {
        callback("", OC_STACK_ERROR);
        return;
    }

    for (auto oit = children.begin(); oit != children.end(); ++oit)
    {
        if(oit->getUri().find("coap://") == std::string::npos)
        {
            std::cout << "The resource with a URI " << oit->getUri() << " is not a remote resource."
                << " Thus, we ignore to send a request for presence check to the resource.\n";

            continue;
        }

        std::vector< std::string > hostAddressVector = str_split(oit->getUri(), '/');
        std::string hostAddress = "";
        for (unsigned int i = 0; i < hostAddressVector.size(); ++i)
        {
            if (i < 3)
            {
                hostAddress.append(hostAddressVector.at(i));
                if (i != 2)
                {
                    hostAddress.append("/");
                }
            }
        }

        std::vector< std::string > resourceTypes = oit->getResourceTypes();
        // for (unsigned int i = 0; i < resourceTypes.size(); ++i)
        // {
        //     std::cout << "\t\t\tresourcetype :" << resourceTypes.at(i) << std::endl;
        // }

        // std::string resourceType = "core.";
        // resourceType.append(str_split(oit->getUri(), '/').at(4));
        // std::cout << "\t\tconvertRT : " << resourceType << std::endl;
        // std::cout << "\t\tresource type front : " << resourceTypes.front() << endl;
        // std::cout << "\t\thost : " << hostAddress << std::endl;
        OCPlatform::OCPresenceHandle presenceHandle;
        OCStackResult result = OC_STACK_ERROR;

        try
        {
            result = OCPlatform::subscribePresence(presenceHandle, hostAddress,
                    // resourceType,
                    resourceTypes.front(),
                    OC_ETHERNET,
                    std::function<
                            void(OCStackResult result, const unsigned int nonce,
                                    const std::string& hostAddress) >(
                            std::bind(&GroupManager::collectionPresenceHandler, this,
                                    std::placeholders::_1, std::placeholders::_2,
                                    std::placeholders::_3, hostAddress, oit->getUri())));

            result = OCPlatform::subscribePresence(presenceHandle, hostAddress,
                    // resourceType,
                    resourceTypes.front(),
                    OC_WIFI,
                    std::function<
                            void(OCStackResult result, const unsigned int nonce,
                                    const std::string& hostAddress) >(
                            std::bind(&GroupManager::collectionPresenceHandler, this,
                                    std::placeholders::_1, std::placeholders::_2,
                                    std::placeholders::_3, hostAddress, oit->getUri())));
        }catch(OCException& e)
        {
            std::cout<< "Exception in subscribePresence: "<< e.what() << std::endl;
        }

        if (result == OC_STACK_OK)
        {
            presenceCallbacks.insert(std::make_pair(oit->getUri(), callback));
        }
        else
        {
            callback("", OC_STACK_ERROR);
        }
    }
}
Ejemplo n.º 7
0
    void ThingsMaintenance::onGetChildInfoForUpdate(const HeaderOptions& headerOptions,
            const OCRepresentation& rep, const int eCode, std::string mnt)
    {
        if (eCode != OC_STACK_OK)
        {
            std::cout << "onGet Response error: " << eCode << std::endl;
            getCallback(mnt)(headerOptions, rep, eCode);
            return ;
        }

        std::cout << "GET request was successful" << std::endl;

        std::cout << "\tResource URI: " << rep.getUri() << std::endl;

        std::vector < OCRepresentation > children = rep.getChildren();
        for (auto oit = children.begin(); oit != children.end(); ++oit)
        {
            std::cout << "\t\tChild Resource URI: " << oit->getUri() << std::endl;
        }

        // Get information by using maintenance name(mnt)
        std::shared_ptr < OCResource > resource = getResource(mnt);
        std::string actionstring = mnt;
        std::string uri = getUriByMaintenanceName(mnt);
        std::string attrKey = mnt;

        if (uri == "")
            return;

        if (resource)
        {
            // In this nest, we create a new action set of which name is the dignostics name.
            // Required information consists of a host address, URI, attribute key, and
            // attribute value.
            ActionSet *newActionSet = new ActionSet();
            newActionSet->actionsetName = mnt;

            for (auto oit = children.begin(); oit != children.end(); ++oit)
            {
                Action *newAction = new Action();

                // oit->getUri() includes a host address as well as URI.
                // We should split these to each other and only use the host address to create
                // a child resource's URI. Note that the collection resource and its child
                // resource are located in same host.
                newAction->target = getHostFromURI(oit->getUri()) + uri;

                Capability *newCapability = new Capability();
                newCapability->capability = attrKey;
                newCapability->status = getUpdateVal(mnt);

                newAction->listOfCapability.push_back(newCapability);
                newActionSet->listOfAction.push_back(newAction);
            }

            // Request to create a new action set by using the above actionSet
            g_groupmanager->addActionSet(resource, newActionSet,
                    std::function<
                            void(const HeaderOptions& headerOptions,
                                    const OCRepresentation& rep, const int eCode) >(
                            std::bind(&ThingsMaintenance::onCreateActionSet, this,
                                    std::placeholders::_1, std::placeholders::_2,
                                    std::placeholders::_3, mnt)));

            delete(newActionSet);

        }
    }