Quantcast
Channel: WE MOVED to github.com/microsoft/cpprestsdk. This site is not monitored!
Viewing all articles
Browse latest Browse all 4845

New Post: monitoring page

$
0
0
I want to create a page (html) that is displaying information about the state of my application, like display running in page until the application ends, and if I connect to the page, I'll see the app's status. I have started from a similar application, but it is getting more and more complicated. Is there a tutorial for such a thing? I want to refresh the page every some time.

Until now I have managed to do as this:
#pragma once

#include <functional>

#include <cpprest/basic_types.h>
#include <cpprest/http_msg.h>
#include <cpprest/http_listener.h>

class Monitoring
{
private:
    void handle_put(web::http::http_request message);
    void handle_post(web::http::http_request message);
    void handle_delete(web::http::http_request message);

    web::http::experimental::listener::http_listener m_listener;

public:
    Monitoring(utility::string_t url, std::function< void(web::http::http_request) > handler);

    pplx::task<void> open();
    pplx::task<void> close();
};
and in main I do:
utility::string_t address = U("http://" + server_addr + ":");
address.append(service_port);

onInit(address);

// my appli run

onEnd();
There is a global std::unique_ptr<Monitoring> gServer that is called in the two functions:
void onInit(const utility::string_t& address)
{
    web::uri_builder uri(address);

////// marked
    std::function<void(web::http::http_request)> har_func = std::bind(&server::request_handler::handle_a_request, request_handler, std::placeholders::_1);
//////
    gServer = std::unique_ptr<Server>(new Server(uri.to_uri().to_string(), har_func));

    gServer->open().wait();
}
and
void onExit()
{
    gServer->close().wait();
    return;
}
The marked is getting complicated. In fact there are more handle_a_request functions that are creating the tables that I have spoken in the beginning, and I am getting lost here... Maybe I don't even need that part.

P.S.: the server::request_handler is defined in the application (that I have inspired from), is there another simpler way to do it, like some implicit thing from cpprest?

Viewing all articles
Browse latest Browse all 4845

Trending Articles