diff --git a/src/Makefile b/src/Makefile index fe3eacb..893bb75 100644 --- a/src/Makefile +++ b/src/Makefile @@ -15,7 +15,7 @@ ifneq ($(MAKECMDGOALS),clean) -include $(DEPENDS) endif -.PHONY: install uninstall clean +.PHONY: all install uninstall clean all: $(TARGET) diff --git a/src/types.cc b/src/types.cc index b2249b5..6b340fa 100644 --- a/src/types.cc +++ b/src/types.cc @@ -1,28 +1,63 @@ #include "types.hh" +#include // from libpEpAdapter /* #include #include #include */ +#include + namespace pEp { + EngineError::EngineError(PEP_STATUS status, const char* message) + : std::runtime_error( + std::string{"EngineError: "} + + (message ? '"' + std::string{message} + "\" " : std::string{} ) + + status_to_string(status) + ) + {} - template class Wrapper<::pEp_identity>; - template class Wrapper<::stringpair_t>; - - template class Wrapper<::message>; template<> template<> message* Wrapper<::message*>::_new(PEP_msg_direction dir, char* s) { message* m = new_message(dir); + if(!m) + { + throw EngineError(PEP_OUT_OF_MEMORY, "new_message()"); + } return m; } + template<> + template<> + ::stringpair_t* Wrapper<::stringpair_t*>::_new(const char* key, const char* value) + { + stringpair_t* sp = new_stringpair(key, value); + if(!sp) + { + throw EngineError(PEP_OUT_OF_MEMORY, "new_stringpair()"); + } + return sp; + } + + template<> + template<> + ::stringpair_t* Wrapper<::stringpair_t*>::_new(const std::string& key, const std::string& value) + { + return Wrapper<::stringpair_t*>::_new(key.c_str(), value.c_str()); + } + Message m(PEP_dir_incoming, "Foo"); + StringPair sp(std::string("foo"), std::string("bar")); + + template class Wrapper<::pEp_identity>; + template class Wrapper<::stringpair_t>; + template class Wrapper<::message>; + } // end of namespace pEp diff --git a/src/types.hh b/src/types.hh index b8148b4..809884e 100644 --- a/src/types.hh +++ b/src/types.hh @@ -6,12 +6,18 @@ #include "wrapper.hh" +#include #include #include #include namespace pEp { + class EngineError : std::runtime_error + { + public: + EngineError(PEP_STATUS status, const char* message = nullptr); + }; using Identity = Wrapper<::pEp_identity>; using StringPair = Wrapper<::stringpair_t>;