| gclib 1.34.15 Communications API for Galil controllers and PLCs |

remote_server.cpp
Go to the documentation of this file.
1
10 #include "examples.h"
11
12 #include <iostream> //std::cout
13
14 #ifdef _WIN32
15 #include <conio.h>
16 #elif __linux__
17 #include <ncurses.h>
18 #endif
19
20 using namespace std;
21
22 void print_server_message(const char* message)
23 {
24 #ifdef _WIN32
25 std::cout << message << std::endl;
26 #elif __linux__
27 printw(message);
28 printw("\n");
29 #endif
30 }
31
39 GReturn remote_server(const char* server_name)
40 {
41 bool loop = true;
42 char connections[G_SMALL_BUFFER];
43 char buf[G_SMALL_BUFFER];
44
45 char instructions[] = "<p> Publish this server to the network\n"
46 "<r> Remove this server from the network\n"
47 "<q> Quit\n";
48
49 #ifdef _WIN32
50 cout << instructions << std::endl;
51 #elif __linux__
52 //These functions set up the ncurses library to capture keyboard input
53 initscr(); // Initialization of ncurses library
54 cbreak(); // Capture one character at a time
55 noecho(); // Do not write back entered characters to the console
56 printw(instructions); //Print instructions to console
57 #endif
58
59 while (loop)
60 {
61 #ifdef _WIN32
62 switch (_getch()) //Capture keypress
63 #elif __linux__
64 switch (getch()) //Capture keypress
65 #endif
66 {
67 case 'q': //Quit
68 loop = false;
69 break;
70 case 'p': //Publish this server to the network
71 e(GPublishServer(server_name, true, false));
72 print_server_message("Published Server");
73 break;
74 case 'r': //Remove this server from the network
75 e(GPublishServer(server_name, false, false));
76 print_server_message("Removed Server");
77 break;
78 }
79 }
80 #if __linux__
81 endwin(); //Restores terminal to previous state
82 #endif
83
84 return GALIL_EXAMPLE_OK;
85 }
examples.h
GPublishServer
GCLIB_DLL_EXPORTED GReturn GCALL GPublishServer(GCStringIn name, GOption publish, GOption save)
Uses GUtility(), G_UTIL_GCAPS_PUBLISH_SERVER to publish local gcaps server to the local network.
Definition: gclibo.c:189
GReturn
int GReturn
Every function returns a value of type GReturn. See gclib_errors.h for possible values.
Definition: gclib.h:93
G_SMALL_BUFFER
#define G_SMALL_BUFFER
Most reads from Galil are small. This value will easily hold most, e.g. TH, TZ, etc.
Definition: gclib.h:89
e
void e(GReturn rc)
A trivial, C++ style return code check used in Galil's examples and demos.
Definition: examples.h:33
message
GReturn message(GCon g)
Demonstrates how to receive messages from the controller and detect differences in Trace and crashed ...
Definition: message.cpp:14
remote_server
GReturn remote_server(const char *server_name)
Publishes local gcaps server to the network.
Definition: remote_server.cpp:39