Skip to content
This repository has been archived by the owner on Mar 3, 2023. It is now read-only.

Commit

Permalink
Version 1.1.0
Browse files Browse the repository at this point in the history
CHANGELOG
- NEW: MeteringSessionManager robustness to network disconnections
  • Loading branch information
xlz-jpponcelet committed Oct 8, 2018
1 parent 5df0ad0 commit 4ff7ae6
Show file tree
Hide file tree
Showing 16 changed files with 362 additions and 72 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
* Mon Oct 08 2018 Accelize v1.1.0
- NEW: MeteringSessionManager robustness to network disconnections

* Wed Sep 12 2018 Accelize v1.0.0
- NEW: MeteringSessionManager to manage DRM metering sessions
- NEW: C-wrapper API
Expand Down
20 changes: 19 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,16 @@ cmake_minimum_required (VERSION 2.8.12)

project(accelize/drmlib)

# Build Type
set(default_build_type "RelWithDebInfo")
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
message(STATUS "Setting build type to '${default_build_type}' as none was specified.")
set(CMAKE_BUILD_TYPE "${default_build_type}" CACHE STRING "Choose the type of build." FORCE)
# Set the possible values of build type for cmake-gui
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS
"Debug" "Release" "MinSizeRel" "RelWithDebInfo")
endif()

# Get version
execute_process(COMMAND git describe --tag --dirty=-d
COMMAND sed s/^v//
Expand All @@ -30,7 +40,13 @@ set(ABI_VERSION ${VERSION_MAJOR})
message(STATUS "ABI library version from Git : ${ABI_VERSION}")

add_compile_options(-std=c++11)
add_compile_options(-fvisibility=hidden)
add_compile_options(-Wall -Wextra -Wnon-virtual-dtor -pedantic)
add_compile_options("$<$<CONFIG:DEBUG>:-Og>")
add_compile_options(-fdebug-prefix-map=${CMAKE_SOURCE_DIR}=.)
string(LENGTH "${CMAKE_SOURCE_DIR}/" SOURCE_PATH_SIZE)
add_definitions("-DSOURCE_PATH_SIZE=${SOURCE_PATH_SIZE}")
add_definitions(-DBUILDING_DRMLIB)
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,--no-undefined")
set(CMAKE_POSITION_INDEPENDENT_CODE TRUE)

Expand All @@ -49,6 +65,7 @@ set(API_HEADERS
include/accelize/drm/error.h
include/accelize/drm/metering.h
include/accelize/drm.h
include/accelize/drmc/common.h
include/accelize/drmc/errorcode.h
include/accelize/drmc/metering.h
include/accelize/drmc/version.h
Expand Down Expand Up @@ -116,7 +133,8 @@ include(GNUInstallDirs)
install(TARGETS accelize_drm LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT libraries)
install(TARGETS accelize_drmc LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT libraries)
install(DIRECTORY ${CMAKE_BINARY_DIR}/include/ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} COMPONENT headers)
install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/licenses/ DESTINATION ${CMAKE_INSTALL_DOCDIR}/licenses/ COMPONENT licenses)
install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/LICENSE DESTINATION ${CMAKE_INSTALL_DOCDIR}/licenses COMPONENT licenses)
install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/third-party-licenses/ DESTINATION ${CMAKE_INSTALL_DOCDIR}/licenses/third-party-licenses/ COMPONENT licenses)

# Documentation
option(DOC "Produce documentation" OFF)
Expand Down
File renamed without changes.
5 changes: 4 additions & 1 deletion include/accelize/drm/error.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,24 @@ limitations under the License.

#include "accelize/drmc/errorcode.h" // enum with error codes

#include "accelize/drmc/common.h"

namespace Accelize {
namespace DRMLib {

/** \brief Exception class with error code for the DRMLib
This class is an exception that may be thrown by the DRMLib in case of synchronous error
*/
class Exception : public std::runtime_error {
class DRMLIB_EXPORT Exception : public std::runtime_error {
protected:
DRMLibErrorCode errCode; /**< error code from the DRMLibErrorCode enum */
mutable std::string errWhat; /**< internal error message to be accessed from what() */

public:
template <class S>
Exception(DRMLibErrorCode errCode, S&& errMsg) : std::runtime_error(std::forward<S>(errMsg)), errCode(errCode) {}
virtual ~Exception() {};
DRMLibErrorCode getErrCode() const;
virtual const char* what() const noexcept;
};
Expand Down
4 changes: 3 additions & 1 deletion include/accelize/drm/session_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ limitations under the License.
#include <string>
#include <functional>

#include "accelize/drmc/common.h"

namespace Accelize {
namespace DRMLib {

Expand All @@ -39,7 +41,7 @@ The session of metering life-cycle is:
After stop the session is correctly ended on the Accelize Webservice.
*/
class MeteringSessionManager {
class DRMLIB_EXPORT MeteringSessionManager {
private:
class Impl; //!< Internal representation
Impl* pImpl; //!< Internal representation
Expand Down
4 changes: 3 additions & 1 deletion include/accelize/drm/version.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,14 @@ limitations under the License.

#define METERINGLIB_VERSION "@GIT_VERSION@"

#include "accelize/drmc/common.h"

namespace Accelize {
namespace DRMLib {

/** \brief Get DRMLib version
*/
const char* getVersion();
const char* getVersion() DRMLIB_EXPORT;

}
}
Expand Down
33 changes: 33 additions & 0 deletions include/accelize/drmc/common.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
Copyright (C) 2018, Accelize
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 _H_ACCELIZE_COMMON_LIBEXPORT
#define _H_ACCELIZE_COMMON_LIBEXPORT

#ifdef __cplusplus
#ifdef BUILDING_DRMLIB
#define DRMLIB_EXPORT __attribute__((visibility("default")))
#define DRMLIB_LOCAL __attribute__((visibility("hidden")))
#else
#define DRMLIB_EXPORT
#define DRMLIB_LOCAL
#endif /* BUILDING_DRMLIB */
#else
#define DRMLIB_EXPORT
#define DRMLIB_LOCAL
#endif /* __cplusplus */

#endif /* _H_ACCELIZE_COMMON_LIBEXPORT */
1 change: 1 addition & 0 deletions include/accelize/drmc/errorcode.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ typedef enum {
DRMWSRespError = 10001, /**< A malformed response has been received from Accelize WebService */
DRMWSReqError = 10002, /**< Failed during HTTP request to Accelize WebService */
DRMWSError = 10003, /**< Error returned from Accelize WebService */
DRMWSMayRetry = 10004, /**< Error with request to Accelize Webservice, retry advised */

DRMCtlrError = 20001, /**< An error happened on a command on the DRM controller */

Expand Down
17 changes: 9 additions & 8 deletions include/accelize/drmc/metering.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ limitations under the License.
#define _H_ACCELIZE_METERING_CWRAPPER

#include "accelize/drmc/errorcode.h"
#include "accelize/drmc/common.h"

#ifdef __cplusplus
extern "C" {
Expand Down Expand Up @@ -58,49 +59,49 @@ typedef void (*ErrorCallBackHandler )(const char* /*error message*
\param[in] conf_file_path, cred_file_path, f_drm_read32, f_drm_write32, f_error_cb : see C++ API documentation
\param[in] user_p : user pointer that will be passed to the callback functions
*/
DRMLibErrorCode MeteringSessionManager_alloc(MeteringSessionManager **p_m, const char* conf_file_path, const char* cred_file_path, ReadReg32ByOffsetHandler f_drm_read32, WriteReg32ByOffsetHandler f_drm_write32, ErrorCallBackHandler f_error_cb, void* user_p);
DRMLibErrorCode MeteringSessionManager_alloc(MeteringSessionManager **p_m, const char* conf_file_path, const char* cred_file_path, ReadReg32ByOffsetHandler f_drm_read32, WriteReg32ByOffsetHandler f_drm_write32, ErrorCallBackHandler f_error_cb, void* user_p) DRMLIB_EXPORT;

/** \brief Wrapper typedef around C++ Accelize::DRMLib::MeteringSessionManager::~MeteringSessionManager destructor
\param[in] **p_m : pointer to a MeteringSessionManager pointer that will be freed. After *p_m == NULL.
*/
DRMLibErrorCode MeteringSessionManager_free(MeteringSessionManager **p_m);
DRMLibErrorCode MeteringSessionManager_free(MeteringSessionManager **p_m) DRMLIB_EXPORT;

/** \brief Wrapper typedef around C++ Accelize::DRMLib::MeteringSessionManager::start_session
\param[in] *m : pointer to a MeteringSessionManager object
*/
DRMLibErrorCode MeteringSessionManager_start_session(MeteringSessionManager *m);
DRMLibErrorCode MeteringSessionManager_start_session(MeteringSessionManager *m) DRMLIB_EXPORT;

/** \brief Wrapper typedef around C++ Accelize::DRMLib::MeteringSessionManager::stop_session
\param[in] *m : pointer to a MeteringSessionManager object
*/
DRMLibErrorCode MeteringSessionManager_stop_session(MeteringSessionManager *m);
DRMLibErrorCode MeteringSessionManager_stop_session(MeteringSessionManager *m) DRMLIB_EXPORT;

/** \brief Wrapper typedef around C++ Accelize::DRMLib::MeteringSessionManager::pause_session
\param[in] *m : pointer to a MeteringSessionManager object
*/
DRMLibErrorCode MeteringSessionManager_pause_session(MeteringSessionManager *m);
DRMLibErrorCode MeteringSessionManager_pause_session(MeteringSessionManager *m) DRMLIB_EXPORT;

/** \brief Wrapper typedef around C++ Accelize::DRMLib::MeteringSessionManager::resume_session
\param[in] *m : pointer to a MeteringSessionManager object
*/
DRMLibErrorCode MeteringSessionManager_resume_session(MeteringSessionManager *m);
DRMLibErrorCode MeteringSessionManager_resume_session(MeteringSessionManager *m) DRMLIB_EXPORT;

/** \brief Wrapper typedef around C++ Accelize::DRMLib::MeteringSessionManager::auto_start_session
\param[in] *m : pointer to a MeteringSessionManager object
*/
DRMLibErrorCode MeteringSessionManager_auto_start_session(MeteringSessionManager *m);
DRMLibErrorCode MeteringSessionManager_auto_start_session(MeteringSessionManager *m) DRMLIB_EXPORT;

/** \brief Wrapper typedef around C++ Accelize::DRMLib::MeteringSessionManager::dump_drm_hw_report
\param[in] *m : pointer to a MeteringSessionManager object
*/
DRMLibErrorCode MeteringSessionManager_dump_drm_hw_report(MeteringSessionManager *m);
DRMLibErrorCode MeteringSessionManager_dump_drm_hw_report(MeteringSessionManager *m) DRMLIB_EXPORT;

#ifdef __cplusplus
}
Expand Down
4 changes: 3 additions & 1 deletion include/accelize/drmc/version.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,14 @@ limitations under the License.
\note This C API is wrapping C++ API, please refer to C++ API
*/

#include "accelize/drmc/common.h"

#ifdef __cplusplus
extern "C" {
#endif

/** \brief Return version of the library as text */
const char * DRMLib_get_version();
const char * DRMLib_get_version() DRMLIB_EXPORT;

#ifdef __cplusplus
}
Expand Down
74 changes: 65 additions & 9 deletions internal_inc/log.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ limitations under the License.

#include <iostream>
#include <sstream>
#include <cstdlib>

#include "accelize/drm/error.h"

Expand All @@ -34,10 +35,30 @@ enum class eLogLevel {
ERROR = 1,
WARNING = 2,
INFO = 3,
DEBUG = 4
DEBUG = 4,
DEBUG2 = 5,
__SIZE
};
static eLogLevel gLogLevel = eLogLevel::INFO;

static eLogLevel getLogLevel() {
static eLogLevel logLevel = [](){
eLogLevel ret = eLogLevel::INFO;

const char* verbose_env = std::getenv("ACCELIZE_DRMLIB_VERBOSE");
if(verbose_env) {
try{
unsigned long uint_verbose_env = std::stoul(verbose_env);
if(uint_verbose_env < static_cast<unsigned long>(eLogLevel::__SIZE))
ret = static_cast<eLogLevel>(uint_verbose_env);
}catch(...){
//fall back to default
}
}

return ret;
}();
return logLevel;
}

static void ssAddToStream(std::ostream& a_stream) {(void)a_stream;}
template<typename T, typename... Args>
Expand All @@ -55,30 +76,42 @@ static std::string stringConcat(Args&&... a_args)
return ss.str();
}

static bool isDebug() {
if(getLogLevel() < eLogLevel::DEBUG) return false;
return true;
}

template <typename... Args>
void Debug( Args&&... args ) {
if(gLogLevel < eLogLevel::DEBUG) return;
if(!isDebug()) return;
ssAddToStream(gLog(), "[DEBUG] ", std::forward<Args>( args )...);
gLog() << std::endl;
}

template <typename... Args>
void Debug2( Args&&... args ) {
if(getLogLevel() < eLogLevel::DEBUG2) return;
ssAddToStream(gLog(), "[DEBUG2] ", std::forward<Args>( args )...);
gLog() << std::endl;
}

template <typename... Args>
void Info( Args&&... args ) {
if(gLogLevel < eLogLevel::INFO) return;
if(getLogLevel() < eLogLevel::INFO) return;
ssAddToStream(gLog(), "[INFO] ", std::forward<Args>( args )...);
gLog() << std::endl;
}

template <typename... Args>
void Warning( Args&&... args ) {
if(gLogLevel < eLogLevel::ERROR) return;
if(getLogLevel() < eLogLevel::ERROR) return;
ssAddToStream(gLog(), "[WARNING] ", std::forward<Args>( args )...);
gLog() << std::endl;
}

template <typename... Args>
void Error( Args&&... args ) {
if(gLogLevel < eLogLevel::ERROR) return;
if(getLogLevel() < eLogLevel::ERROR) return;
ssAddToStream(gLog(), "[ERROR] ", std::forward<Args>( args )...);
gLog() << std::endl;
}
Expand All @@ -91,11 +124,34 @@ template <typename... Args>
}
}

#define Assert(expr) \
if(expr) {} else {Throw(DRMLibAssert, "An assertion failed in DRMLib in ", __FILE__, ":", __LINE__, " (", __func__, ") : ", #expr, ". Please contact support.");}
#define __FILENAME__ (__FILE__ + SOURCE_PATH_SIZE)

#define _WarningAssert(expr, ...) \
if(expr) {} else {Warning("An assertion in DRMLib was not verified in ", __FILENAME__, ":", __LINE__, " (", __func__, ") : ", __VA_ARGS__, ". Please contact support, the library may not work as expected.");}
#define _Assert(expr, ...) \
if(expr) {} else {Throw(DRMLibAssert, "An assertion failed in DRMLib in ", __FILENAME__, ":", __LINE__, " (", __func__, ") : ", __VA_ARGS__, ". Please contact support.");}

#define __Assert(F, expr) F(expr, #expr)
#define __Assert2op(F, a, b, _op_) \
do { auto _a=a; auto _b=b; \
F(_a _op_ _b, #a, " (= ", _a, ") " , #_op_, " ", #b " (= ", _b, ")"); \
} while(0);

#define WarningAssert(expr) __Assert(_WarningAssert, expr)
#define WarningAssertEqual(a, b) __Assert2op(_WarningAssert, a, b, ==)
#define WarningAssertGreater(a, b) __Assert2op(_WarningAssert, a, b, >)
#define WarningAssertGreaterEqual(a, b) __Assert2op(_WarningAssert, a, b, >=)
#define WarningAssertLess(a, b) __Assert2op(_WarningAssert, a, b, <)
#define WarningAssertLessEqual(a, b) __Assert2op(_WarningAssert, a, b, <=)
#define Assert(expr) __Assert(_Assert, expr)
#define AssertEqual(a, b) __Assert2op(_Assert, a, b, ==)
#define AssertGreater(a, b) __Assert2op(_Assert, a, b, >)
#define AssertGreaterEqual(a, b) __Assert2op(_Assert, a, b, >=)
#define AssertLess(a, b) __Assert2op(_Assert, a, b, <)
#define AssertLessEqual(a, b) __Assert2op(_Assert, a, b, <=)

#define Unreachable() \
Throw(DRMLibAssert, "An unreachable part of code has be reached in DRMLib in ", __FILE__, ":", __LINE__, " (", __func__, ") : Please contact support.")
Throw(DRMLibAssert, "An unreachable part of code has be reached in DRMLib in ", __FILENAME__, ":", __LINE__, " (", __func__, ") : Please contact support.")


#endif // _H_ACCELIZE_METERING_LOG
5 changes: 4 additions & 1 deletion internal_inc/ws_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ limitations under the License.

#include <string>
#include <jsoncpp/json/json.h>
#include <chrono>

namespace Accelize {
namespace DRMLib {
Expand All @@ -31,15 +32,17 @@ class MeteringWSClient {
std::string client_id;
std::string client_secret;
std::string metering_url;
std::chrono::seconds default_request_timeout;

public:
MeteringWSClient(const Json::Value& config_server, const Json::Value& credentials);
~MeteringWSClient() = default;

Json::Value getLicense(const Json::Value& json_req);
Json::Value getLicense(const Json::Value& json_req, std::chrono::steady_clock::time_point deadline);

protected:
std::string getOAuth2token();
std::string getOAuth2token(std::chrono::steady_clock::time_point deadline);

};

Expand Down
Loading

0 comments on commit 4ff7ae6

Please sign in to comment.