Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix api error handling #68

Merged
merged 3 commits into from
Oct 7, 2022
Merged
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
12 changes: 0 additions & 12 deletions examples/example_device/ExampleDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -363,13 +363,6 @@ void ExampleDevice::setParameter(

if (fcn)
fcn(object, name, mem);
else {
fprintf(stderr,
"warning - no parameter setter for type '%s'"
", '%s' parameter will be ignored\n",
toString(type),
name);
}
}

void ExampleDevice::unsetParameter(ANARIObject o, const char *name)
Expand Down Expand Up @@ -569,11 +562,6 @@ extern "C" EXAMPLE_DEVICE_INTERFACE ANARI_DEFINE_LIBRARY_NEW_DEVICE(
return nullptr;
}

extern "C" EXAMPLE_DEVICE_INTERFACE ANARI_DEFINE_LIBRARY_INIT(example)
{
printf("...loaded example library!\n");
}

extern "C" EXAMPLE_DEVICE_INTERFACE ANARI_DEFINE_LIBRARY_GET_DEVICE_SUBTYPES(
example, library)
{
Expand Down
39 changes: 22 additions & 17 deletions libs/anari/API.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,22 +42,29 @@ using anari::LibraryImpl;
// Helper functions ///////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////

static inline LibraryImpl &libraryRef(ANARILibrary l)
static LibraryImpl &libraryRef(ANARILibrary l)
{
if (l == nullptr) {
throw std::runtime_error("null library provided");
}
return *((LibraryImpl *)l);
}

static inline DeviceImpl &deviceRef(ANARIDevice d)
static DeviceImpl &deviceRef(ANARIDevice d)
{
if (d == nullptr) {
throw std::runtime_error("null device provided");
}
return *((DeviceImpl *)d);
}

static void invokeStatusCallback(ANARIStatusCallback cb,
const void *userPtr,
const char *message,
ANARIDevice device = nullptr,
ANARIObject source = nullptr,
ANARIDataType sourceType = ANARI_UNKNOWN,
ANARIStatusSeverity severity = ANARI_SEVERITY_FATAL_ERROR,
ANARIStatusCode code = ANARI_STATUS_UNKNOWN_ERROR)
{
if (cb)
cb(userPtr, device, source, sourceType, severity, code, message);
}

///////////////////////////////////////////////////////////////////////////////
// Initialization /////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
Expand All @@ -69,7 +76,8 @@ extern "C" ANARILibrary anariLoadLibrary(const char *libraryName,
if (std::string(libraryName) == "environment") {
char *libraryFromEnv = getenv("ANARI_LIBRARY");
if (!libraryFromEnv) {
throw std::runtime_error(
invokeStatusCallback(statusCB,
statusCBUserPtr,
"'environment' library selected but ANARI_LIBRARY is not set");
}

Expand All @@ -88,13 +96,14 @@ extern "C" ANARILibrary anariLoadLibrary(const char *libraryName,
msg += libraryName;
msg += "'\nreason: ";
msg += e.what();
statusCB(statusCBUserPtr,
invokeStatusCallback(statusCB,
statusCBUserPtr,
msg.c_str(),
nullptr,
nullptr,
ANARI_LIBRARY,
ANARI_SEVERITY_ERROR,
ANARI_STATUS_INVALID_OPERATION,
msg.c_str());
ANARI_STATUS_INVALID_OPERATION);
}

return retval;
Expand Down Expand Up @@ -124,11 +133,7 @@ ANARI_CATCH_END_NORETURN()
extern "C" ANARIDevice anariNewDevice(
ANARILibrary l, const char *deviceType) ANARI_CATCH_BEGIN
{
auto &lib = libraryRef(l);
auto _d = lib.newDevice(deviceType);
if (!_d)
return nullptr;
return _d;
return libraryRef(l).newDevice(deviceType);
}
ANARI_CATCH_END(nullptr)

Expand Down
4 changes: 1 addition & 3 deletions libs/sink_device/SinkDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -309,9 +309,7 @@ static char deviceName[] = "sink";
extern "C" SINK_DEVICE_INTERFACE ANARI_DEFINE_LIBRARY_NEW_DEVICE(
sink, library, subtype)
{
if (subtype == std::string("default") || subtype == std::string("sink"))
return (ANARIDevice) new anari::sink_device::SinkDevice(library);
return nullptr;
return (ANARIDevice) new anari::sink_device::SinkDevice(library);
}

extern "C" SINK_DEVICE_INTERFACE ANARI_DEFINE_LIBRARY_INIT(sink) {}
Expand Down