* @version 1.0
* @brief This file is implementation of client-common functions.
*/
+#include <dpl/log/log.h>
+
#include <client-common.h>
#include <message-buffer.h>
#include <protocols.h>
};
ControlShPtr Control::create() {
- return ControlShPtr(new ControlImpl());
+ try {
+ return std::make_shared<ControlImpl>();
+ } catch (const std::bad_alloc &) {
+ LogDebug("Bad alloc was caught during ControlImpl creation.");
+ } catch (...) {
+ LogError("Critical error: Unknown exception was caught druing ControlImpl creation!");
+ }
+ return ControlShPtr();
}
} // namespace CKM
}
ManagerShPtr Manager::create() {
- return ManagerShPtr(new ManagerImpl());
+ try {
+ return std::make_shared<ManagerImpl>();
+ } catch (const std::bad_alloc &) {
+ LogDebug("Bad alloc was caught during ManagerImpl creation.");
+ } catch (...) {
+ LogError("Critical error: Unknown exception was caught during ManagerImpl creation!");
+ }
+ return ManagerShPtr();
}
} // namespace CKM
}
CertificateShPtr Certificate::create(const RawBuffer &rawBuffer, DataFormat format) {
- CertificateShPtr output(new CertificateImpl(rawBuffer, format));
- if (output.get() == NULL)
- output.reset();
- return output;
+ try {
+ CertificateShPtr output = std::make_shared<CertificateImpl>(rawBuffer, format);
+ if (output->empty())
+ output.reset();
+ return output;
+ } catch (const std::bad_alloc &) {
+ LogDebug("Bad alloc was caught during CertificateImpl creation");
+ } catch (...) {
+ LogError("Critical error: Unknown exception was caught during CertificateImpl creation!");
+ }
+ return CertificateShPtr();
}
} // namespace CKM
}
KeyShPtr Key::create(const RawBuffer &raw, const Password &password) {
- KeyShPtr output(new GenericKey(raw, password));
- if (output->empty())
- output.reset();
- return output;
+ try {
+ KeyShPtr output = std::make_shared<GenericKey>(raw, password);
+ if (output->empty())
+ output.reset();
+ return output;
+ } catch (const std::bad_alloc &) {
+ LogDebug("Bad alloc was catch during GenericKey creation");
+ } catch (...) {
+ LogError("Critical error: Unknown exception was caught during GenericKey creation");
+ }
+ return KeyShPtr();
}
} // namespace CKM