Skip to content

Commit

Permalink
lib: fix default GingaOptions and add ws option
Browse files Browse the repository at this point in the history
  • Loading branch information
alanlivio committed Apr 30, 2021
1 parent 0808d3f commit 730acb5
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 31 deletions.
39 changes: 22 additions & 17 deletions lib/Formatter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,6 @@ along with Ginga. If not, see <https://www.gnu.org/licenses/>. */

GINGA_NAMESPACE_BEGIN

// Option defaults.
static GingaOptions opts_defaults = {
800, // width
600, // height
false, // debug
false, // experimental
false, // opengl
"", // background ("" == none)
};

// Option data.
typedef struct GingaOptionData
{
Expand Down Expand Up @@ -121,8 +111,12 @@ Formatter::getState ()
}

bool
Formatter::startWebServices (){
return _webservices->start();
Formatter::startWebServices ()
{
if (_opts.webservice && !_webservices->isStarted ())
return _webservices->start ();
else
return false;
}

bool
Expand All @@ -135,9 +129,9 @@ Formatter::start (const string &file, string *errmsg)
if (_state != GINGA_STATE_STOPPED)
return false;

if (!_webservices->isStarted())
this->startWebServices();
if (_opts.webservice && !_webservices->isStarted ())
this->startWebServices ();

// Parse document.
g_assert_null (_doc);
w = _opts.width;
Expand Down Expand Up @@ -448,7 +442,18 @@ Formatter::Formatter (const GingaOptions *opts) : Ginga (opts)
const char *s;

_state = GINGA_STATE_STOPPED;
_opts = (opts) ? *opts : opts_defaults;
if (opts)
_opts = *opts;
else
{
// defaults.
_opts.width = 800;
_opts.height = 600;
_opts.debug = false;
_opts.webservice = false;
_opts.opengl = false;
_opts.experimental = false;
};
_background = { 0., 0., 0., 0. };

_lastTickTotal = 0;
Expand All @@ -458,7 +463,7 @@ Formatter::Formatter (const GingaOptions *opts) : Ginga (opts)
= (s = g_getenv ("G_MESSAGES_DEBUG")) ? string (s) : "";

_doc = nullptr;
_webservices = new WebServices(this);
_webservices = new WebServices (this);
_docPath = "";
_eos = false;

Expand Down
1 change: 0 additions & 1 deletion lib/Formatter.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ class Formatter : public Ginga
explicit Formatter (const GingaOptions *);
~Formatter ();

WebServices *getWebService ();
Document *getDocument ();
bool getEOS ();
void setEOS (bool);
Expand Down
3 changes: 3 additions & 0 deletions lib/ginga.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ struct GingaOptions
/// @brief Whether to enable debug mode.
bool debug;

/// @brief Whether to enable debug mode.
bool webservice;

/// @brief Whether to enable experimental features.
bool experimental;

Expand Down
11 changes: 6 additions & 5 deletions src/ginga.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ static Ginga *GINGA = nullptr;
static gboolean opt_debug = FALSE; // toggle debug
static gboolean opt_experimental = FALSE; // toggle experimental stuff
static gboolean opt_fullscreen = FALSE; // toggle fullscreen-mode
static gboolean opt_wsonly = FALSE; // toggle webservices-only-mode
static gboolean opt_ws = FALSE; // toggle webservices-only-mode
static gboolean opt_opengl = FALSE; // toggle OpenGL backend
static string opt_background = ""; // background color
static gint opt_width = 800; // initial window width
Expand Down Expand Up @@ -101,8 +101,8 @@ static GOptionEntry options[]
"Enable debugging", NULL },
{ "fullscreen", 'f', 0, G_OPTION_ARG_NONE, &opt_fullscreen,
"Enable full-screen mode", NULL },
{ "wsonly", 'w', 0, G_OPTION_ARG_NONE, &opt_wsonly,
"Enable WebServices-only mode that start WS and ignore file arguments", NULL },
{ "ws", 'w', 0, G_OPTION_ARG_NONE, &opt_ws,
"Enable WebService and turn file param optional.", NULL },
{ "opengl", 'g', 0, G_OPTION_ARG_NONE, &opt_opengl,
"Use OpenGL backend", NULL },
{ "size", 's', 0, G_OPTION_ARG_CALLBACK, pointerof (opt_size_cb),
Expand Down Expand Up @@ -343,7 +343,7 @@ main (int argc, char **argv)
_exit (0);
}

if (!opt_wsonly && saved_argc < 2)
if (!opt_ws && saved_argc < 2)
{
usage_error ("Missing file operand");
_exit (0);
Expand Down Expand Up @@ -406,6 +406,7 @@ main (int argc, char **argv)
opts.width = opt_width;
opts.height = opt_height;
opts.debug = opt_debug;
opts.webservice = opt_ws;
opts.experimental = opt_experimental;
opts.opengl = opt_opengl;
opts.background = string (opt_background);
Expand All @@ -414,7 +415,7 @@ main (int argc, char **argv)
int fail_count = 0;

// Run only GingaCC-WebServices
if (opt_wsonly && saved_argc < 2)
if (opt_ws && saved_argc < 2)
{
GINGA->startWebServices ();
GMainLoop * main_loop = g_main_loop_new (NULL, FALSE);
Expand Down
17 changes: 9 additions & 8 deletions tests/test-Ginga-getOptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,22 @@ main (void)
{
const GingaOptions *out;
ignore_unused (out);
GingaOptions opts = {
10, // width
20, // height
false, // debug
false, // experimental
false, // opengl
"green", // background
};
GingaOptions opts;
opts.width = 10;
opts.height = 20;
opts.debug = false;
opts.experimental = false;
opts.webservice = false;
opts.opengl = false;
opts.background = "green";
Ginga *ginga = Ginga::create (&opts);
g_assert_nonnull (ginga);

out = ginga->getOptions ();
g_assert (out->width == opts.width);
g_assert (out->height == opts.height);
g_assert (out->debug == opts.debug);
g_assert (out->webservice == opts.webservice);
g_assert (out->experimental == opts.experimental);
g_assert (out->opengl == opts.opengl);
g_assert (out->background == opts.background);
Expand Down

0 comments on commit 730acb5

Please sign in to comment.