Skip to content

Commit

Permalink
added version output
Browse files Browse the repository at this point in the history
Signed-off-by: Tolga Cakir <tolga@cevel.net>
  • Loading branch information
tolga9009 committed Jun 2, 2016
1 parent 63f0dc2 commit bd0ee61
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ Options:
-o <output> Output Path [default: /tmp/gchd.ts]
-p <port> Port for UDP streaming [default: 57384]
-r <resolution> Resolution of Input Source [default: 1080]
-v Print program version
-P <pid-path> PID path [default: /var/run/gchd.pid]
```
Expand Down
10 changes: 9 additions & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ void help(std::string name) {
<< " -o <output> Output Path [default: /tmp/gchd.ts]" << std::endl
<< " -p <port> Port for UDP streaming [default: " << PORT_NUM << "]" << std::endl
<< " -r <resolution> Resolution of Input Source [default: 1080]" << std::endl
<< " -v Print program version" << std::endl
<< " -P <pid-path> PID path [default: /var/run/gchd.pid]" << std::endl;
}

Expand All @@ -45,6 +46,10 @@ void usage(std::string name, std::string optarg, std::string option, const std::
std::cerr << "Try '" << name << " -h' for more information." << std::endl;
}

void version(std::string name, std::string version) {
std::cerr << name << " " << version << std::endl;
}

int main(int argc, char *argv[]) {
// object for managing runtime information
Process process;
Expand All @@ -71,7 +76,7 @@ int main(int argc, char *argv[]) {
// handling command-line options
int opt;

while ((opt = getopt(argc, argv, ":c:f:hi:n:o:p:r:P:")) != -1) {
while ((opt = getopt(argc, argv, ":c:f:hi:n:o:p:r:vP:")) != -1) {
switch (opt) {
case 'c': {
if (std::string(optarg) == "yuv") {
Expand Down Expand Up @@ -149,6 +154,9 @@ int main(int argc, char *argv[]) {
usage(process.getName(), optarg, "-r", arguments);
return EXIT_FAILURE;
}
case 'v':
version(process.getName(), process.getVersion());
return EXIT_SUCCESS;
case 'P':
pid = std::string(optarg);
break;
Expand Down
7 changes: 7 additions & 0 deletions src/process.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@

#include <process.hpp>

// constants
constexpr auto version = "0.1.0";

std::atomic<bool> Process::isActive_;

bool Process::isActive() {
Expand Down Expand Up @@ -72,6 +75,10 @@ void Process::destroyPid() {
}
}

std::string Process::getVersion() {
return version;
}

void Process::sigHandler(int sig) {
std::cerr << std::endl << "Stop signal received." << std::endl;

Expand Down
1 change: 1 addition & 0 deletions src/process.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class Process {
void setName(std::string name);
int createPid(std::string pidPath);
void destroyPid();
std::string getVersion();
Process();
~Process();

Expand Down

0 comments on commit bd0ee61

Please sign in to comment.