aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/allocate_queue.cpp31
-rw-r--r--src/allocate_queue.hpp49
-rw-r--r--src/app.cpp90
-rw-r--r--src/app.hpp16
-rw-r--r--src/main.cpp16
-rw-r--r--src/windowmanager-client.cpp8
-rw-r--r--src/windowmanager-client.hpp8
7 files changed, 146 insertions, 72 deletions
diff --git a/src/allocate_queue.cpp b/src/allocate_queue.cpp
index 0d7a646..14bf6f5 100644
--- a/src/allocate_queue.cpp
+++ b/src/allocate_queue.cpp
@@ -17,8 +17,11 @@
#include "allocate_queue.hpp"
#include <algorithm>
+using std::string;
+
namespace wm {
+
AllocateRequestList::AllocateRequestList(){}
AllocateRequestList::~AllocateRequestList(){}
@@ -26,22 +29,19 @@ bool AllocateRequestList::addClient(WMClient* client){
return true;
}
-void AllocateRequestList::removeClient(const char* appid){
- return true;
+void AllocateRequestList::removeClient(const string &appid){
}
-const WMClient* AllocateRequestList::lookUpClient(const char appid){
- std::string key = std::string(appid);
- auto itr = client_list.find(appid);
- return (itr != client_list.end()) ? itr.second() : nullptr;
+WMClient* AllocateRequestList::lookUpClient(const string &appid){
+ return nullptr;
}
-unsigned AllocateRequestList::getSequenceNumber(appid, role, area){
+unsigned AllocateRequestList::getSequenceNumber(const string &appid, const string &role, const string &area){
return 0;
}
-bool AllocateRequestList::addAllocateRequest(WMClient &client, unsigned seq_num, std::string &task){
- return true;
+unsigned AllocateRequestList::addAllocateRequest(WMRequest req){
+ return 1;
}
bool AllocateRequestList::requestFinished(){
@@ -52,8 +52,12 @@ unsigned AllocateRequestList::lookUpAllocatingApp(const char *appid){
return 1;
}
-unsigned AllocateRequestList::currentSequnce(const char *appid){
- return 1;
+void AllocateRequestList::setEndDrawFinished(unsigned request_seq, const string &role){
+
+}
+
+bool AllocateRequestList::endDrawFullfilled(unsigned request_seq){
+ return false;
}
void AllocateRequestList::removeRequest(unsigned req_seq){
@@ -61,7 +65,10 @@ void AllocateRequestList::removeRequest(unsigned req_seq){
}
void AllocateRequestList::setCurrentSequence(unsigned req_seq){
-
+ this->seq_num = req_seq;
+ if(0 == this->seq_num){
+ this->seq_num = 1;
+ }
}
bool AllocateRequestList::haveRequest(){
diff --git a/src/allocate_queue.hpp b/src/allocate_queue.hpp
index df57370..7b36bfe 100644
--- a/src/allocate_queue.hpp
+++ b/src/allocate_queue.hpp
@@ -17,32 +17,54 @@
#ifndef ALLOCATE_LIST_HPP
#define ALLOCATE_LIST_HPP
#include <vector>
+#include <string>
+#include <map>
#include "windowmanager-client.hpp"
namespace wm {
+typedef enum Task{
+ TASK_ALLOCATE,
+ TASK_RELEASE
+}ResourceTask;
+
+struct WMRequest{
+ explicit WMRequest(std::string appid, std::string role,
+ std::string area, ResourceTask task);
+ virtual ~WMRequest();
+ WMRequest(const WMRequest &obj);
+
+ std::string appid;
+ std::string role;
+ std::string area;
+ Task task;
+ unsigned seq_num;
+ bool end_draw_finished;
+ bool allocating;
+};
+
class AllocateRequestList {
public:
AllocateRequestList();
- ~AllocateRequestList();
+ virtual ~AllocateRequestList();
AllocateRequestList(const AllocateRequestList &obj) = delete;
- typedef std::function<void(const WMClient *)> onEndDraw;
- typedef std::function<void(const WMClient *)> onReverted;
-
// Client Database Interface
- bool addClient(WMClient &client);
- bool removeClient(const char* appid);
- const WMClient* loopUpClient(const char* appid);
+ bool addClient(WMClient *client);
+ void removeClient(const std::string &appid);
+ WMClient* lookUpClient(const std::string &appid);
// Request Interface
- unsigned currentSequnceNumber();
- unsigned getSequenceNumber(appid, role, area);
- bool addAllocateRequest(WMClient &client, unsigned seq_num, std::string &task);
+ unsigned currentSequenceNumber();
+ unsigned getSequenceNumber(const std::string &appid, const std::string &role, const std::string &area);
+ unsigned addAllocateRequest(WMRequest req);
+ /* TODO: consider, which is better WMClient or std::string appid?
+ if appid is key to manage resources, it is better to select std::string
+ otherwise WMClient is better, IMO */
bool requestFinished();
unsigned lookUpAllocatingApp(const char *appid);
- unsigned currentSequence();
void setEndDrawFinished(unsigned request_seq, const std::string &role);
+ bool endDrawFullfilled(unsigned request_seq);
void removeRequest(unsigned request_seq);
void setCurrentSequence(unsigned request_seq);
bool haveRequest();
@@ -59,8 +81,9 @@ public:
bool hasElement(int request_num); */
private:
- std::vector<WMClient *> requestQueue;
-
+ std::vector<WMRequest> req_list;
+ std::map<std::string, WMClient> client_list;
+ unsigned seq_num;
};
}
diff --git a/src/app.cpp b/src/app.cpp
index 8038f4c..ce41827 100644
--- a/src/app.cpp
+++ b/src/app.cpp
@@ -38,6 +38,10 @@
#include "windowmanager-client.hpp"
#include "allocate_queue.hpp"
+extern "C" {
+ #include <systemd/sd-event.h>
+}
+
#define TIME_OUT 1000000UL /* 1s */
namespace wm {
@@ -62,8 +66,9 @@ const char kKeyHeightPixel[] = "height_pixel";
const char kKeyWidthMm[] = "width_mm";
const char kKeyHeightMm[] = "height_mm";
-static const std::string task_allocate = "allocate"
-static const std::string task_release = "release"
+static const std::string task_allocate = "allocate";
+static const std::string task_release = "release";
+static sd_event_source *timer_ev_src = nullptr;
static AllocateRequestList allocate_list;
@@ -97,17 +102,19 @@ struct result<layer_map> load_layer_map(char const *filename) {
return to_layer_map(jids);
}
-} // namespace
-static int App::processTimerHandler(sd_event_source *s, uint64_t usec, void *userdata){
- HMI_NOTICE("Time out occurs because the client replys endDraw slow, so revert the request");
+static int processTimerHandler(sd_event_source *s, uint64_t usec, void *userdata){
+ HMI_NOTICE("wm", "Time out occurs because the client replys endDraw slow, so revert the request");
reinterpret_cast<wm::App *>(userdata)->timerHandler();
+ return 0;
}
+} // namespace
+
void App::timerHandler(){
// TODO: write reset process
- unsigned seq = allocate_list.curerntSequenceNumber();
- allocate_list.resetRequest(seq);
+ unsigned seq = allocate_list.currentSequenceNumber();
+ allocate_list.removeRequest(seq);
}
/**
@@ -355,21 +362,24 @@ void App::do_allocate_window_resource(unsigned sequence_number){
do {
// TODO: Tasks will be changed according to policy manager result
// do task(onTransition (activate))
- }while (!allocate_list.requestFinished())
+ }while (!allocate_list.requestFinished());
// lm_.updateLayout(jobj);
// TODO: emit syncDraw with application
do{
- client->emit_syncdraw(role);
+ //client->emit_syncdraw(role);
}while (!allocate_list.requestFinished());
- // is this needed?
+ // is the below necessary?
//allocate_list.setAllocated(sequence_number);
if(timer_ev_src != nullptr){
// firsttime set into sd_event
int ret = sd_event_add_time(afb_daemon_get_event_loop(), &timer_ev_src,
CLOCK_BOOTTIME, time(NULL) + TIME_OUT, 0, processTimerHandler, this);
+ if(ret < 0){
+ HMI_ERROR("wm", "Can't set timer");
+ }
}
else{
// update timer limitation after second time
@@ -386,12 +396,13 @@ void App::api_activate_surface(char const *appid, char const *drawing_name, char
*/
auto const &surface_id = this->lookup_id(drawing_name);
- std::string role = std::string(drawing_name);
- std::string area = std::string(drawing_area);
+ std::string id = appid;
+ std::string role = drawing_name;
+ std::string area = drawing_area;
- const WMClient* client = allocate_list.loopUpClient(appid);
+ WMClient* client = allocate_list.lookUpClient(id);
if(!client){
- reply("%d doesn't request 'requestSurface' yet", appid);
+ reply("app doesn't request 'requestSurface' yet");
return;
}
@@ -415,21 +426,22 @@ void App::api_activate_surface(char const *appid, char const *drawing_name, char
/*
* Queueing Phase
*/
- unsigned current = allocate_list.curerntSequenceNumber();
- unsigned requested_num = getSequenceNumber(appid, role, area);
+ unsigned current = allocate_list.currentSequenceNumber();
+ unsigned requested_num = allocate_list.getSequenceNumber(id, role, area);
if(requested_num != 0){
- HMI_SEQ_INFO(requested_num, "%s %s %s request is already queued", appid, role, area);
+ HMI_SEQ_INFO(requested_num, "%s %s %s request is already queued", id.c_str(), role.c_str(), area.c_str());
reply("already requested");
return;
}
- static unsigned ++sequence_number;
- HMI_SEQ_DEBUG(sequence_number, "%s start sequence with %s, %s", appid, role, area);
+ WMRequest req = WMRequest(id, role, area, Task::TASK_ALLOCATE);
+ unsigned new_req = allocate_list.addAllocateRequest(req);
- if(sequence_number != current){
+ HMI_SEQ_DEBUG(new_req, "%s start sequence with %s, %s", id.c_str(), role.c_str(), area.c_str());
+
+ if(new_req != current){
// Add request, then invoked after the previous task is finished
- allocate_list.addAllocateRequest(client, sequence_number, task_allocate);
- HMI_SEQ_DEBUG(sequence_number, "request is accepted");
+ HMI_SEQ_DEBUG(new_req, "request is accepted");
reply(nullptr);
return;
}
@@ -437,7 +449,7 @@ void App::api_activate_surface(char const *appid, char const *drawing_name, char
/*
* Do allocate tasks
*/
- this->do_allocate_window_resource(sequence_number);
+ this->do_allocate_window_resource(new_req);
if (!surface_id)
{
@@ -591,7 +603,13 @@ void App::api_activate_surface(char const *appid, char const *drawing_name, char
void App::api_deactivate_surface(char const *appid, char const *drawing_name, const reply_func &reply) {
ST();
auto const &surface_id = this->lookup_id(drawing_name);
- WMClient* client = allocate_list.lookupClient(appid);
+
+ std::string id = appid;
+ WMClient* client = allocate_list.lookUpClient(id);
+
+ if(!client){
+ HMI_ERROR("wm", "client %s is not registered", appid);
+ }
if (!surface_id) {
reply ("Surface does not exist");
@@ -706,12 +724,16 @@ void App::do_enddraw(unsigned sequence_number){
}while(!allocate_list.requestFinished());
}
+void App::process_request(){
+
+}
+
void App::api_enddraw(char const *appid, char const *drawing_name) {
unsigned request_seq = allocate_list.lookUpAllocatingApp(appid);
- unsigned current_seq = allocate_list.currentSequence();
+ unsigned current_seq = allocate_list.currentSequenceNumber();
if(current_seq != request_seq){
if(request_seq == 0){
- HMI_ERROR("You don't have Window Resource");
+ HMI_ERROR("wm", "You don't have Window Resource");
}
else{
HMI_ERROR("wm", "unknown error. Application may not obey the sequence manner. please call endDraw after syncDraw");
@@ -720,7 +742,7 @@ void App::api_enddraw(char const *appid, char const *drawing_name) {
}
std::string role = drawing_name;
- std::string area = drawing_area;
+ //std::string area = drawing_area;
allocate_list.setEndDrawFinished(request_seq, role);
if(allocate_list.endDrawFullfilled(request_seq)){
@@ -818,7 +840,12 @@ void App::surface_removed(uint32_t surface_id) {
} else {
auto drawing_name = this->lookup_name(surface_id);
if (drawing_name) {
- this->api_deactivate_surface(drawing_name->c_str(), [](const char*){});
+ std::string appid = "";
+ /* const WMClient *client = lookUpClient(surface_id);
+ appid = client->appID();
+
+ */
+ this->api_deactivate_surface(appid.c_str(), drawing_name->c_str(), [](const char*){});
}
}
@@ -852,7 +879,7 @@ void App::emit_invisible(char const *label) {
void App::emit_visible(char const *label) { return emit_visible(label, true); }
-result<int> App::api_request_surface(char const *drawing_name, char const * appid, int flag) {
+result<int> App::api_request_surface(char const * appid, char const *drawing_name) {
auto lid = this->layers.get_layer_id(std::string(drawing_name));
if (!lid) {
/**
@@ -889,7 +916,7 @@ result<int> App::api_request_surface(char const *drawing_name, char const * appi
return Err<int>("Surface already present");
}
-char const *App::api_request_surface(char const *drawing_name,
+char const *App::api_request_surface(char const *appid, char const *drawing_name,
char const *ivi_id) {
ST();
@@ -1063,7 +1090,8 @@ void App::deactivate(int id) {
void App::deactivate_main_surface() {
this->layers.main_surface = -1;
- this->api_deactivate_surface(this->layers.main_surface_name.c_str(), [](const char*){});
+ std::string appid = "HomeScreen";
+ this->api_deactivate_surface(appid.c_str(), this->layers.main_surface_name.c_str(), [](const char*){});
}
bool App::can_split(struct LayoutState const &state, int new_id) {
diff --git a/src/app.hpp b/src/app.hpp
index e7a9ae0..b25f568 100644
--- a/src/app.hpp
+++ b/src/app.hpp
@@ -201,11 +201,11 @@ struct App {
void set_pending_events();
- result<int> api_request_surface(char const *drawing_name, char const *appid, int flag);
- char const *api_request_surface(char const *drawing_name, char const *ivi_id);
+ result<int> api_request_surface(char const *appid, char const *drawing_name);
+ char const *api_request_surface(char const *appid, char const *drawing_name, char const *ivi_id);
void api_activate_surface(char const *appid, char const *drawing_name, char const *drawing_area, const reply_func &reply);
- void api_deactivate_surface(char const *drawing_name, const reply_func &reply);
- void api_enddraw(char const *drawing_name);
+ void api_deactivate_surface(char const *appid, char const *drawing_name, const reply_func &reply);
+ void api_enddraw(char const *appid, char const *drawing_name);
result<json_object *> api_get_display_info();
result<json_object *> api_get_area_info(char const *drawing_name);
void api_ping();
@@ -217,7 +217,8 @@ struct App {
void surface_removed(uint32_t surface_id);
// Do not use this function
- static int processTimerHandler(sd_event_source *s, uint64_t usec, void *userdata);
+ //static int processTimerHandler(sd_event_source *s, uint64_t usec, void *userdata);
+ void timerHandler();
private:
optional<int> lookup_id(char const *name);
@@ -229,7 +230,6 @@ struct App {
void check_flushdraw(int surface_id);
int init_layers();
- void timerHandler();
void surface_set_layout(int surface_id, optional<int> sub_surface_id = nullopt);
void layout_commit();
@@ -243,6 +243,10 @@ struct App {
void emit_invisible(char const *label);
void emit_visible(char const *label);
+ void do_allocate_window_resource(unsigned sequence_number);
+ void do_enddraw(unsigned sequence_number);
+ void process_request();
+
void activate(int id);
void deactivate(int id);
void deactivate_main_surface();
diff --git a/src/main.cpp b/src/main.cpp
index bd591a4..4954abf 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -209,7 +209,8 @@ void windowmanager_requestsurface(afb_req req) noexcept {
}
}
- auto ret = g_afb_instance->app.api_request_surface(a_drawing_name, afb_req_get_application_id(req), 0);
+ auto ret = g_afb_instance->app.api_request_surface(
+ afb_req_get_application_id(req), a_drawing_name);
if(isFirstReq){
wmClientCtxt* ctxt = new wmClientCtxt(a_drawing_name);
@@ -262,7 +263,8 @@ void windowmanager_requestsurfacexdg(afb_req req) noexcept {
}
char const* a_ivi_id = json_object_get_string(j_ivi_id);
- auto ret = g_afb_instance->app.api_request_surface(a_drawing_name, a_ivi_id);
+ auto ret = g_afb_instance->app.api_request_surface(
+ afb_req_get_application_id(req), a_drawing_name, a_ivi_id);
if (ret != nullptr) {
afb_req_fail(req, "failed", ret);
return;
@@ -298,7 +300,9 @@ void windowmanager_activatesurface(afb_req req) noexcept {
return;
}
- g_afb_instance->app.api_activate_surface(a_drawing_name, a_drawing_area,
+ g_afb_instance->app.api_activate_surface(
+ afb_req_get_application_id(req),
+ a_drawing_name, a_drawing_area,
[&req](const char* errmsg){
if (errmsg != nullptr) {
HMI_ERROR("wm", errmsg);
@@ -332,7 +336,8 @@ void windowmanager_deactivatesurface(afb_req req) noexcept {
return;
}
- g_afb_instance->app.api_deactivate_surface(a_drawing_name,
+ g_afb_instance->app.api_deactivate_surface(
+ afb_req_get_application_id(req), a_drawing_name,
[&req](const char* errmsg){
if (errmsg != nullptr) {
HMI_ERROR("wm", errmsg);
@@ -366,7 +371,8 @@ void windowmanager_enddraw(afb_req req) noexcept {
}
afb_req_success(req, NULL, "success");
- g_afb_instance->app.api_enddraw(a_drawing_name);
+ g_afb_instance->app.api_enddraw(
+ afb_req_get_application_id(req), a_drawing_name);
} catch (std::exception &e) {
HMI_WARNING("wm", "failed", "Uncaught exception while calling enddraw: %s", e.what());
diff --git a/src/windowmanager-client.cpp b/src/windowmanager-client.cpp
index ee6164a..512f271 100644
--- a/src/windowmanager-client.cpp
+++ b/src/windowmanager-client.cpp
@@ -28,4 +28,12 @@ WMClient::WMClient(const char* appid, unsigned layerID, unsigned surfaceID, cons
}
+/* const std::vector<optional<unsigned>> surfaceIDList(){
+
+}
+
+std::optional<unsigned> surfaceID(role);
+
+} */
+
} \ No newline at end of file
diff --git a/src/windowmanager-client.hpp b/src/windowmanager-client.hpp
index bf0a9d7..441dc77 100644
--- a/src/windowmanager-client.hpp
+++ b/src/windowmanager-client.hpp
@@ -33,10 +33,8 @@ public:
WMClient(const char* appid, unsigned layerID, unsigned surfaceID, const char* role);
virtual ~WMClient();
//WMClient::WMClient(const WMClient &obj);
- const vector<optional<unsigned>> surfaceIDList();
- optional<unsigned> surfaceID(role);
- bool hasRequestingApp(appid);
- void createNewRequest(int count, const vector<std::string> &applist);
+ /* const std::vector<optional<unsigned>> surfaceIDList();
+ optional<unsigned> surfaceID(role); */
private:
unsigned layer;
@@ -45,7 +43,7 @@ public:
std::vector<std::string> roles;
std::unordered_map<std::string, struct afb_event> event_list;
unsigned request_number;
- std::vector<Task *> requestingTask;
+ //std::vector<Task *> requestingTask;
};
}