]> git.proxmox.com Git - ceph.git/blob - ceph/src/jaegertracing/opentelemetry-cpp/examples/http/server.h
update ceph source to reef 18.1.2
[ceph.git] / ceph / src / jaegertracing / opentelemetry-cpp / examples / http / server.h
1 // Copyright The OpenTelemetry Authors
2 // SPDX-License-Identifier: Apache-2.0
3
4 #pragma once
5 #include <atomic>
6 #include <string>
7 #include "opentelemetry/ext/http/server/http_server.h"
8
9 namespace
10 {
11
12 class HttpServer : public HTTP_SERVER_NS::HttpRequestCallback
13 {
14
15 protected:
16 HTTP_SERVER_NS::HttpServer server_;
17 std::string server_url_;
18 uint16_t port_;
19 std::atomic<bool> is_running_{false};
20
21 public:
22 HttpServer(std::string server_name = "test_server", uint16_t port = 8800) : port_(port)
23 {
24 server_.setServerName(server_name);
25 server_.setKeepalive(false);
26 }
27
28 void AddHandler(std::string path, HTTP_SERVER_NS::HttpRequestCallback *request_handler)
29 {
30 server_.addHandler(path, *request_handler);
31 }
32
33 void Start()
34 {
35 if (!is_running_.exchange(true))
36 {
37 server_.addListeningPort(port_);
38 server_.start();
39 }
40 }
41
42 void Stop()
43 {
44 if (is_running_.exchange(false))
45 {
46 server_.stop();
47 }
48 }
49
50 ~HttpServer() { Stop(); }
51 };
52
53 } // namespace