#include <set>
#include <stdio.h>
#include <string.h>
+#include <sys/types.h>
#include <glib.h>
#include <unistd.h>
#include <askuser-notification/ask-user-client-channel.h>
#include <askuser-notification/ask-user-server-channel.h>
#include <askuser-notification/ask-user-types.h>
+#include <askuser-notification/connection-exception.h>
#include <privacy_privilege_manager.h>
using namespace AskUser::Protocol;
switch (c) {
case 's':
ctx.m_mode = Mode::SERVER;
- print_server_help();
break;
case 'c':
ctx.m_mode = Mode::CLIENT;
- print_client_help();
break;
case 'h':
default:
try {
ctx.initialize();
}
+ catch (const ConnectionException &e) {
+ printf("Connection exception occured during initialization: %s, exiting.\n", e.what());
+ printf("Check if the /var/run/user_ext/%u directory exists.\n", geteuid());
+ exit(EXIT_FAILURE);
+ }
+ catch (const std::exception &e) {
+ printf("Standard exception occured during initialization: %s, exiting.\n", e.what());
+ exit(EXIT_FAILURE);
+ }
catch (...) {
- printf("Unknwon exception occured, exiting.\n");
+ printf("Unknwon exception occured during initialization, exiting.\n");
exit(EXIT_FAILURE);
}
+ switch (ctx.m_mode) {
+ case Mode::SERVER:
+ print_server_help();
+ break;
+ case Mode::CLIENT:
+ print_client_help();
+ break;
+ case Mode::UNKNOWN:
+ default:
+ printf("Unknown mode\n");
+ exit(EXIT_FAILURE);
+ }
+
GMainLoop *mainloop = g_main_loop_new(nullptr, FALSE);
GIOChannel *gio_channel = g_io_channel_unix_new(0);
#include <functional>
#include <log/alog.h>
+#include <askuser-notification/connection-exception.h>
#include <askuser-notification-client.h>
int tryCatch(const std::function<int(void)> &func) {
try {
return func();
+ } catch (const Protocol::ConnectionException &e) {
+ ALOGE(e.what());
+ return ASKUSER_API_CONNECTION_ERROR;
} catch (const std::bad_alloc &e) {
ALOGE(e.what());
return ASKUSER_API_OUT_OF_MEMORY;
#include <attributes/attributes.h>
#include <askuser-notification/ask-user-client-channel.h>
+#include <askuser-notification/connection-exception.h>
#include <ask-user-config.h>
#include <message-utils.h>
void ClientChannel::init() {
Sock s(Sock::CLI_STREAM);
if (0 > s.connect(getStreamSocketPath(geteuid())))
- throw std::logic_error("Cannot connect to the server");
+ throw ConnectionException("Cannot connect to the server");
int fd = s.getFd();
m_sockets[fd] = SockDesc(std::move(s));
#include <sstream>
#include <askuser-notification/ask-user-server-channel.h>
+#include <askuser-notification/connection-exception.h>
#include <ask-user-config.h>
#include <message-utils.h>
void ServerChannel::init() {
Sock stream(Sock::SRV_STREAM);
- stream.connect(getStreamSocketPath(geteuid()));
+ if (0 > stream.connect(getStreamSocketPath(geteuid())))
+ throw ConnectionException("Cannot create server socket");
int fd = stream.getFd();
m_sockets[fd] = SockDesc(std::move(stream));
--- /dev/null
+/*
+ * Copyright (c) 2016 Samsung Electronics Co.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License
+ */
+/**
+ * @file connection-exception.h
+ * @author Piotr Sawicki <p.sawicki2@partner.samsung.com>
+ * @brief The declaration of ConnectionException.
+ */
+
+#pragma once
+
+#include <exception>
+#include <string>
+
+namespace AskUser {
+
+namespace Protocol {
+
+class ConnectionException : public std::exception
+{
+public:
+ ConnectionException(const std::string &msg) : m_msg(msg) {
+ }
+
+ virtual const char* what() const noexcept {
+ return m_msg.c_str();
+ }
+
+private:
+ std::string m_msg;
+};
+
+} // namespace Protocol
+
+} // namespace AskUser
+