Skip to content

Commit c7c7883

Browse files
Commit changes to templated logger
This mechanism allows us to eliminate at compile time logging calls that affect performance
1 parent 52389e0 commit c7c7883

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+732
-626
lines changed

applications/friopenigtlinkfaketracker/main.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ void start_tracking(std::shared_ptr<curan::communication::Server<curan::communic
108108
}
109109
catch (...)
110110
{
111-
curan::utilities::cout << "exception was thrown in the communication loop\n";
111+
curan::utilities::print<curan::utilities::major_failure>("exception was thrown in the communication loop\n");
112112
}
113113
}
114114

@@ -247,8 +247,7 @@ int main(int argc, char *argv[])
247247
auto server_joints = curan::communication::Server<curan::communication::protocols::fri>::make(context, port_fri);
248248

249249
std::thread thred_joint{[&](){ start_joint_tracking(server_joints, state_flag, shared_state);}};
250-
251-
curan::utilities::cout << "Starting server with port: " << port << " and in the localhost\n";
250+
curan::utilities::print<curan::utilities::major_failure>("Starting server with port: {:d} and in the localhost\n",port);
252251
context.run();
253252
keep_going.store(false);
254253
robot_flag.set(false);
@@ -257,6 +256,6 @@ int main(int argc, char *argv[])
257256
}
258257
catch (std::exception &e)
259258
{
260-
std::cout << "main Exception : " << e.what() << std::endl;
259+
curan::utilities::print<curan::utilities::major_failure>("main Exception : {}\n" ,e.what() );
261260
}
262261
}

applications/friopenigtlinktracker/main.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ void robot_control(curan::robotic::RobotLBR& lbr)
2929
{
3030
try
3131
{
32-
curan::utilities::cout << "Lauching robot control thread\n";
32+
curan::utilities::print<curan::utilities::info>("Lauching robot control thread\n");
3333
KUKA::FRI::UdpConnection connection{20};
3434
KUKA::FRI::ClientApplication app(connection, lbr);
3535
app.connect(DEFAULT_PORTID, NULL);
@@ -245,7 +245,7 @@ int main(int argc, char *argv[])
245245
std::cout << "joint tracking stopping" << std::endl;
246246
}}; //---------------------------
247247

248-
curan::utilities::cout << "Starting server with port: " << port << " and in the localhost\n";
248+
curan::utilities::print<curan::utilities::info>("Starting server with port: {:d} and in the localhost\n",port);
249249
context.run();
250250
server_joints->cancel();
251251
client.cancel();
@@ -256,6 +256,6 @@ int main(int argc, char *argv[])
256256
}
257257
catch (std::exception &e)
258258
{
259-
std::cout << "main Exception : " << e.what() << std::endl;
259+
curan::utilities::print<curan::utilities::major_failure>("main Exception : {}\n",e.what());
260260
}
261261
}

applications/gaussian_mixture/datacollection/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ int main(int argc, char* argv[]) {
124124

125125
try
126126
{
127-
curan::utilities::cout << "Lauching robot control thread\n";
127+
curan::utilities::print<curan::utilities::info>("Lauching robot control thread\n");
128128

129129
KUKA::FRI::UdpConnection connection{20};
130130
KUKA::FRI::ClientApplication app(connection, client);

applications/gaussian_mixture/limitcycle/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ int main(int argc, char* argv[]) {
111111

112112
try
113113
{
114-
curan::utilities::cout << "Lauching robot control thread\n";
114+
curan::utilities::print<curan::utilities::info>("Lauching robot control thread\n");
115115

116116
KUKA::FRI::UdpConnection connection{20};
117117
KUKA::FRI::ClientApplication app(connection, client);

libraries/communication/include/communication/Client.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,14 @@ namespace curan
4242
{
4343
};
4444

45+
Client(const Client &other) = delete;
46+
47+
Client &operator=(const Client &other) = delete;
48+
49+
Client(Client &&other) = delete;
50+
51+
Client &operator=(Client &&other) = delete;
52+
4553
public:
4654
~Client()
4755
{

libraries/communication/include/communication/Server.h

Lines changed: 15 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,6 @@ namespace curan
3535
{
3636
}
3737

38-
Server(asio::io_context &io_context, unsigned short port, std::function<bool(std::error_code ec)> connection_callback) : _cxt{io_context}, acceptor_{_cxt, asio::ip::tcp::endpoint(asio::ip::tcp::v4(), port)}
39-
{
40-
}
41-
4238
public:
4339
static inline std::shared_ptr<Server<protocol>> make(asio::io_context &io_context, unsigned short port)
4440
{
@@ -55,7 +51,7 @@ namespace curan
5551
*/
5652
static inline std::shared_ptr<Server<protocol>> make(asio::io_context &io_context, unsigned short port, std::function<bool(std::error_code ec)> connection_callback)
5753
{
58-
std::shared_ptr<Server<protocol>> server = std::shared_ptr<Server<protocol>>(new Server{io_context, port, connection_callback});
54+
std::shared_ptr<Server<protocol>> server = std::shared_ptr<Server<protocol>>(new Server{io_context, port});
5955
server->accept(connection_callback);
6056
return server;
6157
}
@@ -98,17 +94,20 @@ namespace curan
9894
acceptor_.cancel();
9995
}
10096

101-
void write(std::shared_ptr<utilities::MemoryBuffer> buffer)
97+
bool write(std::shared_ptr<utilities::MemoryBuffer> buffer)
10298
{
10399
std::lock_guard<std::mutex> g{mut};
100+
bool send_info = false;
104101
if (list_of_clients.size() == 0)
105-
return;
106-
list_of_clients.remove_if([buffer](std::shared_ptr<Client<protocol>> &client)
107-
{
108-
if(!client->get_socket().sendable())
109-
return true;
110-
client->write(buffer);
111-
return false; });
102+
return send_info;
103+
104+
list_of_clients.remove_if([buffer,&send_info](std::shared_ptr<Client<protocol>> &client){
105+
if(!client->get_socket().sendable())
106+
return true;
107+
client->write(buffer);
108+
send_info = true;
109+
return false; });
110+
return send_info;
112111
}
113112

114113
inline asio::io_context &get_context()
@@ -129,10 +128,8 @@ namespace curan
129128
for (auto &submitted_callables : callables)
130129
client_ptr->connect(submitted_callables);
131130
list_of_clients.push_back(client_ptr);
132-
133131
}
134-
else
135-
{
132+
else{ //what else to do if the user did not provide any callback mechanism?
136133
throw std::runtime_error("cannot wait for client");
137134
}
138135
accept();
@@ -156,12 +153,8 @@ namespace curan
156153
else
157154
client_ptr->get_socket().close();
158155
}
159-
else
160-
{
161-
connection_callback(ec);
162-
}
163-
164-
accept(connection_callback);
156+
else if(connection_callback(ec))
157+
accept(connection_callback);
165158
});
166159
}
167160
};

libraries/communication/include/communication/Socket.h

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,6 @@ namespace curan
8989
bool shoud_write = to_send.empty();
9090
auto size_before = to_send.size();
9191
to_send.push_back(buff);
92-
// std::printf("(pointer = %llu ) before (%llu) after (%llu)\n",(size_t) this, size_before, to_send.size());
9392
if (shoud_write && is_connected)
9493
do_write();
9594
});
@@ -153,10 +152,12 @@ namespace curan
153152
auto client = owner.lock();
154153
timer.async_wait([this, client, connection_callback](asio::error_code ec)
155154
{
156-
if (is_connected)
157-
return;
158-
close();
159-
connection_callback(ec); });
155+
if (is_connected)
156+
return;
157+
close();
158+
connection_callback(ec);
159+
}
160+
);
160161
asio::async_connect(_socket, endpoints,
161162
[this, client, connection_callback](std::error_code ec, asio::ip::tcp::endpoint e)
162163
{

libraries/imageprocessing/src/StudyManager.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ bool StudyManager::load_studies(std::vector<std::filesystem::path> paths) {
6666
}
6767
catch (const itk::ExceptionObject& e) {
6868
std::string s{ e.what() };
69-
utilities::cout << "Exception thrown: " + s;
69+
utilities::print<utilities::minor_failure>("StudyManager load_studies exception thrown: {}",e.what());
7070
return false;
7171
}
7272
study.study_img.push_back(image2D);
@@ -80,7 +80,7 @@ bool StudyManager::load_studies(std::vector<std::filesystem::path> paths) {
8080

8181
if (tagItr == end)
8282
{
83-
std::cerr << "Tag " << entryId; std::cerr << " not found in the DICOM header" << std::endl;
83+
utilities::print<utilities::minor_failure>("Tag {} not found in the DICOM header\n",entryId);
8484
return false;
8585
}
8686

@@ -90,7 +90,7 @@ bool StudyManager::load_studies(std::vector<std::filesystem::path> paths) {
9090
tagvalue = entryvalue->GetMetaDataObjectValue();
9191
}
9292
else {
93-
std::cerr << "Entry was not of string type" << std::endl;
93+
utilities::print<utilities::minor_failure>("Entry was not of string type\n");
9494
return false;
9595
}
9696

@@ -146,7 +146,7 @@ bool StudyManager::load_studies(std::vector<std::filesystem::path> paths) {
146146

147147
if (tagItr == end)
148148
{
149-
std::cerr << "Tag " << entryId; std::cerr << " not found in the DICOM header" << std::endl;
149+
utilities::print<utilities::minor_failure>("Tag {} not found in the DICOM header\n",entryId);
150150
return false;
151151
}
152152

@@ -155,7 +155,7 @@ bool StudyManager::load_studies(std::vector<std::filesystem::path> paths) {
155155
if (entryvalue) {
156156
tagvalue = entryvalue->GetMetaDataObjectValue();
157157
} else {
158-
std::cerr << "Entry was not of string type" << std::endl;
158+
utilities::print<utilities::minor_failure>("Entry was not of string type\n");
159159
return false;
160160
}
161161

libraries/imageprocessing/src/VolumeAlgorithms.cpp

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ bool GetPerpendicularSlice(Volume& in_vol, InternalImageType::Pointer& out_vol,
5151
filter->Update();
5252
}
5353
catch (const itk::ExceptionObject& e) {
54-
utilities::cout << e.what();
54+
utilities::print<utilities::minor_failure>("GetPerpendicularSlice() exception thrown: {}",e.what());
5555
return false;
5656
}
5757

@@ -210,8 +210,10 @@ int TrilinearInterpolation(const Eigen::Vector4d point,
210210
a *= ACCUMULATION_MULTIPLIER; // needs to be done for proper conversion to unsigned short for accumulation buffer
211211
break;
212212
default:
213-
std::string s = "Unknown Compounding operator detected, value " + std::to_string(compoundingMode) + ". Leaving value as-is.";
214-
utilities::cout << s;
213+
{
214+
std::string compmode = std::to_string(compoundingMode);
215+
utilities::print<utilities::minor_failure>("Unknown Compounding operator detected, value {0}. Leaving value as-is\n",compmode);
216+
}
215217
break;
216218
}
217219
inPtrTmp++;
@@ -363,8 +365,10 @@ int NearestNeighborInterpolation(const Eigen::Vector4d point,
363365
break;
364366
}
365367
default:
366-
std::string s = "Unknown Compounding operator detected, value " + std::to_string(compoundingMode) + ". Leaving value as-is.";
367-
utilities::cout << s;
368+
{
369+
std::string msg{std::to_string(compoundingMode)};
370+
utilities::print<utilities::minor_failure>("Unknown Compounding operator detected, value {0}. Leaving value as-is\n",msg);
371+
}
368372
break;
369373
}
370374
return 1;

libraries/imageprocessing/src/VolumeReconstructor.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -314,8 +314,7 @@ void VolumeReconstructor::fill_holes()
314314
break;
315315
default:
316316
{
317-
std::string s = "Unknown interpolation mode: " + std::to_string(fillType);
318-
utilities::cout << s;
317+
utilities::print<utilities::minor_failure>("Unknown interpolation mode: {}\n", std::to_string(fillType));
319318
return;
320319
}
321320
}

0 commit comments

Comments
 (0)