Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
121 changes: 60 additions & 61 deletions api/janice_error.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,38 +27,64 @@ extern "C" {
// ----------------------------------------------------------------------------
// Error Handling

// taa: this hack creates the enum and an array containing the names of the enums.
// We handle JANICE_SUCCESS and JANICE_NUM_ERRORS somewhat separately.

#define JANICE_ERROR_ENUM \
X(JANICE_UNKNOWN_ERROR, "Unknown error") /* Catch all error code */ \
X(JANICE_INTERNAL_ERROR, "Internal SDK error") \
X(JANICE_OUT_OF_MEMORY, "Out of memory error") \
X(JANICE_INVALID_SDK_PATH, "Invalid SDK path") \
X(JANICE_BAD_SDK_CONFIG, "Bad SDK configuration") \
X(JANICE_BAD_LICENSE, "Bad license") \
X(JANICE_MISSING_DATA, "Missing required data") /* Missing SDK data */\
X(JANICE_INVALID_GPU, "Invalid GPU") /* The GPU is not functioning */ \
X(JANICE_BAD_ARGUMENT, "An argument to a JanICE function is invalid") \
X(JANICE_OPEN_ERROR, "Failed to open a file") \
X(JANICE_READ_ERROR, "Failed to read from a file") \
X(JANICE_WRITE_ERROR, "Failed to write to a file") \
X(JANICE_PARSE_ERROR, "Failed to parse a file") \
X(JANICE_INVALID_MEDIA, "Invalid media file") /* Failed to decode a media file */ \
X(JANICE_OUT_OF_BOUNDS_ACCESS, "Out of bounds access into a buffer") \
X(JANICE_MEDIA_AT_END, "A media object reached the end of its internal data") \
X(JANICE_INVALID_ATTRIBUTE_KEY, "An invalid attribute key was provided") \
X(JANICE_MISSING_ATTRIBUTE, "A value for a valid attribute key is not present") \
X(JANICE_DUPLICATE_ID, "Duplicate template ID in a gallery") \
X(JANICE_MISSING_ID, "Missing template ID in a gallery") \
X(JANICE_MISSING_FILE_NAME, "Missing a file name") \
X(JANICE_INCORRECT_ROLE, "Incorrect template role") \
X(JANICE_FAILURE_TO_SERIALIZE, "Unable to serialize an API object") \
X(JANICE_FAILURE_TO_DESERIALIZE, "Unable to deserialize an API object") \
X(JANICE_BATCH_ABORTED_EARLY, "Batch call aborted early due to error") \
X(JANICE_BATCH_FINISHED_WITH_ERRORS, "Batch call finished, but with errors") \
X(JANICE_CALLBACK_EXIT_IMMEDIATELY, "A callback requested its parent exit immediately") \
X(JANICE_NOT_IMPLEMENTED, "Optional function is not implemented")



enum JaniceError
{
JANICE_SUCCESS = 0 , // No error
JANICE_UNKNOWN_ERROR , // Catch all error code
JANICE_INTERNAL_ERROR , // An internal SDK error was encountered
JANICE_OUT_OF_MEMORY , // Out of memory error
JANICE_INVALID_SDK_PATH , // Invalid SDK location
JANICE_BAD_SDK_CONFIG , // Invalid SDK configuration
JANICE_BAD_LICENSE , // Incorrect license file
JANICE_MISSING_DATA , // Missing SDK data
JANICE_INVALID_GPU , // The GPU is not functioning
JANICE_BAD_ARGUMENT , // An argument to a JanICE function is invalid
JANICE_OPEN_ERROR , // Failed to open a file
JANICE_READ_ERROR , // Failed to read from a file
JANICE_WRITE_ERROR , // Failed to write to a file
JANICE_PARSE_ERROR , // Failed to parse a file
JANICE_INVALID_MEDIA , // Failed to decode a media file
JANICE_OUT_OF_BOUNDS_ACCESS , // Out of bounds access into a buffer
JANICE_MEDIA_AT_END , // Media object is at the end of its data
JANICE_INVALID_ATTRIBUTE_KEY , // An invalid attribute key was provided
JANICE_MISSING_ATTRIBUTE , // A value for a valid attribute key is not present
JANICE_DUPLICATE_ID , // Template id already exists in a gallery
JANICE_MISSING_ID , // Template id can't be found
JANICE_MISSING_FILE_NAME , // An expected file name is not given
JANICE_INCORRECT_ROLE , // Incorrect template role
JANICE_FAILURE_TO_SERIALIZE , // Could not serialize a data structure
JANICE_FAILURE_TO_DESERIALIZE , // Could not deserialize a data structure
JANICE_BATCH_ABORTED_EARLY , // Batch call aborted early due to error
JANICE_BATCH_FINISHED_WITH_ERRORS, // Batch call finished, but with errors
JANICE_CALLBACK_EXIT_IMMEDIATELY , // Callback error indicating processing should stop immediately
JANICE_NOT_IMPLEMENTED , // Optional function return
JANICE_NUM_ERRORS // Utility to iterate over all errors
# define X(a,b) a,
JANICE_SUCCESS = 0,
JANICE_ERROR_ENUM
# undef X
JANICE_NUM_ERRORS // Utility to iterate over all errors
};

char const *const janice_error_names[] = {
# define X(a,b) #a,
"JANICE_SUCCESS",
JANICE_ERROR_ENUM
# undef X
0
};

char const *const janice_error_strings[] = {
# define X(a,b) b,
"Success",
JANICE_ERROR_ENUM
# undef X
"The total number of errors. This shouldn't have been returned..."
};

struct JaniceErrors
Expand All @@ -71,40 +97,13 @@ JANICE_EXPORT JaniceError janice_clear_errors(JaniceErrors* errors);

static inline const char* janice_error_to_string(JaniceError error)
{
if (error == JANICE_SUCCESS) return "Success";
else if (error == JANICE_UNKNOWN_ERROR) return "Unknown error";
else if (error == JANICE_INTERNAL_ERROR) return "Internal SDK error";
else if (error == JANICE_OUT_OF_MEMORY) return "Out of memory error";
else if (error == JANICE_INVALID_SDK_PATH) return "Invalid SDK path";
else if (error == JANICE_BAD_SDK_CONFIG) return "Bad SDK configuration";
else if (error == JANICE_BAD_LICENSE) return "Bad license";
else if (error == JANICE_MISSING_DATA) return "Missing required data";
else if (error == JANICE_INVALID_GPU) return "Invalid GPU";
else if (error == JANICE_BAD_ARGUMENT) return "An argument to a JanICE function is invalid";
else if (error == JANICE_OPEN_ERROR) return "Failed to open a file";
else if (error == JANICE_READ_ERROR) return "Failed to read from a file";
else if (error == JANICE_WRITE_ERROR) return "Failed to write to a file";
else if (error == JANICE_PARSE_ERROR) return "Failed to parse a file";
else if (error == JANICE_INVALID_MEDIA) return "Invalid media file";
else if (error == JANICE_OUT_OF_BOUNDS_ACCESS) return "Out of bounds access into a buffer";
else if (error == JANICE_MEDIA_AT_END) return "A media object has reached the end of its internal data";
else if (error == JANICE_INVALID_ATTRIBUTE_KEY) return "An invalid attribute key has been provided";
else if (error == JANICE_MISSING_ATTRIBUTE) return "A valid attribute key was provided but there is no value";
else if (error == JANICE_DUPLICATE_ID) return "Duplicate template ID in a gallery";
else if (error == JANICE_MISSING_ID) return "Missing template ID in a gallery";
else if (error == JANICE_MISSING_FILE_NAME) return "Missing a file name";
else if (error == JANICE_INCORRECT_ROLE) return "Incorrect template role";
else if (error == JANICE_FAILURE_TO_SERIALIZE) return "Unable to serialize an API object";
else if (error == JANICE_FAILURE_TO_DESERIALIZE) return "Unable to deserialize an API object";
else if (error == JANICE_BATCH_ABORTED_EARLY) return "Batch call aborted early due to an error";
else if (error == JANICE_BATCH_FINISHED_WITH_ERRORS) return "Batch call finished but with errors";
else if (error == JANICE_CALLBACK_EXIT_IMMEDIATELY) return "A callback requested its parent exit immediately";
else if (error == JANICE_NOT_IMPLEMENTED) return "Optional function is not implemented";
else if (error == JANICE_NUM_ERRORS) return "The total number of errors. This shouldn't have been returned...";

if (error < JANICE_SUCCESS || error > JANICE_NUM_ERRORS) {
return "Unknown error code";
}
return janice_error_strings[error];
}


// ----------------------------------------------------------------------------

#ifdef __cplusplus
Expand Down
36 changes: 34 additions & 2 deletions harness/include/fast-cpp-csv-parser/csv.h
Original file line number Diff line number Diff line change
Expand Up @@ -847,7 +847,8 @@ namespace io{
void parse_line(
char*line,
char**sorted_col,
const std::vector<int>&col_order
const std::vector<int>&col_order,
ignore_column ignore_policy = ignore_no_column
){
for(std::size_t i=0; i<col_order.size(); ++i){
if(line == nullptr)
Expand All @@ -862,7 +863,7 @@ namespace io{
sorted_col[col_order[i]] = col_begin;
}
}
if(line != nullptr)
if(line != nullptr && ignore_policy != ignore_extra_column)
throw ::io::error::too_many_columns();
}

Expand Down Expand Up @@ -1241,6 +1242,37 @@ namespace io{
throw;
}

return true;
}
template<class ...ColType>
bool read_row(ignore_column ignore_policy, ColType& ...cols){
static_assert(sizeof...(ColType)>=column_count,
"not enough columns specified");
static_assert(sizeof...(ColType)<=column_count,
"too many columns specified");
try{
try{

char*line;
do{
line = in.next_line();
if(!line)
return false;
}while(comment_policy::is_comment(line));

detail::parse_line<trim_policy, quote_policy>
(line, row, col_order, ignore_policy);

parse_helper(0, cols...);
}catch(error::with_file_name&err){
err.set_file_name(in.get_truncated_file_name());
throw;
}
}catch(error::with_file_line&err){
err.set_file_line(in.get_file_line());
throw;
}

return true;
}
};
Expand Down
43 changes: 10 additions & 33 deletions harness/include/janice_harness.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,40 +20,17 @@
static inline void janice_harness_register_nonfatal_errors(const std::vector<std::string>& error_list, std::set<JaniceError>& ignored_errors) {
for (auto &error_str : error_list) {
JaniceError error;
if (error_str == "JANICE_SUCCESS") error = JANICE_SUCCESS;
else if (error_str == "JANICE_UNKNOWN_ERROR") error = JANICE_UNKNOWN_ERROR;
else if (error_str == "JANICE_INTERNAL_ERROR") error = JANICE_INTERNAL_ERROR;
else if (error_str == "JANICE_OUT_OF_MEMORY") error = JANICE_OUT_OF_MEMORY;
else if (error_str == "JANICE_INVALID_SDK_PATH") error = JANICE_INVALID_SDK_PATH;
else if (error_str == "JANICE_BAD_SDK_CONFIG") error = JANICE_BAD_SDK_CONFIG;
else if (error_str == "JANICE_BAD_LICENSE") error = JANICE_BAD_LICENSE;
else if (error_str == "JANICE_MISSING_DATA") error = JANICE_MISSING_DATA;
else if (error_str == "JANICE_INVALID_GPU") error = JANICE_INVALID_GPU;
else if (error_str == "JANICE_BAD_ARGUMENT") error = JANICE_BAD_ARGUMENT;
else if (error_str == "JANICE_OPEN_ERROR") error = JANICE_OPEN_ERROR;
else if (error_str == "JANICE_READ_ERROR") error = JANICE_READ_ERROR;
else if (error_str == "JANICE_WRITE_ERROR") error = JANICE_WRITE_ERROR;
else if (error_str == "JANICE_PARSE_ERROR") error = JANICE_PARSE_ERROR;
else if (error_str == "JANICE_INVALID_MEDIA") error = JANICE_INVALID_MEDIA;
else if (error_str == "JANICE_OUT_OF_BOUNDS_ACCESS") error = JANICE_OUT_OF_BOUNDS_ACCESS;
else if (error_str == "JANICE_MEDIA_AT_END") error = JANICE_MEDIA_AT_END;
else if (error_str == "JANICE_INVALID_ATTRIBUTE_KEY") error = JANICE_INVALID_ATTRIBUTE_KEY;
else if (error_str == "JANICE_MISSING_ATTRIBUTE") error = JANICE_MISSING_ATTRIBUTE;
else if (error_str == "JANICE_DUPLICATE_ID") error = JANICE_DUPLICATE_ID;
else if (error_str == "JANICE_MISSING_ID") error = JANICE_MISSING_ID;
else if (error_str == "JANICE_MISSING_FILE_NAME") error = JANICE_MISSING_FILE_NAME;
else if (error_str == "JANICE_INCORRECT_ROLE") error = JANICE_INCORRECT_ROLE;
else if (error_str == "JANICE_FAILURE_TO_SERIALIZE") error = JANICE_FAILURE_TO_SERIALIZE;
else if (error_str == "JANICE_FAILURE_TO_DESERIALIZE") error = JANICE_FAILURE_TO_DESERIALIZE;
else if (error_str == "JANICE_BATCH_ABORTED_EARLY") error = JANICE_BATCH_ABORTED_EARLY;
else if (error_str == "JANICE_BATCH_FINISHED_WITH_ERRORS") error = JANICE_BATCH_FINISHED_WITH_ERRORS;
else if (error_str == "JANICE_CALLBACK_EXIT_IMMEDIATELY") error = JANICE_CALLBACK_EXIT_IMMEDIATELY;
else if (error_str == "JANICE_NOT_IMPLEMENTED") error = JANICE_NOT_IMPLEMENTED;
else {
throw std::runtime_error("Unknown error string: " + error_str);
bool found = false;
for (int err = (int)JANICE_SUCCESS; err < (int)JANICE_NUM_ERRORS; ++err) {
if (error_str == janice_error_strings[err]) {
ignored_errors.insert((JaniceError)err);
found = true;
break;
}
}
if (! found) {
throw std::runtime_error("Unknown error string: " + error_str);
}

ignored_errors.insert(error);
}
}

Expand Down
5 changes: 4 additions & 1 deletion harness/janice_cluster_media.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#include <arg_parser/args.hpp>
#include <fast-cpp-csv-parser/csv.h>
#include <boost/filesystem.hpp>

#include <iostream>
#include <fstream>
Expand Down Expand Up @@ -95,7 +96,9 @@ int main(int argc, char* argv[])
media.length = filenames.size();
media.media = new JaniceMediaIterator[media.length];
for (size_t i=0; i < media.length; i++) {
JANICE_ASSERT(janice_io_opencv_create_media_iterator(std::string(args::get(media_path) + "/" + filenames[i]).c_str(), &media.media[i]), ignored_errors);
boost::filesystem::path filename(args::get(media_path));
filename /= filenames[i];
JANICE_ASSERT(janice_io_opencv_create_media_iterator(filename.string().c_str(), &media.media[i]), ignored_errors);
}

JaniceClusterIdsGroup cluster_ids;
Expand Down
5 changes: 4 additions & 1 deletion harness/janice_create_gallery.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#include <arg_parser/args.hpp>
#include <fast-cpp-csv-parser/csv.h>
#include <boost/filesystem.hpp>

#include <iostream>
#include <chrono>
Expand Down Expand Up @@ -74,7 +75,9 @@ int main(int argc, char* argv[])
{
int template_id;
while (metadata.read_row(template_id)) {
filenames.push_back(args::get(template_path) + "/" + std::to_string(template_id) + ".tmpl");
boost::filesystem::path template_file(args::get(template_path));
template_file /= (std::to_string(template_id) + ".tmpl");
filenames.push_back(template_file.string());
template_ids.push_back(template_id);
}
}
Expand Down
5 changes: 4 additions & 1 deletion harness/janice_detect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#include <arg_parser/args.hpp>
#include <fast-cpp-csv-parser/csv.h>
#include <boost/filesystem.hpp>

#include <iostream>
#include <chrono>
Expand Down Expand Up @@ -89,7 +90,9 @@ int main(int argc, char* argv[])
std::string filename;
while (metadata.read_row(filename)) {
JaniceMediaIterator it;
JANICE_ASSERT(janice_io_opencv_create_media_iterator((args::get(media_path) + "/" + filename).c_str(), &it), ignored_errors);
boost::filesystem::path media_file(args::get(media_path));
media_file /= filename;
JANICE_ASSERT(janice_io_opencv_create_media_iterator(media_file.string().c_str(), &it), ignored_errors);

filenames.push_back(filename);
media.push_back(it);
Expand Down
11 changes: 7 additions & 4 deletions harness/janice_enroll_detections.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#include <arg_parser/args.hpp>
#include <fast-cpp-csv-parser/csv.h>
#include <boost/filesystem.hpp>

#include <unordered_map>
#include <iostream>
Expand Down Expand Up @@ -102,7 +103,9 @@ int main(int argc, char* argv[])
JaniceRect rect;

while (metadata.read_row(filename, template_id, subject_id, sighting_id, rect.x, rect.y, rect.width, rect.height)) {
template_id_metadata_lut[template_id][sighting_id].push_back(std::make_pair(args::get(media_path) + "/" + filename, rect));
boost::filesystem::path input_file(args::get(media_path));
input_file /= filename;
template_id_metadata_lut[template_id][sighting_id].push_back(std::make_pair(input_file.string(), rect));
template_id_subject_id_lut[template_id] = subject_id;
}
}
Expand Down Expand Up @@ -234,9 +237,9 @@ int main(int argc, char* argv[])
JANICE_ASSERT(janice_serialize_template(tmpls.tmpls[tmpl_idx], &buffer, &tmpl_size), ignored_errors);
JANICE_ASSERT(janice_free_buffer(&buffer), ignored_errors);
}

std::string tmpl_file = args::get(dst_path) + "/" + std::to_string(batch_template_ids[tmpl_idx]) + ".tmpl";
JANICE_ASSERT(janice_write_template(tmpls.tmpls[tmpl_idx], tmpl_file.c_str()), ignored_errors);
boost::filesystem::path tmpl_file(args::get(dst_path));
tmpl_file /= (std::to_string(batch_template_ids[tmpl_idx]) + ".tmpl");
JANICE_ASSERT(janice_write_template(tmpls.tmpls[tmpl_idx], tmpl_file.string().c_str()), ignored_errors);

fprintf(output, "%llu,%d,%d,0,%d,%f,%zu\n", batch_template_ids[tmpl_idx], template_id_subject_id_lut[batch_template_ids[tmpl_idx]], context.role, batch_idx, elapsed, tmpl_size);
}
Expand Down
Loading