/*
- * Copyright (c) 2017 Samsung Electronics Co.
+ * Copyright (c) 2017-2018 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.
namespace {
+int ASKUSER_IDLE_TIMER_SEC = 4;
+
int uiResponseToClientResponse(NResponseType response) {
int clientResponse;
std::string appId, pkgLabel;
identifyApp(creds.label, appId, pkgLabel);
+
+ ALOGD("Proper client connected");
+ stopTimer();
+
ConnectionInfo connInfo{appId, pkgLabel, creds.uid};
m_connToInfo.insert(it, std::make_pair(fd, connInfo));
}
ALOGD("Removing channel with fd " << fd);
m_connToInfo.erase(fd);
+ if (m_connToInfo.empty()) {
+ ALOGD("No more clients");
+ startTimer();
+ }
auto it = m_fdInfo.find(fd);
if (it == m_fdInfo.end()) {
return;
return ECORE_CALLBACK_CANCEL;
}
+void Logic::startTimer() {
+ if (m_timer)
+ return;
+ ALOGD("Starting timer");
+ m_timer = ecore_timer_add(ASKUSER_IDLE_TIMER_SEC, &Logic::timerHandler, this);
+ if (m_timer == nullptr)
+ ALOGE("Failed to add ecore timer");
+}
+
+void Logic::stopTimer() {
+ ALOGD("Stopping timer");
+ if (m_timer == nullptr)
+ return;
+ (void)ecore_timer_del(m_timer);
+ m_timer = nullptr;
+}
+
+Eina_Bool Logic::timerHandler(void *data) {
+ Logic *logic = static_cast<Logic*>(data);
+ if (logic->m_connToInfo.empty()) {
+ ALOGD("No connected clients to handle after timer run out. Closing...");
+ logic->stop();
+ }
+ return ECORE_CALLBACK_CANCEL;
+}
+
void Logic::prepareChannel() {
AskUser::Protocol::ServerCallbacksPtr callbacks(new AskUser::Protocol::ServerCallbacks(this));
std::unique_ptr<AskUser::Protocol::ServerChannel> channel(new AskUser::Protocol::ServerChannel(std::move(callbacks)));
/*
- * Copyright (c) 2017 Samsung Electronics Co.
+ * Copyright (c) 2017-2018 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.
#include <deque>
#include <server-channel.h>
+#include <Elementary.h>
+
#include "event/Event.h"
#include "PrivaciesSequence.h"
private:
std::string m_msg;
};
- Logic() : m_currentEvent{-1, -1} {}
+ Logic() : m_currentEvent{-1, -1}, m_timer(nullptr) {}
void init();
void run();
void stop();
// Descriptor handlers
static Eina_Bool clientChHandler(void *data, Ecore_Fd_Handler *handler);
static Eina_Bool signalHandler(void *data, Ecore_Fd_Handler *handler);
+ static Eina_Bool timerHandler(void *data);
//static Eina_Bool signalHandler(void *data, int type, void *event);
void addEvent(Protocol::ConnectionFd fd, Protocol::RequestId id, const std::vector<Privacy> &privacies);
Eina_Bool processChannel(int fd, int mask);
bool identifyClient(const std::string &label, std::string &appId, std::string &pkgId);
+
void processEvents();
void processResponse(const ConnectionInfo &conn, int clientResponse, const Policy &level);
bool isEventProcessed();
void finishCurrentRequest();
+
+ void startTimer();
+ void stopTimer();
+
void popupResponse(NResponseType response);
bool processError(EventId id, int error);
std::map<Protocol::ConnectionFd, FdInfo> m_fdInfo;
-
-
std::map<Protocol::ConnectionFd, ConnectionInfo> m_connToInfo;
std::map<EventId, PrivaciesSequence> m_eventToPrivaciesSeq;
+
+ Ecore_Timer *m_timer;
};
} // namespace Notification