diff --git a/src/system_wrappers/interface/data_log_c.h b/src/system_wrappers/interface/data_log_c.h new file mode 100644 index 0000000000..39825233c2 --- /dev/null +++ b/src/system_wrappers/interface/data_log_c.h @@ -0,0 +1,88 @@ +/* + * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +/* + * This is a pure C wrapper of the DataLog class. The functions are directly + * mapped here except for InsertCell as C does not support templates. + * See data_log.h for a description of the functions. + */ + +#ifndef SRC_SYSTEM_WRAPPERS_INTERFACE_DATA_LOG_C_H_ +#define SRC_SYSTEM_WRAPPERS_INTERFACE_DATA_LOG_C_H_ + +#include /* size_t */ +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/* + * All char* parameters in this file are expected to be null-terminated + * character sequences. + */ +int WebRtcDataLog_CreateLog(); +void WebRtcDataLog_ReturnLog(); +char* WebRtcDataLog_Combine(char* combined_name, size_t combined_len, + const char* table_name, int table_id); +int WebRtcDataLog_AddTable(const char* table_name); +int WebRtcDataLog_AddColumn(const char* table_name, const char* column_name, + int multi_value_length); + +int WebRtcDataLog_InsertCell_int(const char* table_name, + const char* column_name, + int value); +int WebRtcDataLog_InsertArray_int(const char* table_name, + const char* column_name, + const int* values, + int length); +int WebRtcDataLog_InsertCell_float(const char* table_name, + const char* column_name, + float value); +int WebRtcDataLog_InsertArray_float(const char* table_name, + const char* column_name, + const float* values, + int length); +int WebRtcDataLog_InsertCell_double(const char* table_name, + const char* column_name, + double value); +int WebRtcDataLog_InsertArray_double(const char* table_name, + const char* column_name, + const double* values, + int length); +int WebRtcDataLog_InsertCell_int32(const char* table_name, + const char* column_name, + int32_t value); +int WebRtcDataLog_InsertArray_int32(const char* table_name, + const char* column_name, + const int32_t* values, + int length); +int WebRtcDataLog_InsertCell_uint32(const char* table_name, + const char* column_name, + uint32_t value); +int WebRtcDataLog_InsertArray_uint32(const char* table_name, + const char* column_name, + const uint32_t* values, + int length); +int WebRtcDataLog_InsertCell_int64(const char* table_name, + const char* column_name, + int64_t value); +int WebRtcDataLog_InsertArray_int64(const char* table_name, + const char* column_name, + const int64_t* values, + int length); + +int WebRtcDataLog_NextRow(const char* table_name); + +#ifdef __cplusplus +} /* end of extern "C" */ +#endif + +#endif /* SRC_SYSTEM_WRAPPERS_INTERFACE_DATA_LOG_C_H_ */ diff --git a/src/system_wrappers/source/data_log_c.cc b/src/system_wrappers/source/data_log_c.cc new file mode 100644 index 0000000000..f8d7efd08c --- /dev/null +++ b/src/system_wrappers/source/data_log_c.cc @@ -0,0 +1,145 @@ +/* + * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +/* + * This is the pure C wrapper of the DataLog class. + */ + +#include "system_wrappers/interface/data_log_c.h" + +#include + +#include "system_wrappers/interface/data_log.h" + +extern "C" int WebRtcDataLog_CreateLog() { + return webrtc::DataLog::CreateLog(); +} + +extern "C" void WebRtcDataLog_ReturnLog() { + return webrtc::DataLog::ReturnLog(); +} + +extern "C" char* WebRtcDataLog_Combine(char* combined_name, size_t combined_len, + const char* table_name, int table_id) { + if (!table_name) return NULL; + std::string combined = webrtc::DataLog::Combine(table_name, table_id); + if (combined.size() >= combined_len) return NULL; + std::copy(combined.begin(), combined.end(), combined_name); + combined_name[combined.size()] = '\0'; + return combined_name; +} + +extern "C" int WebRtcDataLog_AddTable(const char* table_name) { + if (!table_name) return -1; + return webrtc::DataLog::AddTable(table_name); +} + +extern "C" int WebRtcDataLog_AddColumn(const char* table_name, + const char* column_name, + int multi_value_length) { + if (!table_name || !column_name) return -1; + return webrtc::DataLog::AddColumn(table_name, column_name, + multi_value_length); +} + +extern "C" int WebRtcDataLog_InsertCell_int(const char* table_name, + const char* column_name, + int value) { + if (!table_name || !column_name) return -1; + return webrtc::DataLog::InsertCell(table_name, column_name, value); +} + +extern "C" int WebRtcDataLog_InsertArray_int(const char* table_name, + const char* column_name, + const int* values, + int length) { + if (!table_name || !column_name) return -1; + return webrtc::DataLog::InsertCell(table_name, column_name, values, length); +} + +extern "C" int WebRtcDataLog_InsertCell_float(const char* table_name, + const char* column_name, + float value) { + if (!table_name || !column_name) return -1; + return webrtc::DataLog::InsertCell(table_name, column_name, value); +} + +extern "C" int WebRtcDataLog_InsertArray_float(const char* table_name, + const char* column_name, + const float* values, + int length) { + if (!table_name || !column_name) return -1; + return webrtc::DataLog::InsertCell(table_name, column_name, values, length); +} + +extern "C" int WebRtcDataLog_InsertCell_double(const char* table_name, + const char* column_name, + double value) { + if (!table_name || !column_name) return -1; + return webrtc::DataLog::InsertCell(table_name, column_name, value); +} + +extern "C" int WebRtcDataLog_InsertArray_double(const char* table_name, + const char* column_name, + const double* values, + int length) { + if (!table_name || !column_name) return -1; + return webrtc::DataLog::InsertCell(table_name, column_name, values, length); +} + +extern "C" int WebRtcDataLog_InsertCell_int32(const char* table_name, + const char* column_name, + int32_t value) { + if (!table_name || !column_name) return -1; + return webrtc::DataLog::InsertCell(table_name, column_name, value); +} + +extern "C" int WebRtcDataLog_InsertArray_int32(const char* table_name, + const char* column_name, + const int32_t* values, + int length) { + if (!table_name || !column_name) return -1; + return webrtc::DataLog::InsertCell(table_name, column_name, values, length); +} + +extern "C" int WebRtcDataLog_InsertCell_uint32(const char* table_name, + const char* column_name, + uint32_t value) { + if (!table_name || !column_name) return -1; + return webrtc::DataLog::InsertCell(table_name, column_name, value); +} + +extern "C" int WebRtcDataLog_InsertArray_uint32(const char* table_name, + const char* column_name, + const uint32_t* values, + int length) { + if (!table_name || !column_name) return -1; + return webrtc::DataLog::InsertCell(table_name, column_name, values, length); +} + +extern "C" int WebRtcDataLog_InsertCell_int64(const char* table_name, + const char* column_name, + int64_t value) { + if (!table_name || !column_name) return -1; + return webrtc::DataLog::InsertCell(table_name, column_name, value); +} + +extern "C" int WebRtcDataLog_InsertArray_int64(const char* table_name, + const char* column_name, + const int64_t* values, + int length) { + if (!table_name || !column_name) return -1; + return webrtc::DataLog::InsertCell(table_name, column_name, values, length); +} + +extern "C" int WebRtcDataLog_NextRow(const char* table_name) { + if (!table_name) return -1; + return webrtc::DataLog::NextRow(table_name); +} diff --git a/src/system_wrappers/source/data_log_c_helpers_unittest.c b/src/system_wrappers/source/data_log_c_helpers_unittest.c new file mode 100644 index 0000000000..f2371f4571 --- /dev/null +++ b/src/system_wrappers/source/data_log_c_helpers_unittest.c @@ -0,0 +1,117 @@ +/* + * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#include "system_wrappers/source/data_log_c_helpers_unittest.h" + +#include +#include + +#include "system_wrappers/interface/data_log_c.h" + +enum { kTestArrayLen = 4 }; +static const char kTableName[] = "c_wrapper_table"; +static const char kColumnName1[] = "Scalar"; +static const char kColumnName2[] = "Vector"; + +int WebRtcDataLogCHelper_TestCreateLog() { + return WebRtcDataLog_CreateLog(); +} + +int WebRtcDataLogCHelper_TestReturnLog() { + WebRtcDataLog_ReturnLog(); + return 0; +} + +int WebRtcDataLogCHelper_TestCombine() { + const int kOutLen = strlen(kTableName) + 4; /* Room for "_17" + '\0' */ + char combined_name[kOutLen]; + char* out_ptr = WebRtcDataLog_Combine(combined_name, kOutLen, kTableName, 17); + if (!out_ptr) return -1; + if (strcmp(combined_name, "c_wrapper_table_17") != 0) return -2; + return 0; +} + +int WebRtcDataLogCHelper_TestAddTable() { + return WebRtcDataLog_AddTable(kTableName); +} + +int WebRtcDataLogCHelper_TestAddColumn() { + if (WebRtcDataLog_AddColumn(kTableName, kColumnName1, 1) != 0) { + return -1; + } + if (WebRtcDataLog_AddColumn(kTableName, kColumnName2, kTestArrayLen) != 0) { + return -2; + } + return 0; +} + +int WebRtcDataLogCHelper_TestNextRow() { + return WebRtcDataLog_NextRow(kTableName); +} + +int WebRtcDataLogCHelper_TestInsertCell_int() { + return WebRtcDataLog_InsertCell_int(kTableName, kColumnName1, 17); +} + +int WebRtcDataLogCHelper_TestInsertArray_int() { + int values[kTestArrayLen] = {1, 2, 3, 4}; + return WebRtcDataLog_InsertArray_int(kTableName, kColumnName2, values, + kTestArrayLen); +} + +int WebRtcDataLogCHelper_TestInsertCell_float() { + return WebRtcDataLog_InsertCell_float(kTableName, kColumnName1, 17.0f); +} + +int WebRtcDataLogCHelper_TestInsertArray_float() { + float values[kTestArrayLen] = {1.0f, 2.0f, 3.0f, 4.0f}; + return WebRtcDataLog_InsertArray_float(kTableName, kColumnName2, values, + kTestArrayLen); +} + +int WebRtcDataLogCHelper_TestInsertCell_double() { + return WebRtcDataLog_InsertCell_int(kTableName, kColumnName1, 17.0); +} + +int WebRtcDataLogCHelper_TestInsertArray_double() { + double values[kTestArrayLen] = {1.0, 2.0, 3.0, 4.0}; + return WebRtcDataLog_InsertArray_double(kTableName, kColumnName2, values, + kTestArrayLen); +} + +int WebRtcDataLogCHelper_TestInsertCell_int32() { + return WebRtcDataLog_InsertCell_int32(kTableName, kColumnName1, 17); +} + +int WebRtcDataLogCHelper_TestInsertArray_int32() { + int32_t values[kTestArrayLen] = {1, 2, 3, 4}; + return WebRtcDataLog_InsertArray_int32(kTableName, kColumnName2, values, + kTestArrayLen); +} + +int WebRtcDataLogCHelper_TestInsertCell_uint32() { + return WebRtcDataLog_InsertCell_uint32(kTableName, kColumnName1, 17); +} + +int WebRtcDataLogCHelper_TestInsertArray_uint32() { + uint32_t values[kTestArrayLen] = {1, 2, 3, 4}; + return WebRtcDataLog_InsertArray_uint32(kTableName, kColumnName2, values, + kTestArrayLen); +} + +int WebRtcDataLogCHelper_TestInsertCell_int64() { + return WebRtcDataLog_InsertCell_int64(kTableName, kColumnName1, 17); +} + +int WebRtcDataLogCHelper_TestInsertArray_int64() { + int64_t values[kTestArrayLen] = {1, 2, 3, 4}; + return WebRtcDataLog_InsertArray_int64(kTableName, kColumnName2, values, + kTestArrayLen); +} diff --git a/src/system_wrappers/source/data_log_c_helpers_unittest.h b/src/system_wrappers/source/data_log_c_helpers_unittest.h new file mode 100644 index 0000000000..ef86eae0b1 --- /dev/null +++ b/src/system_wrappers/source/data_log_c_helpers_unittest.h @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#ifndef SRC_SYSTEM_WRAPPERS_SOURCE_DATA_LOG_C_HELPERS_UNITTEST_H_ +#define SRC_SYSTEM_WRAPPERS_SOURCE_DATA_LOG_C_HELPERS_UNITTEST_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +int WebRtcDataLogCHelper_TestCreateLog(); + +int WebRtcDataLogCHelper_TestReturnLog(); + +int WebRtcDataLogCHelper_TestCombine(); + +int WebRtcDataLogCHelper_TestAddTable(); + +int WebRtcDataLogCHelper_TestAddColumn(); + +int WebRtcDataLogCHelper_TestNextRow(); + +int WebRtcDataLogCHelper_TestInsertCell_int(); + +int WebRtcDataLogCHelper_TestInsertArray_int(); + +int WebRtcDataLogCHelper_TestInsertCell_float(); + +int WebRtcDataLogCHelper_TestInsertArray_float(); + +int WebRtcDataLogCHelper_TestInsertCell_double(); + +int WebRtcDataLogCHelper_TestInsertArray_double(); + +int WebRtcDataLogCHelper_TestInsertCell_int32(); + +int WebRtcDataLogCHelper_TestInsertArray_int32(); + +int WebRtcDataLogCHelper_TestInsertCell_uint32(); + +int WebRtcDataLogCHelper_TestInsertArray_uint32(); + +int WebRtcDataLogCHelper_TestInsertCell_int64(); + +int WebRtcDataLogCHelper_TestInsertArray_int64(); + +#ifdef __cplusplus +} // end of extern "C" +#endif + +#endif // SRC_SYSTEM_WRAPPERS_SOURCE_DATA_LOG_C_HELPERS_UNITTEST_H_ diff --git a/src/system_wrappers/source/data_log_unittest.cc b/src/system_wrappers/source/data_log_unittest.cc index 9458234664..d588947f04 100644 --- a/src/system_wrappers/source/data_log_unittest.cc +++ b/src/system_wrappers/source/data_log_unittest.cc @@ -11,7 +11,9 @@ #include #include -#include "data_log.h" +#include "system_wrappers/interface/data_log.h" +#include "system_wrappers/interface/data_log_c.h" +#include "system_wrappers/source/data_log_c_helpers_unittest.h" #include "gtest/gtest.h" using ::webrtc::DataLog; @@ -272,3 +274,32 @@ TEST(TestDataLog, VerifyMultipleTables) { fclose(table); } } + +TEST(TestDataLogCWrapper, VerifyCWrapper) { + // Simply call all C wrapper log functions through the C helper unittests. + // Main purpose is to make sure that the linkage is correct. + + EXPECT_EQ(0, WebRtcDataLogCHelper_TestCreateLog()); + EXPECT_EQ(0, WebRtcDataLogCHelper_TestCombine()); + EXPECT_EQ(0, WebRtcDataLogCHelper_TestAddTable()); + EXPECT_EQ(0, WebRtcDataLogCHelper_TestAddColumn()); + EXPECT_EQ(0, WebRtcDataLogCHelper_TestInsertCell_int()); + EXPECT_EQ(0, WebRtcDataLogCHelper_TestInsertArray_int()); + EXPECT_EQ(0, WebRtcDataLogCHelper_TestNextRow()); + EXPECT_EQ(0, WebRtcDataLogCHelper_TestInsertCell_float()); + EXPECT_EQ(0, WebRtcDataLogCHelper_TestInsertArray_float()); + EXPECT_EQ(0, WebRtcDataLogCHelper_TestNextRow()); + EXPECT_EQ(0, WebRtcDataLogCHelper_TestInsertCell_double()); + EXPECT_EQ(0, WebRtcDataLogCHelper_TestInsertArray_double()); + EXPECT_EQ(0, WebRtcDataLogCHelper_TestNextRow()); + EXPECT_EQ(0, WebRtcDataLogCHelper_TestInsertCell_int32()); + EXPECT_EQ(0, WebRtcDataLogCHelper_TestInsertArray_int32()); + EXPECT_EQ(0, WebRtcDataLogCHelper_TestNextRow()); + EXPECT_EQ(0, WebRtcDataLogCHelper_TestInsertCell_uint32()); + EXPECT_EQ(0, WebRtcDataLogCHelper_TestInsertArray_uint32()); + EXPECT_EQ(0, WebRtcDataLogCHelper_TestNextRow()); + EXPECT_EQ(0, WebRtcDataLogCHelper_TestInsertCell_int64()); + EXPECT_EQ(0, WebRtcDataLogCHelper_TestInsertArray_int64()); + EXPECT_EQ(0, WebRtcDataLogCHelper_TestNextRow()); + EXPECT_EQ(0, WebRtcDataLogCHelper_TestReturnLog()); +} diff --git a/src/system_wrappers/source/system_wrappers.gyp b/src/system_wrappers/source/system_wrappers.gyp index c3e98ea107..02221df967 100644 --- a/src/system_wrappers/source/system_wrappers.gyp +++ b/src/system_wrappers/source/system_wrappers.gyp @@ -33,6 +33,7 @@ '../interface/cpu_features_wrapper.h', '../interface/critical_section_wrapper.h', '../interface/data_log.h', + '../interface/data_log_c.h', '../interface/data_log_impl.h', '../interface/event_wrapper.h', '../interface/file_wrapper.h', @@ -63,6 +64,7 @@ 'critical_section.cc', 'critical_section_posix.h', 'critical_section_windows.h', + 'data_log_c.cc', 'event.cc', 'event_posix.h', 'event_windows.h', diff --git a/src/system_wrappers/source/system_wrappers_tests.gyp b/src/system_wrappers/source/system_wrappers_tests.gyp index 5005d866f7..6c126301aa 100644 --- a/src/system_wrappers/source/system_wrappers_tests.gyp +++ b/src/system_wrappers/source/system_wrappers_tests.gyp @@ -26,6 +26,8 @@ 'list_unittest.cc', 'map_unittest.cc', 'data_log_helpers_unittest.cc', + 'data_log_c_helpers_unittest.c', + 'data_log_c_helpers_unittest.h', ], 'conditions': [ ['enable_data_logging==1', {