implement common sound dir, add some sounds
Stefan Schuermans

Stefan Schuermans commited on 2019-09-01 13:45:33
Showing 22 changed files, with 89 additions and 11 deletions.

... ...
@@ -1 +0,0 @@
1
-../../sounds
2 0
\ No newline at end of file
... ...
@@ -1 +0,0 @@
1
-../../sounds
2 0
\ No newline at end of file
... ...
@@ -1 +0,0 @@
1
-../../sounds
2 0
\ No newline at end of file
... ...
@@ -13,6 +13,7 @@
13 13
 #include <string>
14 14
 #include <string.h>
15 15
 #include <thread>
16
+#include <vector>
16 17
 
17 18
 #ifdef BLINKER_CFG_LINPHONE
18 19
 #include <linphone/linphonecore.h>
... ...
@@ -174,8 +175,15 @@ struct Data {
174 175
  */
175 176
 void set_playback(Data &data, std::string const &name)
176 177
 {
177
-  Directory dir(data.configData->soundDir);
178
-  data.playback = dir.getFile(name + ".wav").getPath();
178
+  // search sound directories for file with mathcing name
179
+  for (Directory const & soundDir : data.configData->soundDirs) {
180
+    File soundFile(soundDir.getFile(name + ".wav"));
181
+    if (soundFile.exists()) {
182
+      data.playback = soundFile.getPath();
183
+      return; // first existing file found is set for playback
184
+    }
185
+  }
186
+  data.playback.clear(); // no file found -> no playback
179 187
 }
180 188
 
181 189
 /**
... ...
@@ -658,7 +666,10 @@ SipPhone::SipPhone(const std::string &name, Mgrs &mgrs,
658 666
   m_sharedData(),
659 667
   m_curConn(nullptr)
660 668
 {
661
-  m_configData.soundDir = dirBase.getSubdir("sounds").getPath();
669
+  m_configData.soundDirs.clear();
670
+  m_configData.soundDirs.push_back(dirBase.getSubdir("sounds"));
671
+  m_configData.soundDirs.push_back(dirBase.getParent().getParent()
672
+                                          .getSubdir("sounds"));
662 673
   m_configData.logFileName = dirBase.getFile("sip.log").getPath();
663 674
   m_sharedData.run = true;
664 675
   m_sharedData.reregister = false;
... ...
@@ -10,7 +10,9 @@
10 10
 #include <mutex>
11 11
 #include <string>
12 12
 #include <thread>
13
+#include <vector>
13 14
 
15
+#include "Directory.h"
14 16
 #include "File.h"
15 17
 #include "Module.h"
16 18
 #include "NameFile.h"
... ...
@@ -27,7 +29,7 @@ class SipPhone: public Module, public OpConnIf, public TimeCallee
27 29
 public:
28 30
   /// configuration data for worker
29 31
   struct ConfigData {
30
-    std::string soundDir; ///< directory of sound files
32
+    std::vector<Directory> soundDirs; ///< dirs for sound files (1st = hi prio)
31 33
     std::string logFileName; ///< base name of log file
32 34
   };
33 35
   /// data shared between linphone thread and main Blinker thread
... ...
@@ -75,6 +75,15 @@ Directory Directory::getSubdir(const std::string &name) const
75 75
   return Directory(m_path + name);
76 76
 }
77 77
 
78
+/**
79
+ * @brief get parent directory
80
+ * @return parent directory object
81
+ */
82
+Directory Directory::getParent() const
83
+{
84
+  return Directory(m_path + "..");
85
+}
86
+
78 87
 /**
79 88
  * @brief get file in directory
80 89
  * @param[in] name of file
... ...
@@ -45,6 +45,12 @@ public:
45 45
    */
46 46
   Directory getSubdir(const std::string &name) const;
47 47
 
48
+  /**
49
+   * @brief get parent directory
50
+   * @return parent directory object
51
+   */
52
+  Directory getParent() const;
53
+
48 54
   /**
49 55
    * @brief get file in directory
50 56
    * @param[in] name of file
... ...
@@ -28,11 +28,24 @@ File::File(const std::string &path):
28 28
  * @brief get path to file
29 29
  * @return path to file
30 30
  */
31
-const std::string & File::getPath()
31
+const std::string & File::getPath() const
32 32
 {
33 33
   return m_path;
34 34
 }
35 35
 
36
+/**
37
+ * @brief check if file exists
38
+ * @return whether file exists
39
+ */
40
+bool File::exists() const
41
+{
42
+  struct stat s;
43
+  if (stat(m_path.c_str(), &s)) {
44
+    return false; // stat failed -> no such file
45
+  }
46
+  return true; // stat worked -> file exists
47
+}
48
+
36 49
 /**
37 50
  * @brief check if file has been modified
38 51
  * @return if file has been modified since last check
... ...
@@ -27,7 +27,13 @@ public:
27 27
    * @brief get path to file
28 28
    * @return path to file
29 29
    */
30
-  const std::string & getPath();
30
+  const std::string & getPath() const;
31
+
32
+  /**
33
+   * @brief check if file exists
34
+   * @return whether file exists
35
+   */
36
+  bool exists() const;
31 37
 
32 38
   /**
33 39
    * @brief check if file has been modified
... ...
@@ -76,6 +76,15 @@ Directory Directory::getSubdir(const std::string &name) const
76 76
   return Directory(m_path + name);
77 77
 }
78 78
 
79
+/**
80
+ * @brief get parent directory
81
+ * @return parent directory object
82
+ */
83
+Directory Directory::getParent() const
84
+{
85
+  return Directory(m_path + "..");
86
+}
87
+
79 88
 /**
80 89
  * @brief get file in directory
81 90
  * @param[in] name of file
... ...
@@ -45,6 +45,12 @@ public:
45 45
    */
46 46
   Directory getSubdir(const std::string &name) const;
47 47
 
48
+  /**
49
+   * @brief get parent directory
50
+   * @return parent directory object
51
+   */
52
+  Directory getParent() const;
53
+
48 54
   /**
49 55
    * @brief get file in directory
50 56
    * @param[in] name of file
... ...
@@ -28,11 +28,24 @@ File::File(const std::string &path):
28 28
  * @brief get path to file
29 29
  * @return path to file
30 30
  */
31
-const std::string & File::getPath()
31
+const std::string & File::getPath() const
32 32
 {
33 33
   return m_path;
34 34
 }
35 35
 
36
+/**
37
+ * @brief check if file exists
38
+ * @return whether file exists
39
+ */
40
+bool File::exists() const
41
+{
42
+  struct stat s;
43
+  if (stat(m_path.c_str(), &s)) {
44
+    return false; // stat failed -> no such file
45
+  }
46
+  return true; // stat worked -> file exists
47
+}
48
+
36 49
 /**
37 50
  * @brief check if file has been modified
38 51
  * @return if file has been modified since last check
... ...
@@ -27,7 +27,13 @@ public:
27 27
    * @brief get path to file
28 28
    * @return path to file
29 29
    */
30
-  const std::string & getPath();
30
+  const std::string & getPath() const;
31
+
32
+  /**
33
+   * @brief check if file exists
34
+   * @return whether file exists
35
+   */
36
+  bool exists() const;
31 37
 
32 38
   /**
33 39
    * @brief check if file has been modified
34 40