Skip to content

Commit

Permalink
add gtkcomboboxhelper functions, some opetions were changed from int-…
Browse files Browse the repository at this point in the history
…index to string-value type, to have more robust way to transmit request between client and server
  • Loading branch information
w0lek committed Nov 29, 2023
1 parent 22bbf9c commit c0fa676
Show file tree
Hide file tree
Showing 7 changed files with 85 additions and 17 deletions.
39 changes: 39 additions & 0 deletions vpr/src/server/gtkcomboboxhelper.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#include "gtkcomboboxhelper.h"
#include <gtk/gtk.h>

gint get_item_count(gpointer combo_box) {
GtkComboBoxText* combo = GTK_COMBO_BOX_TEXT(combo_box);

// Get the model of the combo box
GtkTreeModel* model = gtk_combo_box_get_model(GTK_COMBO_BOX(combo));

// Get the number of items (indexes) in the combo box
gint count = gtk_tree_model_iter_n_children(model, NULL);
return count;
}

gint get_item_index_by_text(gpointer combo_box, gchar* target_item) {
gint result_index = -1;
GtkComboBoxText* combo = GTK_COMBO_BOX_TEXT(combo_box);

// Get the model of the combo box
GtkTreeModel* model = gtk_combo_box_get_model(GTK_COMBO_BOX(combo));

gchar* current_item_text = nullptr;

for (gint index=0; index<get_item_count(combo_box); ++index) {
GtkTreeIter iter;

// Check if the index is within bounds
if (gtk_tree_model_iter_nth_child(model, &iter, NULL, index)) {
gtk_tree_model_get(model, &iter, 0, &current_item_text, -1);
if (g_strcmp0(target_item, current_item_text) == 0) {
result_index = index;
break;
}
}
}

g_free(current_item_text);
return result_index;
}
10 changes: 10 additions & 0 deletions vpr/src/server/gtkcomboboxhelper.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#ifndef GTKCOMBOBOXHELPER_H
#define GTKCOMBOBOXHELPER_H

#include <glib.h>

gint get_item_count(gpointer combo_box);

gint get_item_index_by_text(gpointer combo_box, gchar* target_item);

#endif // GTKCOMBOBOXHELPER_H
16 changes: 14 additions & 2 deletions vpr/src/server/pathhelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#include <sstream>
#include <cassert>

std::string getPathsStr(const std::vector<tatum::TimingPath>& paths, int detailesLevel, bool is_flat_routing)
std::string getPathsStr(const std::vector<tatum::TimingPath>& paths, const std::string& detailsLevel, bool is_flat_routing)
{
// shortcuts
auto& atom_ctx = g_vpr_ctx.atom();
Expand All @@ -22,7 +22,19 @@ std::string getPathsStr(const std::vector<tatum::TimingPath>& paths, int detaile
auto analysis_delay_calc = std::make_shared<AnalysisDelayCalculator>(atom_ctx.nlist, atom_ctx.lookup, net_delay, is_flat_routing);

VprTimingGraphResolver resolver(atom_ctx.nlist, atom_ctx.lookup, *timing_ctx.graph, *analysis_delay_calc.get(), is_flat_routing);
resolver.set_detail_level(static_cast<e_timing_report_detail>(detailesLevel));
e_timing_report_detail detailesLevelEnum = e_timing_report_detail::NETLIST;
if (detailsLevel == "netlist") {
detailesLevelEnum = e_timing_report_detail::NETLIST;
} else if (detailsLevel == "aggregated") {
detailesLevelEnum = e_timing_report_detail::AGGREGATED;
} else if (detailsLevel == "detailed") {
detailesLevelEnum = e_timing_report_detail::DETAILED_ROUTING;
} else if (detailsLevel == "debug") {
detailesLevelEnum = e_timing_report_detail::DEBUG;
} else {
std::cerr << "unhandled option" << detailsLevel << std::endl;
}
resolver.set_detail_level(detailesLevelEnum);
//

std::stringstream ss;
Expand Down
2 changes: 1 addition & 1 deletion vpr/src/server/pathhelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

#include "tatum/report/TimingPath.hpp"

std::string getPathsStr(const std::vector<tatum::TimingPath>& paths, int detailesLevel, bool is_flat_routing);
std::string getPathsStr(const std::vector<tatum::TimingPath>& paths, const std::string& detailesLevel, bool is_flat_routing);
void calcCritPath(int numMax, const std::string& type);

#endif
2 changes: 1 addition & 1 deletion vpr/src/server/task.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class Task {
bool isFinished() const { return m_isFinished; }
bool hasError() const { return m_hasError; }

void error(const std::string& error) {
void fail(const std::string& error) {
std::cout << "task " << info() << " finished with error " << error << std::endl;
m_result = error;
m_isFinished = true;
Expand Down
31 changes: 19 additions & 12 deletions vpr/src/server/taskresolver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#include "pathhelper.h"
#include "telegramoptions.h"
#include "telegramparser.h"
#include <gtk/gtk.h>
#include "gtkcomboboxhelper.h"
#include <ezgl/application.hpp>
#endif

Expand All @@ -30,11 +30,11 @@ void TaskResolver::addTask(Task task)
if (t.cmd() == task.cmd()) {
if (t.options() == task.options()) {
std::string msg = "similar task is already in execution, reject new task: " + t.info()+ " and waiting for old task: " + task.info() + " execution";
task.error(msg);
task.fail(msg);
} else {
if (task.jobId() > t.jobId()) {
std::string msg = "old task: " + t.info() + " is overriden by a new task: " + task.info();
t.error(msg);
t.fail(msg);
}
}
}
Expand Down Expand Up @@ -78,7 +78,7 @@ void TaskResolver::update(ezgl::application* app)
options.validateNamePresence({OPTION_PATH_NUM, OPTION_PATH_TYPE, OPTION_DETAILS_LEVEL, OPTION_IS_FLOAT_ROUTING});
int nCriticalPathNum = options.getInt(OPTION_PATH_NUM, 1);
std::string typePath = options.getString(OPTION_PATH_TYPE);
int detailsLevel = options.getInt(OPTION_DETAILS_LEVEL, 0);
std::string detailsLevel = options.getString(OPTION_DETAILS_LEVEL);
bool isFlat = options.getBool(OPTION_IS_FLOAT_ROUTING, false);
if (!options.hasErrors()) {
calcCritPath(nCriticalPathNum, typePath);
Expand All @@ -91,29 +91,36 @@ void TaskResolver::update(ezgl::application* app)
} else {
std::string msg = "options errors in get crit path list telegram: " + options.errorsStr();
std::cerr << msg << std::endl;
task.error(msg);
task.fail(msg);
}
} else if (task.cmd() == CMD_DRAW_PATH_ID) {
options.validateNamePresence({OPTION_PATH_INDEX, OPTION_HIGHTLIGHT_MODE});
int pathIndex = options.getInt(OPTION_PATH_INDEX, -1);
int highLightMode = options.getInt(OPTION_HIGHTLIGHT_MODE, 1);
std::string highLightMode = options.getString(OPTION_HIGHTLIGHT_MODE);
if (!options.hasErrors()) {
if ((pathIndex >= 0) && (pathIndex < g_vpr_ctx.crit_paths.size())) {
g_vpr_ctx.crit_path_index = pathIndex;

// update gtk UI
GtkComboBox* toggle_crit_path = GTK_COMBO_BOX(app->get_object("ToggleCritPath"));
gtk_combo_box_set_active(toggle_crit_path, highLightMode);

task.success();
gint highLightModeIndex = get_item_index_by_text(toggle_crit_path, highLightMode.data());
if (highLightModeIndex != -1) {
gtk_combo_box_set_active(toggle_crit_path, highLightModeIndex);
task.success();
} else {
std::string msg{"cannot find ToggleCritPath qcombobox index for item " + highLightMode};
std::cerr << msg << std::endl;
task.fail(msg);
}
} else {
std::string msg = "selectedIndex=" + std::to_string(pathIndex) + " is out of range [0-" + std::to_string(g_vpr_ctx.crit_paths.size()-1) + "]";
task.error(msg);
std::cerr << msg << std::endl;
task.fail(msg);
}
} else {
std::string msg = "options errors in highlight crit path telegram: " + options.errorsStr();
std::string msg{"options errors in highlight crit path telegram: " + options.errorsStr()};
std::cerr << msg << std::endl;
task.error(msg);
task.fail(msg);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion vpr/src/server/taskresolver.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#ifndef STANDALONE_APP
namespace ezgl {
class application;
};
}
#endif

class TaskResolver {
Expand Down

0 comments on commit c0fa676

Please sign in to comment.