4
* Copyright 2010 Eric Day
6
* Licensed under the Apache License, Version 2.0 (the "License");
7
* you may not use this file except in compliance with the License.
8
* You may obtain a copy of the License at
10
* http://www.apache.org/licenses/LICENSE-2.0
12
* Unless required by applicable law or agreed to in writing, software
13
* distributed under the License is distributed on an "AS IS" BASIS,
14
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
* See the License for the specific language governing permissions and
16
* limitations under the License.
21
* @brief Notification Definitions
31
#include <scalestack/common/exception.h>
32
#include <scalestack/common/notification.h>
43
notification::notification(void)
45
if (pipe(_pipe) == -1)
46
_throw_exception(_("Could not create notification pipe"));
49
notification::~notification()
55
void notification::send(void)
57
if (write(_pipe[1], "\0", 1) == -1 && errno != EINTR)
58
_throw_exception(_("Could not write to notification pipe"));
61
void notification::wait(void)
65
if (read(_pipe[0], buffer, sizeof(buffer)) == -1 && errno != EINTR)
66
_throw_exception(_("Could not read from notification pipe"));
73
void notification::_throw_exception(const char* prefix)
75
char message[SCALESTACK_MAX_MESSAGE_SIZE];
76
snprintf(message, SCALESTACK_MAX_MESSAGE_SIZE,
77
"%s: %s:%d", prefix, strerror(errno), errno);
78
throw exception("notification", message);
81
} /* namespace common */
82
} /* namespace scalestack */