37 static uv_pipe_t stdin_pipe;
43 uv_buf_t
alloc_buffer(uv_handle_t *handle,
size_t suggested_size);
56 static void read_stdin(uv_stream_t *stream, ssize_t nread, uv_buf_t buf)
62 if (uv_last_error(uv_default_loop()).code == UV_EOF)
64 uv_close((uv_handle_t *) &stdin_pipe, NULL);
69 std::string cmd(buf.base, nread);
74 uv_stop(uv_default_loop());
97 LOG(INFO) <<
"Application configuration saved !" <<
NL;
109 LOG(INFO) <<
"Application configuration restored !" <<
NL;
118 int main(
int argc,
char *argv[])
123 uv_loop_t *loop = uv_default_loop();
133 std::cout <<
"usage : " << argv[0] <<
" [number]" << std::endl;
137 std::stringstream ss;
138 ss <<
"hf://node.example.com/" << argv[1];
148 uv_pipe_init(loop, &stdin_pipe, 0);
149 uv_pipe_open(&stdin_pipe, 0);
151 uv_read_start((uv_stream_t *) &stdin_pipe,
alloc_buffer, read_stdin);
153 uv_run(loop, UV_RUN_DEFAULT);
uv_buf_t alloc_buffer(uv_handle_t *handle, size_t suggested_size)
This function is used to allocate the buffers used with libuv.
bool Handle(std::string command)
Handle the command.
Transport Layer implementation over TCP/IP using libuv.
This file contains the definitions for the HAN-FUN example applications.
void Saved()
Callback indicating that the application configuration has been saved.
void Restored()
Callback indicating that the application configuration has been restored.
This file contains the declarations of the transport layer over libuv.
void destroy()
Free the system resources associated with this transport layer.
#define NL
Helper define for new-line and stream clear.
const HF::UID::UID uid() const
Return the UID of the local device on this transport layer.
#define UNUSED(x)
Helper macro to remove warning about unused function/method argument.
This file contains the definitions for the common functionality in the HAN-FUN example applications...
#define LOG(X)
Log messages with the level given by X.
void Save()
Save application configuration.
void Initialize(HF::Transport::Layer &transport)
Initialize the application.