1 /******************************************************************
3 * Copyright 2015 Samsung Electronics All Rights Reserved.
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
19 ******************************************************************/
22 * @file simulator_utils.h
24 * @brief This file provides utility methods used by both client and servers.
27 #ifndef SIMULATOR_UTILS_H_
28 #define SIMULATOR_UTILS_H_
30 #include "simulator_exceptions.h"
32 #include "OCException.h"
37 * Utilities for Invokation of OC platfrom level APIs.
39 template <typename FnT, typename... ArgsT>
40 typename std::enable_if<std::is_same<OCStackResult, decltype(std::declval<FnT>()(std::declval<ArgsT>()...))>::value>::type
41 invokeocplatform(FnT fn, ArgsT &&...args)
45 OCStackResult ocResult = fn(std::forward<ArgsT>(args)...);
46 if (OC_STACK_OK != ocResult)
48 // Throw SimulatorException converting error codes
49 throw SimulatorException(static_cast<SimulatorResult>(ocResult), OC::OCException::reason(ocResult));
52 catch (OC::OCException &e)
54 // Throw SimulatorException converting error codes
55 throw SimulatorException(static_cast<SimulatorResult>(e.code()), e.reason());
61 class OCRepresentation;
64 std::string getPayloadString(const OC::OCRepresentation &);
65 std::string getRequestString(const std::map<std::string, std::string> &queryParams,
66 const OC::OCRepresentation &rep);
67 std::string getRequestString(const std::map<std::string, std::string> &queryParams);