ocresourcehandler.h 5.03 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
//******************************************************************
//
// Copyright 2014 Intel Mobile Communications GmbH All Rights Reserved.
//
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//      http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

#ifndef OC_RESOURCEHANDLER_H
#define OC_RESOURCEHANDLER_H

#include "ocstack.h"
#include "ocstackinternal.h"
#include "ocserverrequest.h"

28 29
/**
 * Common JSON string components used by the stack to build JSON strings.
30 31
 * These details are exposed in ocstackconfig.h file in the form of documentation.
 * Remember to update the documentation there if these are changed.
32
 */
33
#define OC_JSON_PREFIX                     "{\"oic\":["
34 35 36 37
#define OC_JSON_PREFIX_LEN                 (sizeof(OC_JSON_PREFIX) - 1)
#define OC_JSON_SUFFIX                     "]}"
#define OC_JSON_SUFFIX_LEN                 (sizeof(OC_JSON_SUFFIX) - 1)
#define OC_JSON_SEPARATOR                  ','
38
#define OC_JSON_SEPARATOR_STR              ","
39
#define OC_KEY_VALUE_DELIMITER             "="
40

41 42 43
/**
 * Static values for various JSON attributes.
 */
44 45 46
#define OC_RESOURCE_OBSERVABLE   1
#define OC_RESOURCE_SECURE       1

47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
/**
 * OIC Virtual resources supported by every OIC device.
 */
typedef enum
{
    OC_UNKNOWN_URI =0,
    OC_WELL_KNOWN_URI,          ///< "/oic/res"
    OC_DEVICE_URI,              ///< "/oic/d"
    OC_PLATFORM_URI,            ///< "/oic/p"
    OC_RESOURCE_TYPES_URI,      ///< "/oic/res/types/d"
#ifdef WITH_PRESENCE
    OC_PRESENCE,                ///< "/oic/ad"
#endif
} OCVirtualResources;

62 63 64
/**
 * The type of query a request/response message is.
 */
65 66
typedef enum
{
67 68
    STACK_RES_DISCOVERY_NOFILTER = 0,
    STACK_RES_DISCOVERY_IF_FILTER,
69 70 71
    STACK_RES_DISCOVERY_RT_FILTER,
    STACK_DEVICE_DISCOVERY_DI_FILTER,
    STACK_DEVICE_DISCOVERY_DN_FILTER
72 73
} StackQueryTypes;

74 75 76
/**
 * The type of handling required to handle a request.
 */
77 78
typedef enum
{
79 80 81 82 83 84 85 86 87
    OC_RESOURCE_VIRTUAL = 0,
    OC_RESOURCE_NOT_COLLECTION_WITH_ENTITYHANDLER,
    OC_RESOURCE_NOT_COLLECTION_DEFAULT_ENTITYHANDLER,
    OC_RESOURCE_COLLECTION_WITH_ENTITYHANDLER,
    OC_RESOURCE_COLLECTION_DEFAULT_ENTITYHANDLER,
    OC_RESOURCE_DEFAULT_DEVICE_ENTITYHANDLER,
    OC_RESOURCE_NOT_SPECIFIED
} ResourceHandling;

88 89 90 91
/**
 * Default entity handler (ie. callback) to be used for resources with
 * no entity handler.
 */
92
OCEntityHandlerResult defaultResourceEHandler(OCEntityHandlerFlag flag,
93
        OCEntityHandlerRequest * request, void* callbackParam);
94

95 96 97 98
/**
 * Find and retrieve pointer to a resource associated with a specific resource
 * URI.
 */
99 100
OCResource *FindResourceByUri(const char* resourceUri);

101 102 103 104 105 106 107 108 109 110
/**
 * Returns true if the specificed resource URI aligns with a pre-existing
 * virtual resource; returns false otherwise.
 */
bool IsVirtualResource(const char* resourceUri);

/**
 * Parameter @ref handling returns by-reference the type of resource handling
 * required by the internal stack based on the specified @ref request.
 */
111
OCStackResult DetermineResourceHandling (const OCServerRequest *request,
112 113 114
                                         ResourceHandling *handling,
                                         OCResource **resource);

115 116 117 118 119 120 121 122 123
/**
 * Processes the specified @ref request based on the type of resource handling
 * @ref resHandling.
 */
OCStackResult ProcessRequest(ResourceHandling resHandling,
                             OCResource *resource,
                             OCServerRequest *request);

/**
124
 * Internal API used to save all of the platform's information for use in platform
125 126
 * discovery requests.
 */
127 128
OCStackResult SavePlatformInfo(OCPlatformInfo info);

129 130 131 132 133 134 135 136
/**
 * Internal API used to save all of the device's information for use in platform
 * discovery requests.
 * The device name is received from the appliation.
 * The deviceID, spec version and data model verson are initialized by the stack.
 */
OCStackResult SaveDeviceInfo(OCDeviceInfo info);

137 138 139 140
/**
 * Internal API used to clear the platform information.
 */
void DeletePlatformInfo();
141

142 143 144
/**
 * Internal API used to clear the device information.
 */
145 146
void DeleteDeviceInfo();

147 148 149
/**
 * Prepares a JSON string for response.
 */
150
OCStackResult BuildVirtualResourceResponse(const OCResource *resourcePtr,
151
                                           OCDiscoveryPayload* payload,
152
                                           CATransportAdapter_t adapter);
153 154 155 156 157

/**
 * A helper function that Maps an @ref OCEntityHandlerResult type to an
 * @ref OCStackResult type.
 */
158 159 160
OCStackResult EntityHandlerCodeToOCStackCode(OCEntityHandlerResult ehResult);

#endif //OC_RESOURCEHANDLER_H
161