commit 9cb381ecd6f53182b6f415e3c7e8c82d098d2f45
Author: Robert Haschke <rhaschke@techfak.uni-bielefeld.de>
Date:   Mon Oct 26 01:36:30 2020 +0100

    Modernize: boost::time -> std::chrono

diff --git a/server/include/Animation.h b/server/include/Animation.h
index ef7c19e..25f37fe 100644
--- a/server/include/Animation.h
+++ b/server/include/Animation.h
@@ -28,9 +28,7 @@
 
 #pragma once
 #include <humotion/gaze_state.h>
-#include "boost/date_time/posix_time/posix_time.hpp"
-#include <boost/thread/thread_time.hpp>
-#include <boost/thread/thread.hpp>
+#include <chrono>
 
 class Animation{
 public:
@@ -90,8 +88,6 @@ private:
 
     bool active;
     unsigned int repetition_now;
-    boost::system_time end_time;
-    boost::system_time start_time;
+    std::chrono::time_point<std::chrono::steady_clock> end_time;
+    std::chrono::time_point<std::chrono::steady_clock> start_time;
 };
-
-
diff --git a/server/include/Arbiter.h b/server/include/Arbiter.h
index a9533f5..fdcc910 100644
--- a/server/include/Arbiter.h
+++ b/server/include/Arbiter.h
@@ -28,6 +28,9 @@
 
 #pragma once
 #include <string>
+#include <vector>
+#include <boost/shared_ptr.hpp>
+#include <boost/thread/mutex.hpp>
 #include <humotion/client/client.h>
 #include "EmotionState.h"
 #include "EmotionConfig.h"
@@ -35,8 +38,6 @@
 #include "Utterance.h"
 #include "AudioPlayer.h"
 #include "Animation.h"
-#include <boost/shared_ptr.hpp>
-#include <vector>
 
 class Arbiter{
 public:
@@ -76,7 +77,7 @@ private:
     humotion::GazeState gaze_state;
 
 
-    boost::posix_time::ptime gaze_state_end_time;
+    std::chrono::time_point<std::chrono::steady_clock> gaze_state_end_time;
     humotion::GazeState gaze_state_old;
     bool gaze_state_animation_restart;
 
@@ -108,5 +109,3 @@ private:
 
     AudioPlayer *audio_player;
 };
-
-
diff --git a/server/include/AudioPlayer.h b/server/include/AudioPlayer.h
index 0a43fea..c003fd7 100644
--- a/server/include/AudioPlayer.h
+++ b/server/include/AudioPlayer.h
@@ -28,8 +28,6 @@
 
 #pragma once
 #include <string>
-#include <boost/thread/thread_time.hpp>
-#include <boost/thread/thread.hpp>
 #include <boost/shared_ptr.hpp>
 #include "AudioData.h"
 
diff --git a/server/include/AudioPlayerLibAO.h b/server/include/AudioPlayerLibAO.h
index aadf904..d3ba679 100644
--- a/server/include/AudioPlayerLibAO.h
+++ b/server/include/AudioPlayerLibAO.h
@@ -29,6 +29,7 @@
 #pragma once
 #include "AudioPlayer.h"
 #include <ao/ao.h>
+#include <boost/thread/thread.hpp>
 
 class AudioPlayerLibAO : public AudioPlayer{
 public:
@@ -53,4 +54,3 @@ private:
     int driver;
 
 };
-
diff --git a/server/include/EmotionConfig.h b/server/include/EmotionConfig.h
index fcf6b96..ab0b4b4 100644
--- a/server/include/EmotionConfig.h
+++ b/server/include/EmotionConfig.h
@@ -28,10 +28,7 @@
 
 #pragma once
 #include <humotion/client/client.h>
-#include "boost/date_time/posix_time/posix_time.hpp"
-#include <boost/thread/thread_time.hpp>
-#include <boost/thread/thread.hpp>
-
+#include <chrono>
 
 class EmotionConfig{
 public:
@@ -76,6 +73,5 @@ public:
     //overblend time
     unsigned int overblend_time_ms;
 private:
-    boost::system_time end_time;
+    std::chrono::time_point<std::chrono::steady_clock> end_time;
 };
-
diff --git a/server/include/Utterance.h b/server/include/Utterance.h
index b8ca9d2..3d8824b 100644
--- a/server/include/Utterance.h
+++ b/server/include/Utterance.h
@@ -29,9 +29,8 @@
 #pragma once
 #include <string>
 #include <vector>
-#include "boost/date_time/posix_time/posix_time.hpp"
-#include <boost/thread/thread_time.hpp>
-#include <boost/thread/thread.hpp>
+#include <chrono>
+#include <boost/shared_ptr.hpp>
 #include "AudioData.h"
 
 class Utterance{
@@ -59,9 +58,8 @@ protected:
 
 private:
     phonemes_vector_t::iterator phonemes_vector_iterator;
-    boost::system_time symbol_end_time;
+    std::chrono::time_point<std::chrono::steady_clock> symbol_end_time;
 
     bool playing;
 
 };
-
diff --git a/server/src/Animation.cpp b/server/src/Animation.cpp
index 12ef64c..aecaf77 100644
--- a/server/src/Animation.cpp
+++ b/server/src/Animation.cpp
@@ -27,8 +27,9 @@
 */
 
 #include "Animation.h"
+#include <stdexcept>
+
 using namespace std;
-using namespace boost;
 
 Animation::Animation(){
     active = false;
@@ -51,8 +52,8 @@ void Animation::start(){
 
     //Set up end time
     int duration = duration_each * repetitions;
-    start_time = get_system_time(); //posix_time::microsec_clock::local_time();
-    end_time   = start_time + boost::posix_time::milliseconds(duration);
+    start_time = std::chrono::steady_clock::now();
+    end_time   = start_time + std::chrono::milliseconds(duration);
 }
 
 bool Animation::is_active(){
@@ -141,16 +142,15 @@ void Animation::apply_on_gazestate(humotion::GazeState *gaze){
     }
 
     //now check if this animation ended:
-    system_time now = get_system_time(); //posix_time::microsec_clock::local_time();
+    std::chrono::time_point<std::chrono::steady_clock> now = std::chrono::steady_clock::now();
     if (now > end_time){
         active = false;
         return;
     }
 
     //milliseconds from the beginning of this ani:
-    posix_time::time_duration diff = now - start_time;
-    float elapsed_ms = diff.total_milliseconds();
-    //printf("mili %f\n",elapsed_ms);
+    float elapsed_ms = std::chrono::duration<float, milli>(now - start_time).count();
+    //printf("milli %f\n",elapsed_ms);
 
     float max_elongation = 0.0;
     float profile = 0.0;
diff --git a/server/src/Arbiter.cpp b/server/src/Arbiter.cpp
index 938e76e..65c6630 100644
--- a/server/src/Arbiter.cpp
+++ b/server/src/Arbiter.cpp
@@ -30,6 +30,8 @@
 #include "AudioPlayerLibAO.h"
 #include "AudioPlayerRSB.h"
 #include <boost/algorithm/string/predicate.hpp>
+#include <boost/thread/mutex.hpp>
+#include <iostream>
 
 using namespace boost;
 using namespace std;
@@ -66,7 +68,7 @@ Arbiter::~Arbiter(){
 
 void Arbiter::set_default_emotion(EmotionState e){
     //lock access
-    mutex::scoped_lock scoped_lock(emotion_config_default_mutex);
+    boost::mutex::scoped_lock scoped_lock(emotion_config_default_mutex);
 
     //update our config, ignore duration as this is the default emotion
     emotion_config_default.select_config(e.value);
@@ -79,7 +81,7 @@ void Arbiter::set_default_emotion(EmotionState e){
 
 void Arbiter::set_current_emotion(EmotionState e){
     //lock access
-    mutex::scoped_lock scoped_lock(emotion_config_current_mutex);
+    boost::mutex::scoped_lock scoped_lock(emotion_config_current_mutex);
 
     //this will set a emotion override for a given time, after the timeout
     //we will return to the default emotion state:
@@ -94,21 +96,21 @@ void Arbiter::set_current_emotion(EmotionState e){
 
 void Arbiter::set_mouth_config(MouthConfig m){
     //lock access
-    mutex::scoped_lock scoped_lock(mouth_config_override_mutex);
+    boost::mutex::scoped_lock scoped_lock(mouth_config_override_mutex);
 
     mouth_config = m;
 }
 
 void Arbiter::set_gaze_target(humotion::GazeState target){
     //lock access
-    mutex::scoped_lock scoped_lock(requested_gaze_state_mutex);
+    boost::mutex::scoped_lock scoped_lock(requested_gaze_state_mutex);
 
     requested_gaze_state = target;
 }
 
 void Arbiter::set_mouth_target(humotion::MouthState target){
     //lock access
-    mutex::scoped_lock scoped_lock(requested_mouth_state_mutex);
+    boost::mutex::scoped_lock scoped_lock(requested_mouth_state_mutex);
 
     requested_mouth_state = target;
 }
@@ -117,7 +119,7 @@ void Arbiter::set_mouth_target(humotion::MouthState target){
 void Arbiter::play_animation(boost::shared_ptr<Animation> incoming_animation){
     //incoming animation, check if this would conflict with any pending animations:
     //lock access & iterate over vector:
-    mutex::scoped_lock lock_av(active_animation_vector_mutex);
+    boost::mutex::scoped_lock lock_av(active_animation_vector_mutex);
     active_animation_vector_t::iterator it;
     for(it = active_animation_vector.begin(); it<active_animation_vector.end(); it++){
         boost::shared_ptr<Animation> current_ani = *it;
@@ -160,10 +162,10 @@ void Arbiter::play_animation(boost::shared_ptr<Animation> incoming_animation){
 
 void Arbiter::speak(boost::shared_ptr<Utterance> u){ //, ao_sample_format audio_format, char *audio_data, unsigned int audio_len){
     //lock audio playback as such:
-    mutex::scoped_lock scoped_lock_audio(audio_player_mutex);
+    boost::mutex::scoped_lock scoped_lock_audio(audio_player_mutex);
 
     //lock utterance & store data:
-    mutex::scoped_lock scoped_lock(utterance_mutex);
+    boost::mutex::scoped_lock scoped_lock(utterance_mutex);
     utterance = u;
     scoped_lock.unlock();
 
@@ -270,7 +272,7 @@ void Arbiter::override_by_emotion(){
     }
 
     //lock access
-    mutex::scoped_lock scoped_lock1(emotion_config_default_mutex);
+    boost::mutex::scoped_lock scoped_lock1(emotion_config_default_mutex);
 
 
     // did the current emotion time out?
@@ -312,17 +314,16 @@ humotion::GazeState Arbiter::soft_overblend_gaze(humotion::GazeState gaze_now,
         // new incoming target, set up soft fade:
         cout << "NEW EMOTION\n";
         gaze_state_old = gaze_state;
-        gaze_state_end_time = get_system_time() + boost::posix_time::milliseconds(overblend_time);
+        gaze_state_end_time = std::chrono::steady_clock::now() + std::chrono::milliseconds(overblend_time);
         gaze_state_animation_restart = false;
     }
     // do smooth overblend, all targets should be reached at gaze_state_end_time
-    boost::posix_time::time_duration tdiff = gaze_state_end_time - get_system_time();
-    if (tdiff.is_negative()) {
+    double diff_ms = std::chrono::duration<double, std::milli>(gaze_state_end_time - std::chrono::steady_clock::now()).count();
+    if (diff_ms < 0) {
         // animation is done, exit now
         return gaze_target;
     } else {
         // do smooth animation
-        double diff_ms = tdiff.total_milliseconds();
         double tp = 1.0 - diff_ms / static_cast<double>(overblend_time);
 
         result.pan_offset = gaze_state_old.pan_offset + tp * (gaze_target.pan_offset - gaze_state_old.pan_offset);
@@ -343,7 +344,7 @@ humotion::GazeState Arbiter::soft_overblend_gaze(humotion::GazeState gaze_now,
 
 void Arbiter::override_by_animation(){
     //lock access & iterate over vector:
-    mutex::scoped_lock lock_av(active_animation_vector_mutex);
+    boost::mutex::scoped_lock lock_av(active_animation_vector_mutex);
     active_animation_vector_t::iterator it;
     for(it = active_animation_vector.begin(); it<active_animation_vector.end(); it++){
         boost::shared_ptr<Animation> current_ani = *it;
diff --git a/server/src/AudioPlayerRSB.cpp b/server/src/AudioPlayerRSB.cpp
index e96346d..d936fb6 100644
--- a/server/src/AudioPlayerRSB.cpp
+++ b/server/src/AudioPlayerRSB.cpp
@@ -127,7 +127,7 @@ void AudioPlayerRSB::playback_thread(){
                 int sampling_rate  = audio_data_ptr->rate();
                 double playback_time = (double)sample_count / (double)sampling_rate;
                 printf("> AudioPlayerRSB estimated playbacktime to %5.3lf seconds. will wait now...",playback_time);
-                boost::this_thread::sleep(boost::posix_time::milliseconds(1000.0 * playback_time));
+                boost::this_thread::sleep(std::chrono::seconds(playback_time));
                 printf("> AudioPlayerRSB finished waiting...\n");
                 break;
             }
diff --git a/server/src/EmotionConfig.cpp b/server/src/EmotionConfig.cpp
index 47b8d66..ca2bdef 100644
--- a/server/src/EmotionConfig.cpp
+++ b/server/src/EmotionConfig.cpp
@@ -27,7 +27,6 @@
 */
 
 #include "EmotionConfig.h"
-using namespace boost;
 
 EmotionConfig::EmotionConfig(){
     select_config(NEUTRAL);
@@ -42,7 +41,7 @@ EmotionConfig::~EmotionConfig(){
 
 
 bool EmotionConfig::is_active(){
-    if (get_system_time() >= end_time){
+    if (std::chrono::steady_clock::now() >= end_time){
         return false;
     }
 
@@ -51,7 +50,7 @@ bool EmotionConfig::is_active(){
 
 void EmotionConfig::set_duration(unsigned long ms){
     //set a timeout:
-    end_time = get_system_time() + posix_time::milliseconds(ms);
+    end_time = std::chrono::steady_clock::now() + std::chrono::milliseconds(ms);
 }
 
 void EmotionConfig::select_config(EmotionType e){
@@ -104,7 +103,7 @@ void EmotionConfig::init_neutral(){
     mouth_override.position_right  = 11.5250000000000000000;
     mouth_override.opening_right   = 0;//2.412000;
     */
-    
+
     mouth_override.position_left   = 20;
     mouth_override.opening_left    = 0.0;
     mouth_override.position_center = 22;
@@ -141,7 +140,7 @@ void EmotionConfig::init_happy(){
     mouth_override.opening_center  = 7.0;
     mouth_override.position_right  = -1+10.5;
     mouth_override.opening_right   = 0.0;*/
-  
+
     mouth_override.position_left   = 18; //13.56850000000000000000;
     mouth_override.opening_left    = 0; //.791000;
     mouth_override.position_center = 26; //14.18400000000000000000;
@@ -149,7 +148,7 @@ void EmotionConfig::init_happy(){
     mouth_override.position_right  = 18; //15.31800000000000000000;
     mouth_override.opening_right   = 0; //2.791000;
 
- 
+
 
 }
 
@@ -240,7 +239,7 @@ void EmotionConfig::init_surprised(){
     mouth_override.position_right  = 22.0;
     mouth_override.opening_right   = 0.0;
 
-    
+
 }
 
 void EmotionConfig::init_fear(){
diff --git a/server/src/Utterance.cpp b/server/src/Utterance.cpp
index 7dc945c..719f2f9 100644
--- a/server/src/Utterance.cpp
+++ b/server/src/Utterance.cpp
@@ -72,7 +72,7 @@ void Utterance::start_playback(){
 
     //fetch first end time
     symbol_duration_pair_t symbol_duration_pair = *phonemes_vector_iterator;
-    symbol_end_time = get_system_time() + boost::posix_time::milliseconds(symbol_duration_pair.second);
+    symbol_end_time = std::chrono::steady_clock::now() + std::chrono::milliseconds(symbol_duration_pair.second);
 
     printf("> we have %d pairs\n",(int)phonemes_vector.size());
 
@@ -87,12 +87,12 @@ string Utterance::currently_active_phoneme(){
     //empty phoneme list
     if (phonemes_vector.size() == 0) return "";
 
-    system_time now = get_system_time();
+    std::chrono::time_point<std::chrono::steady_clock> now = std::chrono::steady_clock::now();
 
     while(now > symbol_end_time){
         //fetch next phoneme:
         symbol_duration_pair_t symbol_duration_pair = *phonemes_vector_iterator;
-        symbol_end_time = symbol_end_time + boost::posix_time::milliseconds(symbol_duration_pair.second);
+        symbol_end_time = symbol_end_time + std::chrono::milliseconds(symbol_duration_pair.second);
         //printf("time: %d", symbol_duration_pair.second);
 
         //do we have to increment the iterator or are we done? (NOTE: -1 is necessary here!)
diff --git a/server/src/main.cpp b/server/src/main.cpp
index 38c52cb..04b054d 100644
--- a/server/src/main.cpp
+++ b/server/src/main.cpp
@@ -34,15 +34,13 @@
 #include <iostream>
 #include <stdlib.h>
 #include <math.h>
-#include <boost/date_time/posix_time/posix_time.hpp>
-#include <boost/thread/thread_time.hpp>
-#include <boost/thread/thread.hpp>
+#include <chrono>
+#include <thread>
 #include <boost/algorithm/string.hpp>
 
 Arbiter *arbiter;
 
 using namespace std;
-using namespace boost;
 
 int main(int argc, char *argv[]) {
     if ((argc != 5) && (argc != 6)){
@@ -59,7 +57,7 @@ int main(int argc, char *argv[]) {
 
     //fetch middleware from cmd line
     std::string mw = argv[1];
-    to_upper(mw); //convert to uppercase
+    boost::algorithm::to_upper(mw); //convert to uppercase
 
     //fetch mw for humotion
     std::string mw_humotion = argv[2];
@@ -84,9 +82,9 @@ int main(int argc, char *argv[]) {
 
     printf("> all done. hlrc server ready\n");
 
-    //send values to human motion server
-    float loop_delay = 1000.0 / 50.0; //run with 50Hz
-    boost::system_time timeout = get_system_time() + posix_time::milliseconds(loop_delay);
+    //send values to human motion server with 50Hz
+    const auto loop_period = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::duration<float>(1.0 / 50));
+    auto timeout = std::chrono::steady_clock::now() + loop_period;
 
     while(client->ok()){
         middleware->tick();
@@ -102,11 +100,9 @@ int main(int argc, char *argv[]) {
         //debug:
         //arbiter->get_mouth_state().dump();
 
-        thread::sleep(timeout);
-        timeout = get_system_time() + posix_time::milliseconds(loop_delay);
+        std::this_thread::sleep_until(timeout);
+        timeout += loop_period;
     }
 
     return EXIT_SUCCESS;
-
 }
-
