Skip to content

Commit

Permalink
Add an extended mode to ola_uni_info showing port counts and RDM devi…
Browse files Browse the repository at this point in the history
…ce counts too
  • Loading branch information
peternewman committed Jan 14, 2020
1 parent e09ff54 commit 98704e0
Showing 1 changed file with 74 additions and 22 deletions.
96 changes: 74 additions & 22 deletions examples/ola-client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,9 @@ typedef struct {
OlaUniverse::merge_mode merge_mode; // the merge mode
string cmd; // argv[0]
string uni_name; // universe name
string dmx; // DMX string
bool blackout;
string dmx; // DMX string
bool extended;
ola::port_priority_mode priority_mode; // port priority mode
uint8_t priority_value; // port priority value
bool list_plugin_ids;
Expand Down Expand Up @@ -143,14 +144,18 @@ void ListPorts(const vector<PortClass> &ports, bool input) {
/*
* This is called when we receive universe results from the client
* @param list_ids_only show ids only
* @param extended show extended info about each universe
* @param universes a vector of OlaUniverses
*/
void DisplayUniverses(SelectServer *ss,
bool list_ids_only,
bool extended,
const Result &result,
const vector <OlaUniverse> &universes) {
vector<OlaUniverse>::const_iterator iter;

string divider = string(58 + (extended ? 41 : 0), '-');

if (!result.Success()) {
cerr << result.Error() << endl;
ss->Terminate();
Expand All @@ -162,20 +167,42 @@ void DisplayUniverses(SelectServer *ss,
cout << iter->Id() << endl;
}
} else {
cout << setw(5) << "Id" << "\t" << setw(30) << "Name" << "\t\tMerge Mode"
<< endl;
cout << "----------------------------------------------------------"
<< endl;
cout << setw(5) << "Id" << "\t" << setw(30) << "Name" << "\t";
if (extended) {
cout << setw(10);
} else {
// By default keep the double tab for backwards compatibility of anyone
// parsing the shell, not that we'd recommend that
cout << "\t";
}
cout << "Merge Mode";
if (extended) {
cout << "\t" << setw(11) << "Input Ports" << "\t" << setw(12)
<< "Output Ports" << "\t" << setw(11) << "RDM Devices";
}
cout << endl;
cout << divider << endl;

for (iter = universes.begin(); iter != universes.end(); ++iter) {
cout << setw(5) << iter->Id() << "\t" << setw(30) << iter->Name()
<< "\t\t"
<< (iter->MergeMode() == OlaUniverse::MERGE_HTP ? "HTP" : "LTP")
<< endl;
<< "\t";
if (extended) {
cout << setw(10);
} else {
// By default keep the double tab for backwards compatibility of anyone
// parsing the shell, not that we'd recommend that
cout << "\t";
}
cout << (iter->MergeMode() == OlaUniverse::MERGE_HTP ? "HTP" : "LTP");
if (extended) {
cout << "\t" << setw(11) << iter->InputPortCount() << "\t" << setw(12)
<< iter->OutputPortCount() << "\t" << setw(11)
<< iter->RDMDeviceCount();
}
cout << endl;
}

cout << "----------------------------------------------------------" <<
endl;
cout << divider << endl;
}

ss->Terminate();
Expand Down Expand Up @@ -298,14 +325,15 @@ void InitOptions(options *opts) {
opts->uni = INVALID_VALUE;
opts->plugin_id = ola::OLA_PLUGIN_ALL;
opts->help = false;
opts->blackout = false;
opts->extended = false;
opts->list_plugin_ids = false;
opts->list_universe_ids = false;
opts->patch_action = ola::client::PATCH;
opts->port_id = INVALID_VALUE;
opts->port_direction = ola::client::OUTPUT_PORT;
opts->device_id = INVALID_VALUE;
opts->merge_mode = OlaUniverse::MERGE_HTP;
opts->blackout = false;
opts->priority_mode = ola::PRIORITY_MODE_INHERIT;
opts->priority_value = 0;
}
Expand Down Expand Up @@ -359,16 +387,17 @@ void ParseOptions(int argc, char *argv[], options *opts) {
};

static struct option long_options[] = {
{"dmx", required_argument, 0, 'd'},
{"blackout", no_argument, 0, 'b'},
{"dmx", required_argument, 0, 'd'},
{"extended", no_argument, 0, 'e'},
{"help", no_argument, 0, 'h'},
{"ltp", no_argument, 0, 'l'},
{"name", required_argument, 0, 'n'},
{"plugin-id", required_argument, 0, 'p'},
{"state", required_argument, 0, 's'},
{"universe", required_argument, 0, 'u'},
{"list-plugin-ids", no_argument, 0, LIST_PLUGIN_IDS_OPTION},
{"list-universe-ids", no_argument, 0, LIST_UNIVERSE_IDS_OPTION},
{"universe", required_argument, 0, 'u'},
{0, 0, 0, 0}
};

Expand All @@ -384,11 +413,14 @@ void ParseOptions(int argc, char *argv[], options *opts) {
switch (c) {
case 0:
break;
case 'b':
opts->blackout = true;
break;
case 'd':
opts->dmx = optarg;
break;
case 'b':
opts->blackout = true;
case 'e':
opts->extended = true;
break;
case 'h':
opts->help = true;
Expand Down Expand Up @@ -620,6 +652,7 @@ void DisplayUniverseInfoHelp(const options &opts) {
"Shows info on the active universes in use.\n"
"\n"
" -h, --help Display this help message and exit.\n"
" --extended Show port counts and RDM devices too.\n"
" --list-universe-ids List universe Ids only.\n"
<< endl;
}
Expand Down Expand Up @@ -736,8 +769,8 @@ void DisplayHelpAndExit(const options &opts) {

/*
* Send a fetch device info request
* @param client the ola client
* @param opts the const options
* @param client the ola client
* @param opts the const options
*/
int FetchDeviceInfo(OlaClientWrapper *wrapper, const options &opts) {
SelectServer *ss = wrapper->GetSelectServer();
Expand Down Expand Up @@ -817,11 +850,32 @@ int FetchPluginState(OlaClientWrapper *wrapper, const options &opts) {
}


/*
* Send a fetch universe info request
* @param client the ola client
* @param opts the const options
*/
int FetchUniverseInfo(OlaClientWrapper *wrapper, const options &opts) {
SelectServer *ss = wrapper->GetSelectServer();
OlaClient *client = wrapper->GetClient();
if (opts.extended && opts.list_universe_ids) {
// These are mutually exclusive
DisplayUniverseInfoHelp(opts);
exit(1);
}

client->FetchUniverseList(NewSingleCallback(&DisplayUniverses,
ss,
opts.list_universe_ids,
opts.extended));
return 0;
}


/*
* send a set name request
* @param client the ola client
* @param opts the const options
* @param opts the const options
*/
int SetUniverseName(OlaClientWrapper *wrapper, const options &opts) {
SelectServer *ss = wrapper->GetSelectServer();
Expand All @@ -839,7 +893,7 @@ int SetUniverseName(OlaClientWrapper *wrapper, const options &opts) {
/*
* send a set name request
* @param client the ola client
* @param opts the const options
* @param opts the const options
*/
int SetUniverseMergeMode(OlaClientWrapper *wrapper,
const options &opts) {
Expand Down Expand Up @@ -960,9 +1014,7 @@ int main(int argc, char *argv[]) {
FetchPluginState(&ola_client, opts);
break;
case UNIVERSE_INFO:
ola_client.GetClient()->FetchUniverseList(
NewSingleCallback(&DisplayUniverses,
ola_client.GetSelectServer(), opts.list_universe_ids));
FetchUniverseInfo(&ola_client, opts);
break;
case UNIVERSE_NAME:
SetUniverseName(&ola_client, opts);
Expand Down

0 comments on commit 98704e0

Please sign in to comment.