Proper error handling for some *NIX functions.
const char *argv0 = m_Arguments[0].c_str();
if (getcwd(Cwd, sizeof(Cwd)) == NULL)
- throw exception(/*"getcwd() failed"*/);
+ throw PosixException("getcwd failed", errno);
if (argv0[0] != '/')
snprintf(FullExePath, sizeof(FullExePath), "%s/%s", Cwd, argv0);
for (Directory = strtok(PathEnv, ":"); Directory != NULL; Directory = strtok(NULL, ":")) {
if (snprintf(PathTest, sizeof(PathTest), "%s/%s", Directory, argv0) < 0)
- throw exception(/*"snprintf() failed"*/);
+ throw PosixException("snprintf failed", errno);
if (access(PathTest, X_OK) == 0) {
strncpy(FullExePath, PathTest, sizeof(FullExePath));
free(PathEnv);
if (!FoundPath)
- throw exception(/*"Could not determine executable path."*/);
+ throw Exception("Could not determine executable path.");
}
}
if ((Buf = realpath(FullExePath, NULL)) == NULL)
- throw exception(/*"realpath() failed"*/);
+ throw PosixException("realpath failed", errno);
// remove filename
char *LastSlash = strrchr(Buf, '/');
string PosixException::FormatErrorCode(int code)
{
return strerror(code);
-}
\ No newline at end of file
+}
OnException += bind_weak(&Socket::ExceptionEventHandler, shared_from_this());
- Sockets.insert(static_pointer_cast<Socket>(shared_from_this()));
+ Sockets.push_back(static_pointer_cast<Socket>(shared_from_this()));
}
void Socket::Stop(void)
{
- Socket::Ptr self = static_pointer_cast<Socket>(shared_from_this());
- Socket::CollectionType::iterator i = Sockets.find(self);
-
- if (i != Sockets.end())
- Sockets.erase(i);
+ Sockets.remove_if(weak_ptr_eq_raw<Socket>(this));
}
void Socket::SetFD(SOCKET fd)
typedef shared_ptr<Socket> Ptr;
typedef weak_ptr<Socket> WeakPtr;
- typedef set< Socket::WeakPtr, owner_less<Socket::WeakPtr> > CollectionType;
+ typedef list<Socket::WeakPtr> CollectionType;
static Socket::CollectionType Sockets;
void Timer::Start(void)
{
- Timers.insert(static_pointer_cast<Timer>(shared_from_this()));
+ Timers.push_back(static_pointer_cast<Timer>(shared_from_this()));
Reschedule(time(NULL) + m_Interval);
}
void Timer::Stop(void)
{
- Timer::Ptr self = static_pointer_cast<Timer>(shared_from_this());
- Timer::CollectionType::iterator i = Timers.find(self);
-
- if (i != Timers.end())
- Timers.erase(i);
+ Timers.remove_if(weak_ptr_eq_raw<Timer>(this));
}
void Timer::Reschedule(time_t next)
typedef shared_ptr<Timer> Ptr;
typedef weak_ptr<Timer> WeakPtr;
- typedef set< Timer::WeakPtr, owner_less<Timer::WeakPtr> > CollectionType;
+ typedef list<Timer::WeakPtr> CollectionType;
static Timer::CollectionType Timers;
}
-#endif /* VARIANT_H */
\ No newline at end of file
+#endif /* VARIANT_H */
m_ConfigRpcEndpoint->RegisterMethodSource("config::PropertyChanged");
}
- m_ConfigRpcEndpoint->RegisterMethodHandler("message::Welcome", bind_weak(&ConfigRpcComponent::WelcomeMessageHandler, shared_from_this()));
+ m_ConfigRpcEndpoint->RegisterMethodHandler("auth::Welcome", bind_weak(&ConfigRpcComponent::WelcomeMessageHandler, shared_from_this()));
m_ConfigRpcEndpoint->RegisterMethodHandler("config::ObjectCreated", bind_weak(&ConfigRpcComponent::RemoteObjectUpdatedHandler, shared_from_this()));
m_ConfigRpcEndpoint->RegisterMethodHandler("config::ObjectRemoved", bind_weak(&ConfigRpcComponent::RemoteObjectRemovedHandler, shared_from_this()));
{
if (ea.Endpoint->HasIdentity()) {
JsonRpcRequest request;
- request.SetVersion("2.0");
request.SetMethod("config::FetchObjects");
ea.Endpoint->ProcessRequest(m_ConfigRpcEndpoint, request);
}
JsonRpcRequest ConfigRpcComponent::MakeObjectMessage(const ConfigObject::Ptr& object, string method, bool includeProperties)
{
JsonRpcRequest msg;
- msg.SetVersion("2.0");
msg.SetMethod(method);
Message params;
void AuthenticationComponent::Start(void)
{
m_AuthenticationEndpoint = make_shared<VirtualEndpoint>();
- m_AuthenticationEndpoint->RegisterMethodHandler("message::SetIdentity", bind_weak(&AuthenticationComponent::IdentityMessageHandler, shared_from_this()));
+ m_AuthenticationEndpoint->RegisterMethodHandler("auth::SetIdentity", bind_weak(&AuthenticationComponent::IdentityMessageHandler, shared_from_this()));
EndpointManager::Ptr mgr = GetIcingaApplication()->GetEndpointManager();
mgr->OnNewEndpoint += bind_weak(&AuthenticationComponent::NewEndpointHandler, shared_from_this());
return 0;
JsonRpcRequest request;
- request.SetVersion("2.0");
request.SetMethod("message::SetIdentity");
IdentityMessage params;
/* there's no authentication for now, just tell them it's ok to send messages */
JsonRpcRequest request;
- request.SetVersion("2.0");
- request.SetMethod("message::Welcome");
+ request.SetMethod("auth::Welcome");
nrea.Sender->ProcessRequest(m_AuthenticationEndpoint, request);
return 0;
return 0;
JsonRpcRequest request;
- request.SetVersion("2.0");
request.SetMethod("message::Subscribe");
SubscriptionMessage subscriptionMessage;
return 0;
JsonRpcRequest request;
- request.SetVersion("2.0");
request.SetMethod("message::Provide");
SubscriptionMessage subscriptionMessage;
cout << "Problem?" << endl;
JsonRpcRequest request;
- request.SetVersion("2.0");
request.SetMethod("test");
for (int i = 0; i < 5; i++)
m_SubscriptionEndpoint->RegisterMethodHandler("message::Provide", bind_weak(&SubscriptionComponent::ProvideMessageHandler, shared_from_this()));
m_SubscriptionEndpoint->RegisterMethodSource("message::Subscribe");
m_SubscriptionEndpoint->RegisterMethodSource("message::Provide");
- m_SubscriptionEndpoint->RegisterMethodSource("message::Welcome");
EndpointManager::Ptr mgr = GetIcingaApplication()->GetEndpointManager();
mgr->OnNewEndpoint += bind_weak(&SubscriptionComponent::NewEndpointHandler, shared_from_this());
{
public:
- JsonRpcRequest(void) : Message() { }
+ JsonRpcRequest(void) : Message() {
+ SetVersion("2.0");
+ }
+
JsonRpcRequest(const Message& message) : Message(message) { }
inline bool GetVersion(string *value) const
class I2_JSONRPC_API JsonRpcResponse : public Message
{
public:
- JsonRpcResponse(void) : Message() { }
+ JsonRpcResponse(void) : Message() {
+ SetVersion("2.0");
+ }
+
JsonRpcResponse(const Message& message) : Message(message) { }
inline bool GetVersion(string *value) const
return GetPropertyString("jsonrpc", value);
}
- inline void SetJsonRpc(const string& value)
+ inline void SetVersion(const string& value)
{
SetPropertyString("jsonrpc", value);
}
for (i = 0; i < buffer_length && isdigit(buffer[i]); i++) {
/* length specifier must have at most 9 characters */
if (i >= 9)
- return false;
+ throw InvalidArgumentException("Length specifier must not exceed 9 characters");
len = len * 10 + (buffer[i] - '0');
}