You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

4810 lines
179 KiB

4 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
4 years ago
4 years ago
​
​
​
​
4 years ago
4 years ago
​
​
​
​
​
​
​
4 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
4 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
4 years ago
4 years ago
​
​
​
​
4 years ago
4 years ago
​
​
​
​
​
​
​
4 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. #include "MySQL_dataBinder.h"
  2. #define LOG( X ) m_pLog->Log( "MDBC", this, X )
  3. #ifdef DEBUG
  4. #define LOG_ERROR( X ) {\
  5. char _tBfrErrMSG2w34[256];\
  6. sprintf( _tBfrErrMSG2w34, "In file %s[%d] in func:%s %s",__FILE__, __LINE__, __func__, X );\
  7. m_pLog->Log( "MDBC", this, _LOG_ERROR, _tBfrErrMSG2w34 );\
  8. }
  9. #else
  10. #define LOG_ERROR( X ) m_pLog->Log( "MDBC", this, _LOG_ERROR, X );
  11. #endif
  12. mysqlDBC *mysqlDBC::_instance = NULL;
  13. /**
  14. * Returns the single instance of the object.
  15. */
  16. mysqlDBC* mysqlDBC::getInstance( config_setting_t * Settings ) {
  17. // check if the instance has been created yet
  18. if( 0 == _instance ){
  19. // if not, then create it
  20. _instance = new mysqlDBC( Settings );
  21. };
  22. // return the single instance
  23. return _instance;
  24. };
  25. mysqlDBC::mysqlDBC( config_setting_t * Settings ):dataBinder(){
  26. m_pLog = basicLogCollection::getInstance();
  27. m_pSettings = basicSettingsProvider::getInstance()->getSubNode( Settings, "DBC" );
  28. m_bIsConnected = false;
  29. m_bIsServerLocal = false;
  30. m_nSiteID = 0;
  31. m_pDatabase = NULL;
  32. };
  33. mysqlDBC::~mysqlDBC(){
  34. m_bIsConnected = false;
  35. if( m_pDatabase != NULL ) delete( m_pDatabase );
  36. m_pDatabase = NULL;
  37. _instance = NULL;
  38. };
  39. bool mysqlDBC::connect( void ){
  40. config_setting_t * tSetting;
  41. m_bIsConnected = false;
  42. if( m_pSettings!= NULL ) {
  43. tSetting = config_setting_get_member( m_pSettings, "DATABASE_HOST" );
  44. if( tSetting == NULL ){
  45. tSetting = config_setting_add(m_pSettings, "DATABASE_HOST", CONFIG_TYPE_STRING );
  46. config_setting_set_string( tSetting, "localhost" );
  47. basicSettingsProvider::getInstance()->compromise();
  48. LOG("No DB Host Setting! Using default!");
  49. };
  50. sprintf(m_pDbHost, "%s", config_setting_get_string(tSetting));
  51. //Check if using local database
  52. if( strstr( m_pDbHost, "localhost" )!= NULL ){
  53. m_bIsServerLocal = true;
  54. } else {
  55. // Check if setting is local IP address
  56. };
  57. tSetting = config_setting_get_member(m_pSettings, "DATABASE_NAME");
  58. if( tSetting == NULL ){
  59. tSetting = config_setting_add(m_pSettings, "DATABASE_NAME", CONFIG_TYPE_STRING );
  60. config_setting_set_string( tSetting, "dfsl_gunter" );
  61. basicSettingsProvider::getInstance()->compromise();
  62. LOG("No DB Database Setting! Using default!");
  63. };
  64. sprintf(m_pDbDatabase, "%s", config_setting_get_string(tSetting));
  65. tSetting = config_setting_get_member( m_pSettings, "DATABASE_USER" );
  66. if( tSetting == NULL ){
  67. tSetting = config_setting_add(m_pSettings, "DATABASE_USER", CONFIG_TYPE_STRING );
  68. config_setting_set_string( tSetting, "dbroot" );
  69. basicSettingsProvider::getInstance()->compromise();
  70. LOG("No DB User Setting! Using default!");
  71. };
  72. sprintf(m_pDbUsername, "%s", config_setting_get_string(tSetting));
  73. tSetting = config_setting_get_member( m_pSettings, "DATABASE_PASSWORD" );
  74. if( tSetting == NULL ){
  75. tSetting = config_setting_add(m_pSettings, "DATABASE_PASSWORD", CONFIG_TYPE_STRING );
  76. config_setting_set_string( tSetting, "123567" );
  77. basicSettingsProvider::getInstance()->compromise();
  78. LOG("No DB Password Setting! Using default!");
  79. };
  80. sprintf(m_pDbPassword, "%s", config_setting_get_string(tSetting));
  81. basicSettingsProvider::getInstance()->validate();
  82. m_pDatabase = new MySQL_Connector();
  83. if( m_pDatabase == NULL )return false;
  84. m_bIsConnected = m_pDatabase->Connect( m_pDbDatabase, m_pDbHost, m_pDbUsername, m_pDbPassword );
  85. } else {
  86. LOG_ERROR("No Settings Provided!");
  87. };
  88. return m_bIsConnected;
  89. };
  90. void mysqlDBC::deleteCamCapPicture( uint32_t PicID ){
  91. if(m_bIsConnected) {
  92. char tQBuf[MAX_PATH_LEN];
  93. sprintf( tQBuf, "DELETE FROM `pictures` WHERE `id`=%d", PicID );
  94. #ifdef DEBUG_EXTRA
  95. LOG(tQBuf);
  96. #endif
  97. m_pDatabase->SilentQuery( tQBuf );
  98. };
  99. };
  100. void mysqlDBC::deleteNode( uint32_t NodeID ){
  101. if(m_bIsConnected) {
  102. char tQBuf[MAX_PATH_LEN];
  103. sprintf( tQBuf, "DELETE FROM `nodes` WHERE `id`=%d", NodeID );
  104. #ifdef DEBUG
  105. LOG(tQBuf);
  106. #endif
  107. m_pDatabase->SilentQuery( tQBuf );
  108. };
  109. };
  110. void mysqlDBC::deleteCamera( uint32_t CamID ){
  111. if(m_bIsConnected) {
  112. char tQBuf[MAX_PATH_LEN];
  113. sprintf( tQBuf, "DELETE FROM `cameras` WHERE `id`=%d", CamID );
  114. #ifdef DEBUG
  115. LOG(tQBuf);
  116. #endif
  117. m_pDatabase->SilentQuery( tQBuf );
  118. };
  119. };
  120. void mysqlDBC::deleteResource( uint32_t ResourceID ){
  121. if(m_bIsConnected) {
  122. char tQBuf[MAX_PATH_LEN];
  123. sprintf( tQBuf, "DELETE FROM `resources` WHERE `id`=%d", ResourceID );
  124. #ifdef DEBUG
  125. LOG(tQBuf);
  126. #endif
  127. m_pDatabase->SilentQuery( tQBuf );
  128. };
  129. };
  130. void mysqlDBC::deleteSensor( uint32_t SensorID ){
  131. if(m_bIsConnected) {
  132. char tQBuf[MAX_PATH_LEN];
  133. sprintf( tQBuf, "DELETE FROM `lrf_sensors` WHERE `id`=%d", SensorID );
  134. #ifdef DEBUG
  135. LOG(tQBuf);
  136. #endif
  137. m_pDatabase->SilentQuery( tQBuf );
  138. };
  139. };
  140. void mysqlDBC::deleteNodeEvents( uint32_t NodeID ){
  141. if(m_bIsConnected) {
  142. char tQBuf[MAX_PATH_LEN];
  143. sprintf(tQBuf, "DELETE `ep` FROM `events_2_pictures` `ep` LEFT JOIN `events_archive` `ea` ON ( `ep`.`evt_id` = `ea`.`id` ) WHERE `ea`.`node_id`=%d", NodeID);
  144. #ifdef DEBUG
  145. LOG(tQBuf);
  146. #endif
  147. m_pDatabase->SilentQuery( tQBuf );
  148. sprintf(tQBuf, "DELETE `ep` FROM `events_2_videos` `ep` LEFT JOIN `events_archive` `ea` ON ( `ep`.`evt_id` = `ea`.`id` ) WHERE `ea`.`node_id`=%d", NodeID);
  149. #ifdef DEBUG
  150. LOG(tQBuf);
  151. #endif
  152. m_pDatabase->SilentQuery( tQBuf );
  153. sprintf( tQBuf, "DELETE FROM `events_archive` WHERE `node_id`=%d", NodeID );
  154. #ifdef DEBUG
  155. LOG(tQBuf);
  156. #endif
  157. m_pDatabase->SilentQuery( tQBuf );
  158. sprintf( tQBuf, "DELETE FROM `events_cloud` WHERE `node_id`=%d", NodeID );
  159. #ifdef DEBUG
  160. LOG(tQBuf);
  161. #endif
  162. m_pDatabase->SilentQuery( tQBuf );
  163. };
  164. };
  165. void mysqlDBC::deleteUART( uint32_t UARTID ){
  166. if(m_bIsConnected) {
  167. char tQBuf[MAX_PATH_LEN];
  168. sprintf( tQBuf, "DELETE FROM `uart_settings` WHERE `id`=%d", UARTID );
  169. #ifdef DEBUG
  170. LOG(tQBuf);
  171. #endif
  172. m_pDatabase->SilentQuery( tQBuf );
  173. };
  174. };
  175. void mysqlDBC::deleteConnections( uint32_t NodeID ){
  176. if(m_bIsConnected) {
  177. char tQBuf[MAX_PATH_LEN];
  178. sprintf( tQBuf, "DELETE FROM `connections` WHERE `from`=%d OR `to`=%d", NodeID, NodeID );
  179. #ifdef DEBUG
  180. LOG(tQBuf);
  181. #endif
  182. m_pDatabase->SilentQuery( tQBuf );
  183. };
  184. };
  185. void mysqlDBC::deleteMediaStream( uint32_t MediaID ){
  186. if(m_bIsConnected) {
  187. char tQBuf[MAX_PATH_LEN];
  188. sprintf( tQBuf, "DELETE FROM `media_streams` WHERE `id`=%d", MediaID );
  189. #ifdef DEBUG
  190. LOG(tQBuf);
  191. #endif
  192. m_pDatabase->SilentQuery( tQBuf );
  193. };
  194. };
  195. void mysqlDBC::deleteNIF( uint32_t NifID ){
  196. if(m_bIsConnected) {
  197. char tQBuf[MAX_PATH_LEN];
  198. sprintf( tQBuf, "DELETE FROM `network_interfaces` WHERE `id`=%d", NifID );
  199. #ifdef DEBUG
  200. LOG(tQBuf);
  201. #endif
  202. m_pDatabase->SilentQuery( tQBuf );
  203. };
  204. };
  205. void mysqlDBC::deleteNIS( uint32_t NisID ){
  206. if(m_bIsConnected) {
  207. char tQBuf[MAX_PATH_LEN];
  208. sprintf( tQBuf, "DELETE FROM `network_infrastructure` WHERE `id`=%d", NisID );
  209. #ifdef DEBUG
  210. LOG(tQBuf);
  211. #endif
  212. m_pDatabase->SilentQuery( tQBuf );
  213. };
  214. };
  215. bool mysqlDBC::cleanEvents2PictureBinding( uint32_t PicID ){
  216. if(m_bIsConnected) {
  217. char tQBuf[MAX_PATH_LEN];
  218. sprintf( tQBuf, "DELETE FROM `events_2_pictures` WHERE `picture_id`=%d", PicID );
  219. #ifdef DEBUG_EXTRA
  220. LOG(tQBuf);
  221. #endif
  222. m_pDatabase->SilentQuery( tQBuf );
  223. return true;
  224. };
  225. return false;
  226. };
  227. bool mysqlDBC::cleanEvents2VideoBinding( uint32_t VidID ){
  228. if(m_bIsConnected) {
  229. char tQBuf[MAX_PATH_LEN];
  230. sprintf( tQBuf, "DELETE FROM `events_2_videos` WHERE `video_id`=%d", VidID );
  231. #ifdef DEBUG_EXTRA
  232. LOG(tQBuf);
  233. #endif
  234. m_pDatabase->SilentQuery( tQBuf );
  235. return true;
  236. };
  237. return false;
  238. };
  239. bool mysqlDBC::cleanResources(bool all ){
  240. if(m_bIsConnected) {
  241. char tQBuf[MAX_PATH_LEN];
  242. if( all ) {
  243. sprintf( tQBuf, "UPDATE `resources` SET `active`=0 WHERE `node_id`=%d", m_nServerNodeID );
  244. } else {
  245. sprintf( tQBuf, "UPDATE `resources` SET `active`=0 WHERE ( `node_id`=%d ) AND ( `type`=100 OR `type`=101 OR `type`=103 OR `type`=120 )", m_nServerNodeID );
  246. };
  247. #ifdef DEBUG_EXTRA
  248. LOG(tQBuf);
  249. #endif
  250. m_pDatabase->SilentQuery( tQBuf );
  251. return true;
  252. };
  253. return false;
  254. };
  255. bool mysqlDBC::cleanNodeEvents( uint32_t NodeID, bool all ){
  256. if(m_bIsConnected) {
  257. char tQBuf[MAX_PATH_LEN];
  258. if( all ) {
  259. sprintf( tQBuf, "DELETE FROM `events_cloud` WHERE `node_id`=%d", NodeID );
  260. m_pDatabase->SilentQuery( tQBuf );
  261. sprintf( tQBuf, "DELETE FROM `events_archive` WHERE `node_id`=%d", NodeID );
  262. m_pDatabase->SilentQuery( tQBuf );
  263. } else {
  264. sprintf( tQBuf, "DELETE FROM `events_cloud` WHERE `node_id`=%d", NodeID );
  265. };
  266. #ifdef DEBUG_EXTRA
  267. LOG(tQBuf);
  268. #endif
  269. m_pDatabase->SilentQuery( tQBuf );
  270. return true;
  271. };
  272. return false;
  273. };
  274. bool mysqlDBC::cleanLRFMask( uint32_t maskID, bool deleteMask ){
  275. if(m_bIsConnected) {
  276. char tQBuf[MAX_PATH_LEN];
  277. sprintf( tQBuf, "DELETE FROM `lrf_mask_trace_zones` WHERE `zone_id` IN ( SELECT `id` FROM `lrf_mask_traces` WHERE `mask_id`=%d )", maskID );
  278. #ifdef DEBUG_EXTRA
  279. LOG(tQBuf);
  280. #endif
  281. m_pDatabase->SilentQuery( tQBuf );
  282. sprintf( tQBuf, "DELETE FROM `lrf_mask_traces` WHERE `mask_id`=%d", maskID );
  283. #ifdef DEBUG_EXTRA
  284. LOG(tQBuf);
  285. #endif
  286. m_pDatabase->SilentQuery( tQBuf );
  287. sprintf( tQBuf, "DELETE FROM `lrf_mask_vertex_points` WHERE `vertex_id` IN ( SELECT `id` FROM `lrf_mask_vertexes` WHERE `mask_id`=%d )", maskID );
  288. #ifdef DEBUG_EXTRA
  289. LOG(tQBuf);
  290. #endif
  291. m_pDatabase->SilentQuery( tQBuf );
  292. sprintf( tQBuf, "DELETE FROM `lrf_mask_vertexes` WHERE `mask_id`=%d", maskID );
  293. #ifdef DEBUG_EXTRA
  294. LOG(tQBuf);
  295. #endif
  296. m_pDatabase->SilentQuery( tQBuf );
  297. //Delete Mask Itself!
  298. if ( deleteMask ) {
  299. sprintf( tQBuf, "DELETE FROM `lrf_masks` WHERE `id`=%d", maskID );
  300. #ifdef DEBUG_EXTRA
  301. LOG(tQBuf);
  302. #endif
  303. m_pDatabase->SilentQuery( tQBuf );
  304. };
  305. return true;
  306. };
  307. return false;
  308. };
  309. bool mysqlDBC::updateCamRange( uint32_t camID, float range ){
  310. if(m_bIsConnected) {
  311. char tQBuf[MAX_PATH_LEN];
  312. sprintf(tQBuf,"UPDATE cameras SET `max_range`=%.3f WHERE `id`=%d",
  313. range,
  314. camID
  315. );
  316. #ifdef DEBUG_EXTRA
  317. LOG(tQBuf);
  318. #endif
  319. m_pDatabase->SilentQuery( tQBuf );
  320. return true;
  321. };
  322. return false;
  323. };
  324. bool mysqlDBC::updateIPCam( CSTR uuid, CSTR Addr ){
  325. if(m_bIsConnected) {
  326. char tQBuf[MAX_PATH_LEN];
  327. char tIpBuf[CTEXT];
  328. char *tPos;
  329. char *tPos2;
  330. tPos = strstr(Addr,"//");
  331. if( tPos != NULL ) {
  332. tPos2 = strstr( tPos + 2,"/");
  333. if( tPos2 != NULL ) {
  334. int len;
  335. len = tPos2 - tPos - 2;
  336. strncpy(tIpBuf,tPos + 2,len);
  337. tIpBuf[len] = (char)0;
  338. } else {
  339. LOG_ERROR("Pos 2 - err");
  340. tIpBuf[0] = (char)0;
  341. };
  342. } else {
  343. LOG_ERROR("Pos 0 - err");
  344. tIpBuf[0] = (char)0;
  345. };
  346. sprintf(tQBuf,"UPDATE cameras SET `online`=1,`onvif_ctrl`='%s', `ip`='%s' WHERE `uuid`='%s'",
  347. Addr,
  348. tIpBuf,
  349. uuid
  350. );
  351. #ifdef DEBUG_EXTRA
  352. LOG(tQBuf);
  353. #endif
  354. m_pDatabase->SilentQuery( tQBuf );
  355. return true;
  356. };
  357. return false;
  358. };
  359. bool mysqlDBC::updateIPCam( uint32_t CamID, CSTR Addr ){
  360. if(m_bIsConnected) {
  361. char tQBuf[MAX_PATH_LEN];
  362. char tIpBuf[CTEXT];
  363. char *tPos;
  364. char *tPos2;
  365. tPos = strstr(Addr,"//");
  366. if( tPos != NULL ) {
  367. tPos2 = strstr( tPos + 2,"/");
  368. if( tPos2 != NULL ) {
  369. int len;
  370. len = tPos2 - tPos - 2;
  371. strncpy(tIpBuf,tPos + 2,len);
  372. tIpBuf[len] = (char)0;
  373. } else {
  374. LOG_ERROR("Pos 2 - err");
  375. tIpBuf[0] = (char)0;
  376. };
  377. } else {
  378. LOG_ERROR("Pos 0 - err");
  379. tIpBuf[0] = (char)0;
  380. };
  381. sprintf(tQBuf,"UPDATE cameras SET `online`=1, `onvif_ctrl`='%s', `ip`='%s' WHERE `id`=%d",
  382. Addr,
  383. tIpBuf,
  384. CamID
  385. );
  386. #ifdef DEBUG_EXTRA
  387. LOG(tQBuf);
  388. #endif
  389. m_pDatabase->SilentQuery( tQBuf );
  390. sprintf(tQBuf,"UPDATE media_streams SET `valid`=1 WHERE source_id=%d AND source_type='D'", CamID );
  391. #ifdef DEBUG_EXTRA
  392. LOG(tQBuf);
  393. #endif
  394. m_pDatabase->SilentQuery( tQBuf );
  395. return true;
  396. };
  397. return false;
  398. };
  399. /*
  400. bool mysqlDBC::addIPCam( uint32_t SiteID, resultWoWo *tPtr ){
  401. if(m_bIsConnected) {
  402. char tQBuf[1024];
  403. char tIpBuf[32];
  404. char tProto[32];
  405. char tPath[CTEXT];
  406. char *tPos;
  407. char *tPos2;
  408. memcpy( tProto, tPtr->XAddrs, 5 );
  409. tProto[5] = (char)0;
  410. if( tProto[4] == ':') tProto[4] = (char)0;
  411. memset( tPath, 0, CTEXT );
  412. tPos = strstr(tPtr->XAddrs,"//");
  413. if( tPos != NULL ) {
  414. tPos2 = strstr( tPos + 2,"/");
  415. if( tPos2 != NULL ) {
  416. int len,len2,len3;
  417. len = tPos2 - tPos - 2;
  418. strncpy( tIpBuf, tPos + 2, len);
  419. tIpBuf[len] = (char)0;
  420. strncpy( tPath, tPos + 2 + len, CTEXT );
  421. } else {
  422. LOG_ERROR("Pos 2 - err");
  423. tIpBuf[0] = (char)0;
  424. };
  425. } else {
  426. LOG_ERROR("Pos 0 - err");
  427. tIpBuf[0] = (char)0;
  428. };
  429. sprintf(tQBuf,"INSERT INTO cameras SET `online`=1, `uuid`='%s', `onvif_ctrl`='%s', `ip`='%s', `type`=2, `status`=0, `site_id`=%d, `mac`='%s', `hardware`='%s', `name`='%s', `onvif_access`='%s' ON DUPLICATE KEY UPDATE `online`=1, `ip`='%s'",
  430. tPtr->RefID,
  431. //tPtr->XAddrs,
  432. tPath,
  433. tIpBuf,
  434. SiteID,
  435. tPtr->MAC,
  436. tPtr->Hardware,
  437. tPtr->Name,
  438. tProto,
  439. //tPtr->XAddrs,
  440. tIpBuf
  441. );
  442. #ifdef DEBUG_EXTRA
  443. LOG(tQBuf);
  444. #endif
  445. m_pDatabase->SilentQuery( tQBuf );
  446. return true;
  447. };
  448. return false;
  449. };
  450. */
  451. bool mysqlDBC::addIPCam( OBSERVER_RESULT *tPtr ){
  452. if(m_bIsConnected) {
  453. char tQBuf[1024];
  454. char tIpBuf[32];
  455. char tProto[32];
  456. char tPath[CTEXT];
  457. char *tPos;
  458. char *tPos2;
  459. memcpy( tProto, tPtr->XAddrs, 5 );
  460. tProto[5] = (char)0;
  461. if( tProto[4] == ':') tProto[4] = (char)0;
  462. memset( tPath, 0, CTEXT );
  463. tPos = strstr(tPtr->XAddrs,"//");
  464. if( tPos != NULL ) {
  465. tPos2 = strstr( tPos + 2,"/");
  466. if( tPos2 != NULL ) {
  467. int len,len2,len3;
  468. len = tPos2 - tPos - 2;
  469. strncpy( tIpBuf, tPos + 2, len);
  470. tIpBuf[len] = (char)0;
  471. strncpy( tPath, tPos + 2 + len, CTEXT );
  472. } else {
  473. LOG_ERROR("Pos 2 - err");
  474. tIpBuf[0] = (char)0;
  475. };
  476. } else {
  477. LOG_ERROR("Pos 0 - err");
  478. tIpBuf[0] = (char)0;
  479. };
  480. sprintf(tQBuf,"INSERT INTO cameras SET `online`=1, `uuid`='%s', `onvif_ctrl`='%s', `ip`='%s', `type`=2, `status`=0, `site_id`=%d, `mac`='%s', `hardware`='%s', `name`='%s', `onvif_access`='%s' ON DUPLICATE KEY UPDATE `online`=1, `ip`='%s'",
  481. tPtr->RefID,
  482. //tPtr->XAddrs,
  483. tPath,
  484. tIpBuf,
  485. m_nSiteID,
  486. tPtr->MAC,
  487. tPtr->Hardware,
  488. tPtr->Name,
  489. tProto,
  490. //tPtr->XAddrs,
  491. tIpBuf
  492. );
  493. #ifdef DEBUG_EXTRA
  494. LOG(tQBuf);
  495. #endif
  496. m_pDatabase->SilentQuery( tQBuf );
  497. return true;
  498. };
  499. return false;
  500. };
  501. bool mysqlDBC::transferEvtToArchive( uint32_t SECONDS ){
  502. if(m_bIsConnected) {
  503. if( SECONDS > 0 ) {
  504. char tQBuf[CTEXT];
  505. sprintf(tQBuf,"INSERT INTO events_archive ( SELECT * FROM events_cloud ec WHERE ec.ts < ( UNIX_TIMESTAMP(NOW()) - %d ) ); DELETE FROM events_cloud WHERE ts < ( UNIX_TIMESTAMP(NOW()) - %d );", SECONDS, SECONDS );
  506. m_pDatabase->SilentQuery( tQBuf );
  507. return true;
  508. };
  509. };
  510. return false;
  511. }
  512. /*
  513. bool mysqlDBC::getLastEvents( vectorEventRecords &VR, uint32_t tss, uint32_t tsms ){
  514. if(m_bIsConnected){
  515. char tQBuf[CTEXT];
  516. AAssoc *result;
  517. sprintf(tQBuf, "SELECT * FROM events_cloud WHERE `ts`>%d AND `ts_ms`>%d", tss, tsms );
  518. result = m_pDatabase->Query( tQBuf );
  519. if( result!= NULL ) {
  520. DBC_EVT_DATA *tPtr;
  521. Assoc *cArr;
  522. for(int i=0;i<result->size();i++) {
  523. cArr = result->at(i);
  524. tPtr = (DBC_EVT_DATA*)malloc(sizeof(DBC_EVT_DATA));
  525. if( tPtr!= NULL ) {
  526. Assoc::iterator it;
  527. memset(tPtr,0,sizeof(DBC_EVT_DATA));
  528. it = cArr->find("id");
  529. if( it != cArr->end() ){
  530. tPtr->id = atoi( it->second.c_str() );
  531. };
  532. it = cArr->find("node_id");
  533. if( it != cArr->end() ){
  534. tPtr->node_id = atoi( it->second.c_str() );
  535. };
  536. it = cArr->find("uuid");
  537. if( it != cArr->end() ){
  538. strncpy( tPtr->uuid, it->second.c_str(),64 );
  539. };
  540. it = cArr->find("ts");
  541. if( it != cArr->end() ){
  542. tPtr->ts_s = atoi( it->second.c_str() );
  543. };
  544. it = cArr->find("ts_ms");
  545. if( it != cArr->end() ){
  546. tPtr->ts_ms = atoi( it->second.c_str() );
  547. };
  548. it = cArr->find("evt_type");
  549. if( it != cArr->end() ){
  550. tPtr->type = atoi( it->second.c_str() );
  551. };
  552. it = cArr->find("range_digital");
  553. if( it != cArr->end() ){
  554. tPtr->range_digital = atoi( it->second.c_str() );
  555. };
  556. it = cArr->find("azimuth");
  557. if( it != cArr->end() ){
  558. tPtr->az = atof( it->second.c_str() );
  559. };
  560. it = cArr->find("elevation");
  561. if( it != cArr->end() ){
  562. tPtr->el = atof( it->second.c_str() );
  563. };
  564. it = cArr->find("range");
  565. if( it != cArr->end() ){
  566. tPtr->ra = atof( it->second.c_str() );
  567. };
  568. it = cArr->find("area");
  569. if( it != cArr->end() ){
  570. tPtr->area = atof( it->second.c_str() );
  571. };
  572. it = cArr->find("lat");
  573. if( it != cArr->end() ){
  574. tPtr->lat = atof( it->second.c_str() );
  575. };
  576. it = cArr->find("lon");
  577. if( it != cArr->end() ){
  578. tPtr->lon = atof( it->second.c_str() );
  579. };
  580. it = cArr->find("alt");
  581. if( it != cArr->end() ){
  582. tPtr->alt = atof( it->second.c_str() );
  583. };
  584. it = cArr->find("ref_uuid");
  585. if( it != cArr->end() ){
  586. strncpy( tPtr->uuid, it->second.c_str(),64 );
  587. };
  588. char tBuf[CLOG];
  589. sprintf(tBuf,"Evt: %d %d %d", tPtr->type, tPtr->ts_s, tPtr->ts_ms );
  590. LOG(tBuf);
  591. VR.push_back(tPtr);
  592. };
  593. };
  594. };
  595. deleteResult( result );
  596. if( m_pDatabase->isConnected()) return true;
  597. };
  598. return false;
  599. };
  600. */
  601. //Is safe to remove???
  602. bool mysqlDBC::getAllCamRecords( uint32_t SiteID, vectorCamRecords &VR ){
  603. if(m_bIsConnected){
  604. char tQBuf[CTEXT];
  605. AAssoc *result;
  606. sprintf(tQBuf, "SELECT * FROM cameras WHERE `site_id`=%d AND `type`=2 AND `status`=2", SiteID );
  607. #ifdef DEBUG_EXTRA
  608. LOG(tQBuf);
  609. #endif
  610. result = m_pDatabase->Query( tQBuf );
  611. if( result!= NULL ) {
  612. DBC_CAM_DATA *tVal;
  613. Assoc *cArr;
  614. for(int i=0;i<result->size();i++) {
  615. LOG("Cam_Record!");
  616. cArr = result->at(i);
  617. tVal = (DBC_CAM_DATA*)malloc(sizeof(DBC_CAM_DATA));
  618. if( tVal!= NULL ) {
  619. Assoc::iterator it;
  620. memset(tVal,0,sizeof(DBC_CAM_DATA));
  621. it = cArr->find("id");
  622. if( it != cArr->end() ){
  623. tVal->id = atoi( it->second.c_str() );
  624. };
  625. it = cArr->find("type");
  626. if( it != cArr->end() ){
  627. tVal->type = atoi( it->second.c_str() );
  628. };
  629. it = cArr->find("online");
  630. if( it != cArr->end() ){
  631. tVal->online = (bool) atoi( it->second.c_str() );
  632. };
  633. it = cArr->find("stream_id");
  634. if( it != cArr->end() ){
  635. tVal->stream_id = atoi( it->second.c_str() );
  636. };
  637. it = cArr->find("hardware");
  638. if( it != cArr->end() ){
  639. strncpy( tVal->hardware, it->second.c_str(), 32 );
  640. };
  641. it = cArr->find("name");
  642. if( it != cArr->end() ){
  643. strncpy( tVal->name, it->second.c_str(), 64 );
  644. };
  645. it = cArr->find("status");
  646. if( it != cArr->end() ){
  647. tVal->status = atoi( it->second.c_str() );
  648. };
  649. it = cArr->find("session");
  650. if( it != cArr->end() ){
  651. strncpy( tVal->session, it->second.c_str(), 32 );
  652. };
  653. it = cArr->find("protocol");
  654. if( it != cArr->end() ){
  655. tVal->protocol = atoi( it->second.c_str() );
  656. };
  657. it = cArr->find("protocol_aux");
  658. if( it != cArr->end() ){
  659. tVal->protocol_aux = atoi( it->second.c_str() );
  660. };
  661. it = cArr->find("x");
  662. if( it != cArr->end() ){
  663. tVal->x = atof( it->second.c_str() );
  664. };
  665. it = cArr->find("y");
  666. if( it != cArr->end() ){
  667. tVal->y = atof( it->second.c_str() );
  668. };
  669. it = cArr->find("z");
  670. if( it != cArr->end() ){
  671. tVal->z = atof( it->second.c_str() );
  672. };
  673. it = cArr->find("x_rot");
  674. if( it != cArr->end() ){
  675. tVal->x_rot = atof( it->second.c_str() );
  676. };
  677. it = cArr->find("y_rot");
  678. if( it != cArr->end() ){
  679. tVal->y_rot = atof( it->second.c_str() );
  680. };
  681. it = cArr->find("z_rot");
  682. if( it != cArr->end() ){
  683. tVal->z_rot = atof( it->second.c_str() );
  684. };
  685. it = cArr->find("imager_type");
  686. if( it != cArr->end() ){
  687. tVal->imager_type = atoi( it->second.c_str() );
  688. };
  689. it = cArr->find("lense_f");
  690. if( it != cArr->end() ){
  691. tVal->lens_f = atoi( it->second.c_str() );
  692. };
  693. it = cArr->find("zoom");
  694. if( it != cArr->end() ){
  695. tVal->zoom = atof( it->second.c_str() );
  696. };
  697. it = cArr->find("access_login");
  698. if( it != cArr->end() ){
  699. strncpy( tVal->username, it->second.c_str(), 32 );
  700. };
  701. it = cArr->find("access_pass");
  702. if( it != cArr->end() ){
  703. strncpy( tVal->password, it->second.c_str(), 32 );
  704. };
  705. it = cArr->find("uuid");
  706. if( it != cArr->end() ){
  707. strncpy( tVal->uuid, it->second.c_str(), 64 );
  708. };
  709. it = cArr->find("mac");
  710. if( it != cArr->end() ){
  711. strncpy( tVal->mac, it->second.c_str(), 17 );
  712. };
  713. it = cArr->find("ip");
  714. if( it != cArr->end() ){
  715. strncpy( tVal->ip, it->second.c_str(), 17 );
  716. };
  717. it = cArr->find("port");
  718. if( it != cArr->end() ){
  719. tVal->port = atoi( it->second.c_str() );
  720. };
  721. it = cArr->find("onvif_access");
  722. if( it != cArr->end() ){
  723. strncpy( tVal->onvif_access, it->second.c_str(), 5);
  724. };
  725. it = cArr->find("onvif_ctrl");
  726. if( it != cArr->end() ){
  727. strncpy( tVal->onvif_ctrl, it->second.c_str(), 250);
  728. };
  729. it = cArr->find("ptz_token");
  730. if( it != cArr->end() ){
  731. strncpy( tVal->ptz_token, it->second.c_str(), 64);
  732. };
  733. VR.push_back(tVal);
  734. };
  735. //??
  736. //delete(cArr);
  737. };
  738. };
  739. deleteResult( result );
  740. #ifdef DEBUG
  741. sprintf( tQBuf,"Now %d Camera Records in System", VR.size());
  742. LOG(tQBuf);
  743. #endif
  744. if( m_pDatabase->isConnected()) return true;
  745. };
  746. return false;
  747. };
  748. DBC_INT_LIST *mysqlDBC::listNodes( uint32_t SiteID, uint32_t ServerID, bool all ){
  749. DBC_INT_LIST * tVal = NULL;
  750. if( m_bIsConnected ){
  751. char tQBuf[1024];
  752. AAssoc *result;
  753. if( all ) {
  754. if ( ServerID == 0 ) {
  755. sprintf(tQBuf, "SELECT `id` FROM `nodes` WHERE `site_id`=%d", SiteID);
  756. } else {
  757. sprintf(tQBuf, "SELECT `id` FROM `nodes` WHERE `site_id`=%d AND `server_id`=%d", SiteID, ServerID );
  758. };
  759. } else {
  760. if ( ServerID == 0 ){
  761. sprintf(tQBuf, "SELECT `id` FROM `nodes` WHERE `site_id`=%d AND `type` > 0", SiteID );
  762. } else {
  763. sprintf(tQBuf, "SELECT `id` FROM `nodes` WHERE `site_id`=%d AND `server_id`=%d AND `type` > 0", SiteID, ServerID );
  764. };
  765. };
  766. #ifdef DEBUG_EXTRA
  767. LOG(tQBuf);
  768. #endif
  769. result = m_pDatabase->Query( tQBuf );
  770. if( result!= NULL ) {
  771. if( result->size() > 0 ) {
  772. Assoc *cArr;
  773. tVal = new DBC_INT_LIST();
  774. if( tVal != NULL ) {
  775. Assoc::iterator it;
  776. for(int i=0; i <result->size();i++) {
  777. cArr = result->at(i);
  778. it = cArr->find("id");
  779. if( it != cArr->end() ){
  780. tVal->push_back( atoi( it->second.c_str() ));
  781. };
  782. };
  783. };
  784. };
  785. };
  786. deleteResult( result );
  787. };
  788. return tVal;
  789. };
  790. DBC_INT_LIST *mysqlDBC::listNewNodes( uint32_t SiteID, uint32_t ServerID, DBC_INT_LIST *old_ids ){
  791. DBC_INT_LIST * tVal = NULL;
  792. char tParam[CTEXT];
  793. //memset( tParam, 0, CTEXT );
  794. sprintf(tParam,"0");
  795. if( old_ids != NULL ) {
  796. char tBuffer[CTEXT];
  797. for(int i = 0; i< old_ids->size(); i++ ) {
  798. sprintf( tBuffer, "%s,%d", tParam, old_ids->at(i) );
  799. strncpy( tParam, tBuffer, CTEXT );
  800. };
  801. };
  802. if( m_bIsConnected ){
  803. char tQBuf[CTEXT];
  804. AAssoc *result;
  805. if ( ServerID == 0 ) {
  806. sprintf(tQBuf, "SELECT id FROM nodes WHERE `site_id`=%d AND `type` > 0 AND `id` NOT IN(%s)", SiteID, tParam);
  807. } else {
  808. sprintf(tQBuf, "SELECT id FROM nodes WHERE `site_id`=%d AND `server_id`=%d AND `type` > 0 AND `id` NOT IN(%s)", SiteID, ServerID, tParam );
  809. };
  810. #ifdef DEBUG_EXTRA
  811. LOG(tQBuf);
  812. #endif
  813. result = m_pDatabase->Query( tQBuf );
  814. if( result!= NULL ) {
  815. if( result->size() > 0 ) {
  816. Assoc *cArr;
  817. tVal = new DBC_INT_LIST();
  818. if( tVal != NULL ) {
  819. Assoc::iterator it;
  820. for(int i=0;i<result->size();i++) {
  821. cArr = result->at(i);
  822. it = cArr->find("id");
  823. if( it != cArr->end() ){
  824. tVal->push_back( atoi( it->second.c_str() ));
  825. };
  826. };
  827. };
  828. };
  829. };
  830. deleteResult( result );
  831. };
  832. return tVal;
  833. };
  834. void mysqlDBC::lazyEventArchiver( uint32_t DalayTime ){
  835. if( m_bIsConnected ){
  836. char tQBuf[CTEXT];
  837. AAssoc *result;
  838. uint32_t LastID = 0;
  839. sprintf( tQBuf, "SELECT * FROM `events_cloud` WHERE ( UNIX_TIMESTAMP(NOW()) - `ts` ) > %d ORDER BY `id` ASC LIMIT 10", DalayTime );
  840. #ifdef DEBUG_EXTRA
  841. LOG(tQBuf);
  842. #endif
  843. result = m_pDatabase->Query( tQBuf );
  844. if( result!= NULL ) {
  845. if( result->size() > 0 ) {
  846. Assoc *cArr;
  847. for(int i=0;i<result->size();i++){
  848. uint32_t nodeid=0;
  849. char uuid[64]={0};
  850. uint32_t ts=0;
  851. uint32_t ts_ms=0;
  852. uint32_t evt_t=0;
  853. uint32_t range_d=0;
  854. float az=.0f, el=.0f, ra=.0f, ar=.0f, lat=.0f, lon=.0f, alt=.0f;
  855. uint32_t ref_id=0;
  856. char ref_uuid[64]={0};
  857. Assoc::iterator it;
  858. cArr = result->at(i);
  859. it = cArr->find("id");
  860. if( it != cArr->end() ){
  861. LastID = atoi( it->second.c_str());
  862. };
  863. it = cArr->find("node_id");
  864. if( it != cArr->end() ){
  865. nodeid = atoi( it->second.c_str());
  866. };
  867. it = cArr->find("uuid");
  868. if( it != cArr->end() ){
  869. strncpy( uuid, it->second.c_str(), 64 );
  870. };
  871. it = cArr->find("ts");
  872. if( it != cArr->end() ){
  873. ts = atoi( it->second.c_str());
  874. };
  875. it = cArr->find("ts_ms");
  876. if( it != cArr->end() ){
  877. ts_ms = atoi( it->second.c_str());
  878. };
  879. it = cArr->find("evt_type");
  880. if( it != cArr->end() ){
  881. evt_t = atoi( it->second.c_str());
  882. };
  883. it = cArr->find("range_digital");
  884. if( it != cArr->end() ){
  885. range_d = atoi( it->second.c_str());
  886. };
  887. it = cArr->find("azimuth");
  888. if( it != cArr->end() ){
  889. az = (float)atof( it->second.c_str());
  890. };
  891. it = cArr->find("elevation");
  892. if( it != cArr->end() ){
  893. el = (float)atof( it->second.c_str());
  894. };
  895. it = cArr->find("range");
  896. if( it != cArr->end() ){
  897. ra = (float)atof( it->second.c_str());
  898. };
  899. it = cArr->find("area");
  900. if( it != cArr->end() ){
  901. ar = (float)atof( it->second.c_str());
  902. };
  903. it = cArr->find("lat");
  904. if( it != cArr->end() ){
  905. lat = (float)atof( it->second.c_str());
  906. };
  907. it = cArr->find("lon");
  908. if( it != cArr->end() ){
  909. lon = (float)atof( it->second.c_str());
  910. };
  911. it = cArr->find("alt");
  912. if( it != cArr->end() ){
  913. alt = (float)atof( it->second.c_str());
  914. };
  915. it = cArr->find("ref_id");
  916. if( it != cArr->end() ){
  917. ref_id = atoi( it->second.c_str());
  918. };
  919. it = cArr->find("ref_uuid");
  920. if( it != cArr->end() ){
  921. strncpy( ref_uuid, it->second.c_str(), 64 );
  922. };
  923. sprintf(tQBuf, "INSERT INTO `events_archive` SET `node_id`=%d, `uuid`='%s', `ts`=%d, `ts_ms`=%d, `evt_type`=%d, `range_digital`=%d, `azimuth`=%0.8f, `elevation`=%0.8f, `range`=%0.2f, `area`=%0.5f, `lat`=%0.8f, `lon`=%0.8f, `alt`=%0.3f, `ref_id`=%d, `ref_uuid`='%s'",
  924. nodeid,
  925. uuid,
  926. ts,
  927. ts_ms,
  928. evt_t,
  929. range_d,
  930. az,
  931. el,
  932. ra,
  933. ar,
  934. lat,
  935. lon,
  936. alt,
  937. ref_id,
  938. ref_uuid
  939. );
  940. uint32_t IID = (uint32_t) m_pDatabase->QueryID(tQBuf);
  941. sprintf(tQBuf,"UPDATE `events_2_pictures` SET `event_id`=%d WHERE `event_id`=%d", IID, LastID );
  942. //m_pDatabase->SilentQuery(tQBuf);
  943. sprintf(tQBuf,"UPDATE `events_2_videos` SET `event_id`=%d WHERE `event_id`=%d", IID, LastID );
  944. //m_pDatabase->SilentQuery(tQBuf);
  945. };
  946. };
  947. };
  948. deleteResult( result );
  949. };
  950. };
  951. DBC_INT_LIST *mysqlDBC::listCamMediaStreams( uint32_t CAMID ){
  952. DBC_INT_LIST * tVal = NULL;
  953. if(m_bIsConnected){
  954. char tQBuf[CTEXT];
  955. AAssoc *result;
  956. sprintf(tQBuf, "SELECT id FROM media_streams WHERE `source_id`=%d AND `valid`=1", CAMID );
  957. #ifdef DEBUG_EXTRA
  958. LOG(tQBuf);
  959. #endif
  960. result = m_pDatabase->Query( tQBuf );
  961. if( result!= NULL ) {
  962. if( result->size() > 0 ) {
  963. Assoc *cArr;
  964. tVal = new DBC_INT_LIST();
  965. if( tVal != NULL ) {
  966. Assoc::iterator it;
  967. for(int i=0;i<result->size();i++) {
  968. cArr = result->at(i);
  969. it = cArr->find("id");
  970. if( it != cArr->end() ){
  971. tVal->push_back( atoi( it->second.c_str() ));
  972. };
  973. };
  974. };
  975. };
  976. };
  977. deleteResult( result );
  978. };
  979. return tVal;
  980. };
  981. DBC_INT_LIST *mysqlDBC::listStreamCapPictures( uint32_t StreamID, uint32_t cnt ){
  982. DBC_INT_LIST * tVal = NULL;
  983. if(m_bIsConnected){
  984. char tQBuf[CTEXT];
  985. AAssoc *result;
  986. sprintf(tQBuf, "SELECT `id` FROM `pictures` WHERE `media_stream_id`=%d LIMIT %d", StreamID, cnt );
  987. #ifdef DEBUG_EXTRA
  988. LOG(tQBuf);
  989. #endif
  990. result = m_pDatabase->Query( tQBuf );
  991. if( result!= NULL ) {
  992. if( result->size() > 0 ) {
  993. Assoc *cArr;
  994. tVal = new DBC_INT_LIST();
  995. if( tVal != NULL ) {
  996. Assoc::iterator it;
  997. for(int i=0;i<result->size();i++) {
  998. cArr = result->at(i);
  999. it = cArr->find("id");
  1000. if( it != cArr->end() ){
  1001. tVal->push_back( atoi( it->second.c_str() ));
  1002. };
  1003. };
  1004. };
  1005. };
  1006. };
  1007. deleteResult( result );
  1008. };
  1009. return tVal;
  1010. };
  1011. DBC_NETWORK_DATA *mysqlDBC::getNetworkData( uint32_t net_id ){
  1012. DBC_NETWORK_DATA * tVal = NULL;
  1013. if(m_bIsConnected){
  1014. char tQBuf[CTEXT];
  1015. AAssoc *result;
  1016. sprintf(tQBuf, "SELECT * FROM `networks` WHERE `id`=%d", net_id );
  1017. #ifdef DEBUG_EXTRA
  1018. LOG(tQBuf);
  1019. #endif
  1020. result = m_pDatabase->Query( tQBuf );
  1021. if( result!= NULL ) {
  1022. if( result->size() > 0 ) {
  1023. Assoc *cArr;
  1024. tVal = (DBC_NETWORK_DATA*) malloc(sizeof(DBC_NETWORK_DATA));
  1025. if( tVal != NULL ) {
  1026. memset(tVal, 0, sizeof(DBC_NETWORK_DATA));
  1027. Assoc::iterator it;
  1028. tVal->id = net_id;
  1029. cArr = result->at(0);
  1030. it = cArr->find("nif_id");
  1031. if( it != cArr->end() ){
  1032. tVal->nif_id = atoi(it->second.c_str());
  1033. };
  1034. it = cArr->find("type");
  1035. if( it != cArr->end() ){
  1036. tVal->type = (NETWORK_TYPE) atoi(it->second.c_str());
  1037. };
  1038. it = cArr->find("address");
  1039. if( it != cArr->end() ){
  1040. strncpy( tVal->address, it->second.c_str(), 65 );
  1041. tVal->address[64]=(char)0;
  1042. };
  1043. it = cArr->find("gateway");
  1044. if( it != cArr->end() ){
  1045. strncpy(tVal->gateway, it->second.c_str(), 65);
  1046. tVal->gateway[64]=(char)0;
  1047. };
  1048. it = cArr->find("mask");
  1049. if( it != cArr->end() ){
  1050. strncpy( tVal->netmask, it->second.c_str(), 65 );
  1051. tVal->netmask[64]=(char)0;
  1052. };
  1053. it = cArr->find("broadcast");
  1054. if( it != cArr->end() ){
  1055. strncpy( tVal->broadcast, it->second.c_str(), 65 );
  1056. tVal->broadcast[64]=(char)0;
  1057. };
  1058. };
  1059. };
  1060. };
  1061. deleteResult( result );
  1062. };
  1063. return tVal;
  1064. };
  1065. DBC_NET_IF_DATA *mysqlDBC::getNIF_Data( uint32_t nif_id ){
  1066. DBC_NET_IF_DATA * tVal = NULL;
  1067. if(m_bIsConnected){
  1068. char tQBuf[CTEXT];
  1069. AAssoc *result;
  1070. sprintf(tQBuf, "SELECT `type`, `mode`, `device_name`, `mac`, `aux_id` FROM `network_interfaces` WHERE `id`=%d", nif_id );
  1071. #ifdef DEBUG_EXTRA
  1072. LOG(tQBuf);
  1073. #endif
  1074. result = m_pDatabase->Query( tQBuf );
  1075. if( result!= NULL ) {
  1076. if( result->size() > 0 ) {
  1077. Assoc *cArr;
  1078. tVal = (DBC_NET_IF_DATA*) malloc(sizeof(DBC_NET_IF_DATA));
  1079. if( tVal != NULL ) {
  1080. Assoc::iterator it;
  1081. tVal->id = nif_id;
  1082. cArr = result->at(0);
  1083. it = cArr->find("type");
  1084. if( it != cArr->end() ){
  1085. tVal->type = atoi(it->second.c_str());
  1086. };
  1087. it = cArr->find("mode");
  1088. if( it != cArr->end() ){
  1089. tVal->mode = atoi(it->second.c_str());
  1090. };
  1091. it = cArr->find("device_name");
  1092. if( it != cArr->end() ){
  1093. strncpy( tVal->device_name, it->second.c_str(),11);
  1094. tVal->device_name[10]=(char)0;
  1095. };
  1096. it = cArr->find("mac");
  1097. if( it != cArr->end() ){
  1098. strncpy( tVal->mac, it->second.c_str(), 33 );
  1099. tVal->mac[32]=(char)0;
  1100. };
  1101. it = cArr->find("aux_id");
  1102. if( it != cArr->end() ){
  1103. tVal->aux_id = atoi(it->second.c_str());
  1104. };
  1105. };
  1106. };
  1107. };
  1108. deleteResult( result );
  1109. };
  1110. return tVal;
  1111. };
  1112. uint32_t mysqlDBC::getNetworkInfrastructureID( uint32_t nif_id ){
  1113. uint32_t tVal = 0;
  1114. if(m_bIsConnected){
  1115. char tQBuf[CTEXT];
  1116. AAssoc *result;
  1117. sprintf(tQBuf, "SELECT id FROM `network_infrastructure` WHERE `nif_id`=%d", nif_id );
  1118. #ifdef DEBUG
  1119. LOG(tQBuf);
  1120. #endif
  1121. result = m_pDatabase->Query( tQBuf );
  1122. if( result!= NULL ) {
  1123. if( result->size() > 0 ) {
  1124. Assoc *cArr;
  1125. Assoc::iterator it;
  1126. cArr = result->at(0);
  1127. it = cArr->find("id");
  1128. if( it != cArr->end() ){
  1129. tVal = atoi( it->second.c_str() );
  1130. };
  1131. };
  1132. };
  1133. deleteResult( result );
  1134. };
  1135. return tVal;
  1136. };
  1137. CSTR mysqlDBC::getNodeName( uint32_t NodeID ){
  1138. CSTR tVal = NULL;
  1139. if(m_bIsConnected){
  1140. char tQBuf[CTEXT];
  1141. AAssoc *result;
  1142. sprintf(tQBuf, "SELECT `name` FROM `nodes` WHERE `id`=%d", NodeID );
  1143. #ifdef DEBUG
  1144. LOG(tQBuf);
  1145. #endif
  1146. result = m_pDatabase->Query( tQBuf );
  1147. if( result!= NULL ) {
  1148. if( result->size() > 0 ) {
  1149. Assoc *cArr;
  1150. Assoc::iterator it;
  1151. cArr = result->at(0);
  1152. it = cArr->find("name");
  1153. if( it != cArr->end() ){
  1154. tVal = strdup( it->second.c_str() );
  1155. };
  1156. };
  1157. };
  1158. deleteResult( result );
  1159. };
  1160. return tVal;
  1161. };
  1162. uint32_t mysqlDBC::getNodeAuxID( uint32_t NodeID ){
  1163. uint32_t tVal;
  1164. if(m_bIsConnected){
  1165. char tQBuf[CTEXT];
  1166. AAssoc *result;
  1167. sprintf(tQBuf, "SELECT `aux_id` FROM `nodes` WHERE `id`=%d", NodeID );
  1168. #ifdef DEBUG
  1169. LOG(tQBuf);
  1170. #endif
  1171. result = m_pDatabase->Query( tQBuf );
  1172. if( result!= NULL ) {
  1173. if( result->size() > 0 ) {
  1174. Assoc *cArr;
  1175. Assoc::iterator it;
  1176. cArr = result->at(0);
  1177. it = cArr->find("aux_id");
  1178. if( it != cArr->end() ){
  1179. tVal = atoi( it->second.c_str() );
  1180. };
  1181. };
  1182. };
  1183. deleteResult( result );
  1184. };
  1185. return tVal;
  1186. };
  1187. uint32_t mysqlDBC::getNodeAuxParam( uint32_t NodeID ){
  1188. uint32_t tVal;
  1189. if(m_bIsConnected){
  1190. char tQBuf[CTEXT];
  1191. AAssoc *result;
  1192. sprintf(tQBuf, "SELECT `aux_parameter` FROM `nodes` WHERE `id`=%d", NodeID );
  1193. #ifdef DEBUG
  1194. LOG(tQBuf);
  1195. #endif
  1196. result = m_pDatabase->Query( tQBuf );
  1197. if( result!= NULL ) {
  1198. if( result->size() > 0 ) {
  1199. Assoc *cArr;
  1200. Assoc::iterator it;
  1201. cArr = result->at(0);
  1202. it = cArr->find("aux_parameter");
  1203. if( it != cArr->end() ){
  1204. tVal = atoi( it->second.c_str() );
  1205. };
  1206. };
  1207. };
  1208. deleteResult( result );
  1209. };
  1210. return tVal;
  1211. };
  1212. uint32_t mysqlDBC::getWiFi_ID( uint32_t nif_id ){
  1213. uint32_t tVal = 0;
  1214. if(m_bIsConnected){
  1215. char tQBuf[CTEXT];
  1216. AAssoc *result;
  1217. sprintf(tQBuf, "SELECT `id` FROM `wifis` WHERE `nif_id`=%d", nif_id );
  1218. #ifdef DEBUG
  1219. LOG(tQBuf);
  1220. #endif
  1221. result = m_pDatabase->Query( tQBuf );
  1222. if( result!= NULL ) {
  1223. if( result->size() > 0 ) {
  1224. Assoc *cArr;
  1225. Assoc::iterator it;
  1226. cArr = result->at(0);
  1227. it = cArr->find("id");
  1228. if( it != cArr->end() ){
  1229. tVal = atoi( it->second.c_str() );
  1230. };
  1231. };
  1232. };
  1233. deleteResult( result );
  1234. };
  1235. return tVal;
  1236. };
  1237. uint32_t mysqlDBC::getNIF_ID( CSTR key ){
  1238. uint32_t tVal = 0;
  1239. if(m_bIsConnected){
  1240. char tQBuf[CTEXT];
  1241. AAssoc *result;
  1242. sprintf(tQBuf, "SELECT id FROM `network_interfaces` WHERE `key`='%s'", key );
  1243. #ifdef DEBUG_EXTRA
  1244. LOG(tQBuf);
  1245. #endif
  1246. result = m_pDatabase->Query( tQBuf );
  1247. if( result!= NULL ) {
  1248. if( result->size() > 0 ) {
  1249. Assoc *cArr;
  1250. Assoc::iterator it;
  1251. cArr = result->at(0);
  1252. it = cArr->find("id");
  1253. if( it != cArr->end() ){
  1254. tVal = atoi( it->second.c_str() );
  1255. };
  1256. };
  1257. };
  1258. deleteResult( result );
  1259. };
  1260. return tVal;
  1261. };
  1262. uint32_t mysqlDBC::getNIF_IDbyDevice( CSTR device ){
  1263. uint32_t tVal = 0;
  1264. if(m_bIsConnected){
  1265. char tQBuf[CTEXT];
  1266. AAssoc *result;
  1267. sprintf(tQBuf, "SELECT id FROM `network_interfaces` WHERE `device_name`='%s'", device );
  1268. #ifdef DEBUG
  1269. LOG(tQBuf);
  1270. #endif
  1271. result = m_pDatabase->Query( tQBuf );
  1272. if( result!= NULL ) {
  1273. if( result->size() > 0 ) {
  1274. Assoc *cArr;
  1275. Assoc::iterator it;
  1276. cArr = result->at(0);
  1277. it = cArr->find("id");
  1278. if( it != cArr->end() ){
  1279. tVal = atoi( it->second.c_str() );
  1280. };
  1281. };
  1282. };
  1283. deleteResult( result );
  1284. };
  1285. return tVal;
  1286. };
  1287. DBC_NODE_DATA *mysqlDBC::getNodeData( uint32_t ID ){
  1288. DBC_NODE_DATA * tVal = NULL;
  1289. if(m_bIsConnected){
  1290. char tQBuf[CTEXT];
  1291. AAssoc *result;
  1292. sprintf(tQBuf, "SELECT * FROM nodes WHERE `id`=%d", ID );
  1293. #ifdef DEBUG_EXTRA
  1294. LOG(tQBuf);
  1295. #endif
  1296. result = m_pDatabase->Query( tQBuf );
  1297. if( result!= NULL ) {
  1298. if( result->size() > 0 ) {
  1299. Assoc *cArr;
  1300. tVal = (DBC_NODE_DATA*) malloc(sizeof(DBC_NODE_DATA));
  1301. if( tVal != NULL ) {
  1302. memset( tVal, 0, sizeof(DBC_NODE_DATA));
  1303. Assoc::iterator it;
  1304. cArr = result->at(0);
  1305. it = cArr->find("id");
  1306. if( it != cArr->end() ){
  1307. tVal->node_id = atoi( it->second.c_str() );
  1308. };
  1309. it = cArr->find("type");
  1310. if( it != cArr->end() ){
  1311. tVal->type = /*(NODE_TYPE)*/ atoi( it->second.c_str() );
  1312. };
  1313. it = cArr->find("aux_id");
  1314. if( it != cArr->end() ){
  1315. tVal->aux_id = atoi( it->second.c_str() );
  1316. };
  1317. it = cArr->find("aux_parameter");
  1318. if( it != cArr->end() ){
  1319. tVal->aux_parameter = atoi( it->second.c_str() );
  1320. };
  1321. it = cArr->find("name");
  1322. if( it != cArr->end() ){
  1323. sprintf( tVal->name, it->second.c_str() );
  1324. };
  1325. it = cArr->find("ts_s");
  1326. if( it != cArr->end() ){
  1327. tVal->tss = atoi( it->second.c_str() );
  1328. };
  1329. it = cArr->find("ts_ms");
  1330. if( it != cArr->end() ){
  1331. tVal->tsm = atoi( it->second.c_str() );
  1332. };
  1333. it = cArr->find("online");
  1334. if( it != cArr->end() ){
  1335. tVal->online = (bool)atoi( it->second.c_str() );
  1336. };
  1337. };
  1338. };
  1339. };
  1340. deleteResult( result );
  1341. };
  1342. return tVal;
  1343. };
  1344. DBC_APF_DATA *mysqlDBC::getAPFData( uint32_t APFID ){
  1345. DBC_APF_DATA * tVal = NULL;
  1346. if(m_bIsConnected){
  1347. char tQBuf[CTEXT];
  1348. AAssoc *result;
  1349. sprintf(tQBuf, "SELECT * FROM `target_filter_apf` WHERE `id`=%d", APFID );
  1350. #ifdef DEBUG
  1351. LOG(tQBuf);
  1352. #endif
  1353. result = m_pDatabase->Query( tQBuf );
  1354. if( result!= NULL ) {
  1355. if( result->size() > 0 ) {
  1356. Assoc *cArr;
  1357. tVal = (DBC_APF_DATA*) malloc(sizeof(DBC_APF_DATA));
  1358. if( tVal != NULL ) {
  1359. memset( tVal, 0 , sizeof(DBC_APF_DATA));
  1360. Assoc::iterator it;
  1361. cArr = result->at(0);
  1362. it = cArr->find("mode");
  1363. if( it != cArr->end() ){
  1364. sprintf( tVal->mode, it->second.c_str() );
  1365. };
  1366. it = cArr->find("port");
  1367. if( it != cArr->end() ){
  1368. tVal->port = atoi( it->second.c_str() );
  1369. };
  1370. it = cArr->find("lat");
  1371. if( it != cArr->end() ){
  1372. tVal->lat = atof( it->second.c_str() );
  1373. };
  1374. it = cArr->find("lon");
  1375. if( it != cArr->end() ){
  1376. tVal->lon = atof( it->second.c_str() );
  1377. };
  1378. it = cArr->find("alt");
  1379. if( it != cArr->end() ){
  1380. tVal->alt = atof( it->second.c_str() );
  1381. };
  1382. it = cArr->find("roll");
  1383. if( it != cArr->end() ){
  1384. tVal->roll = atof( it->second.c_str() );
  1385. };
  1386. it = cArr->find("pitch");
  1387. if( it != cArr->end() ){
  1388. tVal->pitch = atof( it->second.c_str() );
  1389. };
  1390. it = cArr->find("yaw");
  1391. if( it != cArr->end() ){
  1392. tVal->yaw = atof( it->second.c_str() );
  1393. };
  1394. it = cArr->find("dx");
  1395. if( it != cArr->end() ){
  1396. tVal->dx = atof( it->second.c_str() );
  1397. };
  1398. it = cArr->find("dy");
  1399. if( it != cArr->end() ){
  1400. tVal->dy = atof( it->second.c_str() );
  1401. };
  1402. it = cArr->find("dz");
  1403. if( it != cArr->end() ){
  1404. tVal->dz = atof( it->second.c_str() );
  1405. };
  1406. };
  1407. };
  1408. };
  1409. deleteResult( result );
  1410. };
  1411. return tVal;
  1412. };
  1413. DBC_FH_DATA *mysqlDBC::getFlyHunterData( uint32_t ID ){
  1414. DBC_FH_DATA * tVal = NULL;
  1415. if(m_bIsConnected){
  1416. char tQBuf[CTEXT];
  1417. AAssoc *result;
  1418. sprintf(tQBuf, "SELECT * FROM `modules_fly_hunter` WHERE `id`=%d", ID );
  1419. #ifdef DEBUG
  1420. LOG(tQBuf);
  1421. #endif
  1422. result = m_pDatabase->Query( tQBuf );
  1423. if( result!= NULL ) {
  1424. if( result->size() > 0 ) {
  1425. Assoc *cArr;
  1426. tVal = (DBC_FH_DATA*) malloc(sizeof(DBC_FH_DATA));
  1427. if( tVal != NULL ) {
  1428. memset( tVal, 0 , sizeof(DBC_FH_DATA));
  1429. Assoc::iterator it;
  1430. cArr = result->at(0);
  1431. it = cArr->find("name");
  1432. if( it != cArr->end() ){
  1433. sprintf( tVal->name, it->second.c_str() );
  1434. };
  1435. it = cArr->find("lat");
  1436. if( it != cArr->end() ){
  1437. tVal->lat = atof( it->second.c_str() );
  1438. };
  1439. it = cArr->find("lon");
  1440. if( it != cArr->end() ){
  1441. tVal->lon = atof( it->second.c_str() );
  1442. };
  1443. it = cArr->find("alt");
  1444. if( it != cArr->end() ){
  1445. tVal->alt = atof( it->second.c_str() );
  1446. };
  1447. it = cArr->find("dc_module_id");
  1448. if( it != cArr->end() ){
  1449. tVal->dc_id = atoi( it->second.c_str() );
  1450. };
  1451. it = cArr->find("uart_id");
  1452. if( it != cArr->end() ){
  1453. tVal->uart_id = atoi( it->second.c_str() );
  1454. };
  1455. };
  1456. };
  1457. };
  1458. deleteResult( result );
  1459. };
  1460. return tVal;
  1461. };
  1462. bool mysqlDBC::fillShadow2D( uint32_t ID, SHADOW & SH ){
  1463. if( m_bIsConnected ){
  1464. char tQBuf[CTEXT];
  1465. AAssoc *result;
  1466. sprintf(tQBuf, "SELECT `lv`.`id`, `lm`.`layer`, `lm`.`status` FROM `lrf_mask_vertexes` `lv` LEFT JOIN `lrf_masks` `lm` ON (`lm`.`id` = `lv`.`mask_id`) WHERE `lm`.`sensor_id`=%d ORDER BY `lv`.`id`", ID );
  1467. LOG(tQBuf);
  1468. result = m_pDatabase->Query( tQBuf );
  1469. if( result!= NULL ) {
  1470. if( result->size() > 0 ) {
  1471. SH.m_nEnabled = 0xFFFFFFFF;
  1472. SH.m_nPolygonCount = result->size();
  1473. SH.pPolygones = (SHADOW_POLY *) calloc( SH.m_nPolygonCount, sizeof( SHADOW_POLY ) );
  1474. if ( SH.pPolygones ) {
  1475. Assoc * cArr;
  1476. for ( uint8_t idx = 0; idx < result->size(); idx++ ) {
  1477. Assoc::iterator it;
  1478. cArr = result->at(idx);
  1479. it = cArr->find("id");
  1480. if( it != cArr->end() ){
  1481. SH.pPolygones[idx].m_nDBID = atoi(it->second.c_str());
  1482. };
  1483. it = cArr->find("layer");
  1484. if( it != cArr->end() ){
  1485. SH.pPolygones[idx].bType = atoi(it->second.c_str());
  1486. };
  1487. it = cArr->find("status");
  1488. if( it != cArr->end() ){
  1489. SH.m_nEnabled &= ( it->second.c_str()[0] == 'E' )?0xFFFFFFFF:~(1<<SH.pPolygones[idx].bType);
  1490. };
  1491. sprintf(tQBuf, "SELECT * FROM `lrf_mask_vertex_points` WHERE `vertex_id`=%d ORDER BY `id`", SH.pPolygones[idx].m_nDBID );
  1492. LOG(tQBuf);
  1493. AAssoc *v_result = m_pDatabase->Query( tQBuf );
  1494. if( v_result!= NULL ) {
  1495. if( v_result->size() > 0 ) {
  1496. SH.pPolygones[idx].wCount = v_result->size();
  1497. SH.pPolygones[idx].pPoint = (HZ_POINT *) calloc( SH.pPolygones[idx].wCount, sizeof( HZ_POINT ) );
  1498. if(SH.pPolygones[idx].pPoint ) {
  1499. for ( uint32_t zdx =0; zdx < SH.pPolygones[idx].wCount; zdx++ ) {
  1500. cArr = v_result->at(zdx);
  1501. it = cArr->find("x");
  1502. if( it != cArr->end() ){
  1503. SH.pPolygones[idx].pPoint[zdx].wX = atoi(it->second.c_str());
  1504. };
  1505. it = cArr->find("y");
  1506. if( it != cArr->end() ){
  1507. SH.pPolygones[idx].pPoint[zdx].wY = atoi(it->second.c_str());
  1508. };
  1509. LOG("Point Added!");
  1510. };
  1511. } else {
  1512. LOG("No mem for Points!");
  1513. };
  1514. } else {
  1515. LOG("No Points!");
  1516. SH.pPolygones[idx].wCount = 0;
  1517. SH.pPolygones[idx].pPoint = NULL;
  1518. };
  1519. deleteResult( v_result );
  1520. };
  1521. };
  1522. };
  1523. };
  1524. deleteResult( result );
  1525. };
  1526. return true;
  1527. };
  1528. return false;
  1529. };
  1530. DBC_SITE_DATA *mysqlDBC::getSiteData( uint32_t ID ){
  1531. DBC_SITE_DATA * tVal = NULL;
  1532. if(m_bIsConnected){
  1533. char tQBuf[CTEXT];
  1534. AAssoc *result;
  1535. sprintf(tQBuf, "SELECT * FROM sites WHERE `id`=%d", ID );
  1536. #ifdef DEBUG
  1537. LOG(tQBuf);
  1538. #endif
  1539. result = m_pDatabase->Query( tQBuf );
  1540. if( result!= NULL ) {
  1541. if( result->size() > 0 ) {
  1542. Assoc *cArr;
  1543. tVal = (DBC_SITE_DATA*) malloc(sizeof(DBC_SITE_DATA));
  1544. if( tVal != NULL ) {
  1545. memset( tVal, 0 , sizeof(DBC_SITE_DATA));
  1546. Assoc::iterator it;
  1547. cArr = result->at(0);
  1548. it = cArr->find("account_id");
  1549. if( it != cArr->end() ){
  1550. tVal->account_id = atoi( it->second.c_str() );
  1551. };
  1552. it = cArr->find("name");
  1553. if( it != cArr->end() ){
  1554. sprintf( tVal->name, it->second.c_str() );
  1555. };
  1556. it = cArr->find("server_ident");
  1557. if( it != cArr->end() ){
  1558. sprintf( tVal->ident, it->second.c_str() );
  1559. };
  1560. it = cArr->find("anchor_lat");
  1561. if( it != cArr->end() ){
  1562. tVal->lat = atof( it->second.c_str() );
  1563. };
  1564. it = cArr->find("anchor_lon");
  1565. if( it != cArr->end() ){
  1566. tVal->lon = atof( it->second.c_str() );
  1567. };
  1568. it = cArr->find("anchor_alt");
  1569. if( it != cArr->end() ){
  1570. tVal->alt = atof( it->second.c_str() );
  1571. };
  1572. it = cArr->find("hemisphere");
  1573. if( it != cArr->end() ){
  1574. tVal->SH = ( it->second.c_str()[0] == 'S' );
  1575. };
  1576. it = cArr->find("map_id");
  1577. if( it != cArr->end() ){
  1578. tVal->map_id = atoi( it->second.c_str() );
  1579. };
  1580. it = cArr->find("local_binding");
  1581. if( it != cArr->end() ){
  1582. tVal->local_binding = (bool) atoi(it->second.c_str());
  1583. };
  1584. };
  1585. };
  1586. };
  1587. deleteResult( result );
  1588. };
  1589. return tVal;
  1590. };
  1591. DBC_TARGET_FLITER_DATA *mysqlDBC::getTargetFilterData( uint32_t ID ){
  1592. DBC_TARGET_FLITER_DATA * tVal = NULL;
  1593. if(m_bIsConnected){
  1594. char tQBuf[CTEXT];
  1595. AAssoc *result;
  1596. sprintf(tQBuf, "SELECT * FROM target_filters WHERE `id`=%d", ID );
  1597. #ifdef DEBUG
  1598. LOG(tQBuf);
  1599. #endif
  1600. result = m_pDatabase->Query( tQBuf );
  1601. if( result!= NULL ) {
  1602. if( result->size() > 0 ) {
  1603. Assoc *cArr;
  1604. tVal = (DBC_TARGET_FLITER_DATA*) malloc(sizeof(DBC_TARGET_FLITER_DATA));
  1605. if( tVal != NULL ) {
  1606. memset( tVal, 0 , sizeof(DBC_TARGET_FLITER_DATA));
  1607. Assoc::iterator it;
  1608. tVal->id = ID;
  1609. cArr = result->at(0);
  1610. it = cArr->find("type");
  1611. if( it != cArr->end() ){
  1612. tVal->type = (TARGET_FILTER_TYPE) atoi( it->second.c_str() );
  1613. };
  1614. it = cArr->find("aux_id");
  1615. if( it != cArr->end() ){
  1616. tVal->aux_id = atoi( it->second.c_str() );
  1617. };
  1618. };
  1619. };
  1620. };
  1621. deleteResult( result );
  1622. };
  1623. return tVal;
  1624. };
  1625. DBC_LRF_DATA *mysqlDBC::getLRFData( uint32_t ID ){
  1626. DBC_LRF_DATA * tVal = NULL;
  1627. if(m_bIsConnected){
  1628. char tQBuf[CTEXT];
  1629. AAssoc *result;
  1630. sprintf(tQBuf, "SELECT * FROM lrf_sensors WHERE `id`=%d", ID );
  1631. #ifdef DEBUG
  1632. LOG(tQBuf);
  1633. #endif
  1634. result = m_pDatabase->Query( tQBuf );
  1635. if( result!= NULL ) {
  1636. if( result->size() > 0 ) {
  1637. Assoc *cArr;
  1638. tVal = (DBC_LRF_DATA*) malloc(sizeof(DBC_LRF_DATA));
  1639. if( tVal != NULL ) {
  1640. memset( tVal, 0 , sizeof(DBC_LRF_DATA));
  1641. Assoc::iterator it;
  1642. tVal->id = ID;
  1643. cArr = result->at(0);
  1644. it = cArr->find("data_status");
  1645. if( it != cArr->end() ){
  1646. tVal->data_status = atoi( it->second.c_str() );
  1647. };
  1648. it = cArr->find("serial");
  1649. if( it != cArr->end() ){
  1650. strncpy( tVal->serial, it->second.c_str(), sizeof(tVal->serial)-1 );
  1651. tVal->serial[sizeof(tVal->serial)-1]=(char)0;
  1652. };
  1653. it = cArr->find("version");
  1654. if( it != cArr->end() ){
  1655. strncpy( tVal->version, it->second.c_str(), sizeof(tVal->version)-1 );
  1656. tVal->version[sizeof(tVal->version)-1]=(char)0;
  1657. };
  1658. it = cArr->find("x");
  1659. if( it != cArr->end() ){
  1660. tVal->x = atof( it->second.c_str() );
  1661. };
  1662. it = cArr->find("y");
  1663. if( it != cArr->end() ){
  1664. tVal->y = atof( it->second.c_str() );
  1665. };
  1666. it = cArr->find("z");
  1667. if( it != cArr->end() ){
  1668. tVal->z = atof( it->second.c_str() );
  1669. };
  1670. it = cArr->find("x_rot");
  1671. if( it != cArr->end() ){
  1672. tVal->x_rot = atof( it->second.c_str() );
  1673. };
  1674. it = cArr->find("y_rot");
  1675. if( it != cArr->end() ){
  1676. tVal->y_rot = atof( it->second.c_str() );
  1677. };
  1678. it = cArr->find("z_rot");
  1679. if( it != cArr->end() ){
  1680. tVal->z_rot = atof( it->second.c_str() );
  1681. };
  1682. it = cArr->find("uart_id");
  1683. if( it != cArr->end() ){
  1684. tVal->uart_id = atoi( it->second.c_str() );
  1685. };
  1686. it = cArr->find("device_id");
  1687. if( it != cArr->end() ){
  1688. tVal->device_id = atoi( it->second.c_str() );
  1689. };
  1690. it = cArr->find("ip_address");
  1691. if( it != cArr->end() ){
  1692. sprintf( tVal->master_host, it->second.c_str() );
  1693. };
  1694. it = cArr->find("aux_ip_address");
  1695. if( it != cArr->end() ){
  1696. sprintf( tVal->slave_host, it->second.c_str() );
  1697. };
  1698. it = cArr->find("port");
  1699. if( it != cArr->end() ){
  1700. tVal->master_port = atoi( it->second.c_str() );
  1701. };
  1702. it = cArr->find("aux_port");
  1703. if( it != cArr->end() ){
  1704. tVal->slave_port = atoi( it->second.c_str() );
  1705. };
  1706. it = cArr->find("auto_draw");
  1707. if( it != cArr->end() ){
  1708. tVal->auto_draw = atoi( it->second.c_str() );
  1709. };
  1710. it = cArr->find("filter_id");
  1711. if( it != cArr->end() ){
  1712. tVal->filter_id = atoi( it->second.c_str() );
  1713. };
  1714. //it = cArr->find("enabled_lrf");
  1715. //if( it != cArr->end() ){
  1716. // tVal->enabled_lrf = atoi( it->second.c_str() );
  1717. //};
  1718. it = cArr->find("max_range");
  1719. if( it != cArr->end() ){
  1720. tVal->max_range = atof( it->second.c_str() );
  1721. };
  1722. it = cArr->find("base_shift");
  1723. if( it != cArr->end() ){
  1724. tVal->base_shift = atoi( it->second.c_str() );
  1725. };
  1726. it = cArr->find("mirror_shift");
  1727. if( it != cArr->end() ){
  1728. tVal->mirror_shift = atoi( it->second.c_str() );
  1729. };
  1730. it = cArr->find("detection_profile_id");
  1731. if( it != cArr->end() ){
  1732. tVal->detection_profile_id = atoi( it->second.c_str() );
  1733. };
  1734. it = cArr->find("draw_lrf_id");
  1735. if( it != cArr->end() ){
  1736. tVal->draw_lrf_id = atoi( it->second.c_str() );
  1737. };
  1738. it = cArr->find("width_table_id");
  1739. if( it != cArr->end() ){
  1740. tVal->width_table_id = atoi( it->second.c_str() );
  1741. };
  1742. it = cArr->find("zoom_table_id");
  1743. if( it != cArr->end() ){
  1744. tVal->zoom_table_id = atoi( it->second.c_str() );
  1745. };
  1746. it = cArr->find("embd_cam");
  1747. if( it != cArr->end() ){
  1748. tVal->embd_cam = atoi( it->second.c_str() );
  1749. };
  1750. it = cArr->find("embd_cam_auto");
  1751. if( it != cArr->end() ){
  1752. tVal->embd_cam_auto = (bool)atoi( it->second.c_str() );
  1753. };
  1754. it = cArr->find("embd_dc");
  1755. if( it != cArr->end() ){
  1756. tVal->embd_dc = atoi( it->second.c_str() );
  1757. };
  1758. it = cArr->find("autoreset");
  1759. if( it != cArr->end() ){
  1760. tVal->autoreset = (bool)atoi( it->second.c_str() );
  1761. };
  1762. it = cArr->find("force_settings");
  1763. if( it != cArr->end() ){
  1764. tVal->force_settings = (bool)atoi( it->second.c_str() );
  1765. };
  1766. };
  1767. };
  1768. };
  1769. deleteResult( result );
  1770. };
  1771. return tVal;
  1772. };
  1773. uint8_t mysqlDBC::getLRFDataStatus( uint32_t ID ){
  1774. uint8_t RetVal = 0;
  1775. if(m_bIsConnected){
  1776. char tQBuf[CTEXT];
  1777. AAssoc *result;
  1778. sprintf(tQBuf, "SELECT `data_status` FROM `lrf_sensors` WHERE `id`=%d", ID );
  1779. #ifdef DEBUG
  1780. LOG(tQBuf);
  1781. #endif
  1782. result = m_pDatabase->Query( tQBuf );
  1783. if( result!= NULL ) {
  1784. if( result->size() > 0 ) {
  1785. Assoc *cArr;
  1786. Assoc::iterator it;
  1787. cArr = result->at(0);
  1788. it = cArr->find("data_status");
  1789. if( it != cArr->end() ){
  1790. RetVal = atoi( it->second.c_str() );
  1791. };
  1792. };
  1793. };
  1794. deleteResult( result );
  1795. };
  1796. return RetVal;
  1797. };
  1798. PLGS_2D_PARAMETERS mysqlDBC::getLRFDetectionProfile( uint32_t lrfID, uint8_t profileID, bool master ){
  1799. PLGS_2D_PARAMETERS retVal = NULL;
  1800. if(m_bIsConnected){
  1801. char tQBuf[CTEXT];
  1802. AAssoc *result;
  1803. sprintf(tQBuf, "SELECT * FROM `lrf_detection_profiles` WHERE `aux_id`=%d AND `profile_id`=%d AND `master`=b'%c'", lrfID, profileID,((master)?'1':'0') );
  1804. #ifdef DEBUG
  1805. LOG(tQBuf);
  1806. #endif
  1807. result = m_pDatabase->Query( tQBuf );
  1808. if( result!= NULL ) {
  1809. if( result->size() > 0 ) {
  1810. retVal = (PLGS_2D_PARAMETERS) malloc(sizeof(LGS_2D_PARAMETERS));
  1811. memset( retVal, 0, sizeof(LGS_2D_PARAMETERS));
  1812. Assoc *cArr;
  1813. Assoc::iterator it;
  1814. cArr = result->at(0);
  1815. it = cArr->find("order");
  1816. if( it != cArr->end() ){
  1817. retVal->nOrder = atoi(it->second.c_str());
  1818. };
  1819. it = cArr->find("offset");
  1820. if( it != cArr->end() ){
  1821. retVal->nOffset = atoi(it->second.c_str());
  1822. };
  1823. it = cArr->find("delta");
  1824. if( it != cArr->end() ){
  1825. retVal->nDelta = atoi(it->second.c_str());
  1826. };
  1827. it = cArr->find("flip");
  1828. if( it != cArr->end() ){
  1829. retVal->nFlip = atoi(it->second.c_str());
  1830. };
  1831. it = cArr->find("width");
  1832. if( it != cArr->end() ){
  1833. retVal->nWidth = atoi(it->second.c_str());
  1834. };
  1835. it = cArr->find("sst");
  1836. if( it != cArr->end() ){
  1837. retVal->bSST = atoi(it->second.c_str());
  1838. };
  1839. it = cArr->find("sun");
  1840. if( it != cArr->end() ){
  1841. retVal->nSun = atoi(it->second.c_str());
  1842. };
  1843. };
  1844. };
  1845. deleteResult( result );
  1846. };
  1847. return retVal;
  1848. };
  1849. CSTR mysqlDBC::getLRFDraw( uint32_t DBID ){
  1850. CSTR RetVal = NULL;
  1851. if(m_bIsConnected){
  1852. char tQBuf[CTEXT];
  1853. AAssoc *result;
  1854. sprintf(tQBuf, "SELECT `md5` FROM `lrf_draw` WHERE `node_id`=%d", DBID );
  1855. #ifdef DEBUG
  1856. LOG(tQBuf);
  1857. #endif
  1858. result = m_pDatabase->Query( tQBuf );
  1859. if( result!= NULL ) {
  1860. if( result->size() > 0 ) {
  1861. Assoc *cArr;
  1862. Assoc::iterator it;
  1863. cArr = result->at(0);
  1864. it = cArr->find("md5");
  1865. if( it != cArr->end() ){
  1866. RetVal = strdup( it->second.c_str() );
  1867. };
  1868. };
  1869. };
  1870. deleteResult( result );
  1871. };
  1872. return RetVal;
  1873. };
  1874. uint32_t mysqlDBC::getLRFMaskID( uint32_t deviceID, uint8_t lrfID, uint8_t layer ){
  1875. uint32_t RetVal = 0;
  1876. if(m_bIsConnected){
  1877. char tQBuf[CTEXT];
  1878. AAssoc *result;
  1879. sprintf(tQBuf, "SELECT `id` FROM `lrf_masks` WHERE `sensor_id`=%d AND `lrf_id`=%d AND `layer`=%d ", deviceID, lrfID, layer );
  1880. #ifdef DEBUG
  1881. LOG(tQBuf);
  1882. #endif
  1883. result = m_pDatabase->Query( tQBuf );
  1884. if( result!= NULL ) {
  1885. if( result->size() > 0 ) {
  1886. Assoc *cArr;
  1887. Assoc::iterator it;
  1888. cArr = result->at(0);
  1889. it = cArr->find("id");
  1890. if( it != cArr->end() ){
  1891. RetVal = atoi( it->second.c_str() );
  1892. };
  1893. };
  1894. };
  1895. deleteResult( result );
  1896. };
  1897. return RetVal;
  1898. };
  1899. /*
  1900. DBC_PUSHED_CMD *mysqlDBC::getLRFPushedCMD( uint32_t ID ){
  1901. DBC_PUSHED_CMD *RetVal = NULL;
  1902. if(m_bIsConnected){
  1903. char tQBuf[CTEXT];
  1904. AAssoc *result;
  1905. sprintf(tQBuf, "SELECT `pushed_cmd`, `pushed_param` FROM `lrf_sensors` WHERE `id`=%d AND `pushed_cmd` > 0", ID );
  1906. #ifdef DEBUG
  1907. //LOG(tQBuf);
  1908. #endif
  1909. result = m_pDatabase->Query( tQBuf );
  1910. if( result!= NULL ) {
  1911. if( result->size() > 0 ) {
  1912. RetVal = (DBC_PUSHED_CMD*)malloc(sizeof(DBC_PUSHED_CMD));
  1913. if( RetVal ) {
  1914. Assoc *cArr;
  1915. Assoc::iterator it;
  1916. cArr = result->at(0);
  1917. it = cArr->find("pushed_cmd");
  1918. if( it != cArr->end() ){
  1919. RetVal->CMD = atoi( it->second.c_str() );
  1920. };
  1921. it = cArr->find("pushed_param");
  1922. if( it != cArr->end() ){
  1923. RetVal->PARAM = atoi( it->second.c_str() );
  1924. };
  1925. };
  1926. };
  1927. //Only If Result is Fetched - Clear Current CMD
  1928. sprintf(tQBuf, "UPDATE `lrf_sensors` SET `pushed_cmd`=0, `pushed_param`=0 WHERE `id`=%d", ID );
  1929. m_pDatabase->SilentQuery( tQBuf );
  1930. };
  1931. deleteResult( result );
  1932. };
  1933. return RetVal;
  1934. };
  1935. */
  1936. DBC_INT_LIST *mysqlDBC::listModules(){
  1937. DBC_INT_LIST * tVal = NULL;
  1938. if(m_bIsConnected){
  1939. char tQBuf[CTEXT];
  1940. AAssoc *result;
  1941. sprintf(tQBuf, "SELECT `id` FROM `server_modules` WHERE `server_id`=%d AND `enabled`=1", m_nServerID );
  1942. #ifdef DEBUG_ALL
  1943. LOG(tQBuf);
  1944. #endif
  1945. result = m_pDatabase->Query( tQBuf );
  1946. if( result!= NULL ) {
  1947. if( result->size() > 0 ) {
  1948. Assoc *cArr;
  1949. tVal = new DBC_INT_LIST();
  1950. if( tVal != NULL ) {
  1951. Assoc::iterator it;
  1952. for(int i=0;i<result->size();i++) {
  1953. cArr = result->at(i);
  1954. it = cArr->find("id");
  1955. if( it != cArr->end() ){
  1956. tVal->push_back( atoi( it->second.c_str() ));
  1957. };
  1958. };
  1959. };
  1960. };
  1961. };
  1962. deleteResult( result );
  1963. };
  1964. return tVal;
  1965. };
  1966. DBC_INT_LIST *mysqlDBC::listFilters( uint32_t ServerID ){
  1967. DBC_INT_LIST * tVal = NULL;
  1968. if(m_bIsConnected){
  1969. char tQBuf[CTEXT];
  1970. AAssoc *result;
  1971. sprintf(tQBuf, "SELECT `id` FROM `target_filters` WHERE `server_id`=%d AND `enabled`=1", ServerID );
  1972. #ifdef DEBUG_ALL
  1973. LOG(tQBuf);
  1974. #endif
  1975. result = m_pDatabase->Query( tQBuf );
  1976. if( result!= NULL ) {
  1977. if( result->size() > 0 ) {
  1978. Assoc *cArr;
  1979. tVal = new DBC_INT_LIST();
  1980. if( tVal != NULL ) {
  1981. Assoc::iterator it;
  1982. for(int i=0;i<result->size();i++) {
  1983. cArr = result->at(i);
  1984. it = cArr->find("id");
  1985. if( it != cArr->end() ){
  1986. tVal->push_back( atoi( it->second.c_str() ));
  1987. };
  1988. };
  1989. };
  1990. };
  1991. };
  1992. deleteResult( result );
  1993. };
  1994. return tVal;
  1995. };
  1996. DBC_INT_LIST *mysqlDBC::listLRFMaskVertexes( uint32_t MaskID ){
  1997. DBC_INT_LIST * tVal = NULL;
  1998. if(m_bIsConnected){
  1999. char tQBuf[CTEXT];
  2000. AAssoc *result;
  2001. sprintf(tQBuf, "SELECT `id` FROM `lrf_mask_vertexes` WHERE `mask_id`=%d", MaskID );
  2002. #ifdef DEBUG_ALL
  2003. LOG(tQBuf);
  2004. #endif
  2005. result = m_pDatabase->Query( tQBuf );
  2006. if( result!= NULL ) {
  2007. if( result->size() > 0 ) {
  2008. Assoc *cArr;
  2009. tVal = new DBC_INT_LIST();
  2010. if( tVal != NULL ) {
  2011. Assoc::iterator it;
  2012. for(int i=0;i<result->size();i++) {
  2013. cArr = result->at(i);
  2014. it = cArr->find("id");
  2015. if( it != cArr->end() ){
  2016. tVal->push_back( atoi( it->second.c_str() ));
  2017. };
  2018. };
  2019. };
  2020. };
  2021. };
  2022. deleteResult( result );
  2023. };
  2024. return tVal;
  2025. };
  2026. DBC_INT_LIST *mysqlDBC::listLRFMaskVertexPoints( uint32_t VertexID ){
  2027. DBC_INT_LIST * tVal = NULL;
  2028. if(m_bIsConnected){
  2029. char tQBuf[CTEXT];
  2030. AAssoc *result;
  2031. sprintf(tQBuf, "SELECT `id` FROM `lrf_mask_vertex_points` WHERE `vertex_id`=%d ORDER BY `id`", VertexID );
  2032. #ifdef DEBUG_ALL
  2033. LOG(tQBuf);
  2034. #endif
  2035. result = m_pDatabase->Query( tQBuf );
  2036. if( result!= NULL ) {
  2037. if( result->size() > 0 ) {
  2038. Assoc *cArr;
  2039. tVal = new DBC_INT_LIST();
  2040. if( tVal != NULL ) {
  2041. Assoc::iterator it;
  2042. for(int i=0;i<result->size();i++) {
  2043. cArr = result->at(i);
  2044. it = cArr->find("id");
  2045. if( it != cArr->end() ){
  2046. tVal->push_back( atoi( it->second.c_str() ));
  2047. };
  2048. };
  2049. };
  2050. };
  2051. };
  2052. deleteResult( result );
  2053. };
  2054. return tVal;
  2055. };
  2056. DBC_INT_LIST *mysqlDBC::listMediaServerStreams( uint32_t SiteId, uint32_t MediaServerID, uint8_t listMode ){
  2057. DBC_INT_LIST * tVal = NULL;
  2058. if(m_bIsConnected){
  2059. char tQBuf[CTEXT];
  2060. AAssoc *result;
  2061. switch( listMode ){
  2062. case LIST_VALID_RECORDS: sprintf(tQBuf, "SELECT id FROM media_server_streams WHERE `valid`=1 AND `site_id`=%d AND `media_server_id`=%d", SiteId, MediaServerID ); break;
  2063. case LIST_INVALID_RECORDS: sprintf(tQBuf, "SELECT id FROM media_server_streams WHERE `valid`=0 AND `site_id`=%d AND `media_server_id`=%d", SiteId, MediaServerID ); break;
  2064. default: sprintf(tQBuf, "SELECT id FROM media_server_streams WHERE `site_id`=%d AND `media_server_id`=%d", SiteId, MediaServerID );
  2065. };
  2066. #ifdef DEBUG_ALL
  2067. LOG(tQBuf);
  2068. #endif
  2069. result = m_pDatabase->Query( tQBuf );
  2070. if( result!= NULL ) {
  2071. if( result->size() > 0 ) {
  2072. Assoc *cArr;
  2073. tVal = new DBC_INT_LIST();
  2074. if( tVal != NULL ) {
  2075. Assoc::iterator it;
  2076. for(int i=0;i<result->size();i++) {
  2077. cArr = result->at(i);
  2078. it = cArr->find("id");
  2079. if( it != cArr->end() ){
  2080. tVal->push_back( atoi( it->second.c_str() ));
  2081. };
  2082. };
  2083. };
  2084. };
  2085. };
  2086. deleteResult( result );
  2087. };
  2088. return tVal;
  2089. };
  2090. DBC_INT_LIST *mysqlDBC::listMediaStreams( uint32_t SiteId, uint8_t listMode ){
  2091. DBC_INT_LIST * tVal = NULL;
  2092. if(m_bIsConnected){
  2093. char tQBuf[CTEXT];
  2094. AAssoc *result;
  2095. switch( listMode ){
  2096. case LIST_VALID_RECORDS:
  2097. sprintf(tQBuf, "SELECT `ms`.`id` FROM `nodes` `nd` LEFT JOIN `media_streams` `ms` ON (`ms`.`id`=`nd`.`aux_parameter`) WHERE `nd`.`type` IN (10,11,12,13) AND `nd`.`site_id`=%d AND `ms`.`valid`=1 AND `nd`.`online`=1", SiteId );
  2098. break;
  2099. case LIST_INVALID_RECORDS:
  2100. sprintf(tQBuf, "SELECT `ms`.`id` FROM `nodes` `nd` LEFT JOIN `media_streams` `ms` ON (`ms`.`id`=`nd`.`aux_parameter`) WHERE `nd`.`type` IN (10,11,12,13) AND `nd`.`site_id`=%d AND `ms`.`valid`=1 AND `nd`.`online`=0", SiteId );
  2101. break;
  2102. default:
  2103. sprintf(tQBuf, "SELECT `ms`.`id` FROM `nodes` `nd` LEFT JOIN `media_streams` `ms` ON (`ms`.`id`=`nd`.`aux_parameter`) WHERE `nd`.`type` IN (10,11,12,13) AND `nd`.`site_id`=%d AND `ms`.`valid`=1", SiteId );
  2104. };
  2105. #ifdef DEBUG_ALL
  2106. LOG(tQBuf);
  2107. #endif
  2108. result = m_pDatabase->Query( tQBuf );
  2109. if( result!= NULL ) {
  2110. if( result->size() > 0 ) {
  2111. Assoc *cArr;
  2112. tVal = new DBC_INT_LIST();
  2113. if( tVal != NULL ) {
  2114. Assoc::iterator it;
  2115. for(int i=0;i<result->size();i++) {
  2116. cArr = result->at(i);
  2117. it = cArr->find("id");
  2118. if( it != cArr->end() ){
  2119. tVal->push_back( atoi( it->second.c_str() ));
  2120. };
  2121. };
  2122. };
  2123. };
  2124. };
  2125. deleteResult( result );
  2126. };
  2127. return tVal;
  2128. };
  2129. DBC_INT_LIST *mysqlDBC::listDetectionProfileIDs( uint32_t nodeID ){
  2130. DBC_INT_LIST * tVal = NULL;
  2131. if(m_bIsConnected){
  2132. char tQBuf[CTEXT];
  2133. AAssoc *result;
  2134. sprintf(tQBuf, "SELECT `profile_id` FROM `lrf_detection_profiles` WHERE `aux_id`=%d ", nodeID );
  2135. #ifdef DEBUG_ALL
  2136. LOG(tQBuf);
  2137. #endif
  2138. result = m_pDatabase->Query( tQBuf );
  2139. if( result!= NULL ) {
  2140. if( result->size() > 0 ) {
  2141. Assoc *cArr;
  2142. tVal = new DBC_INT_LIST();
  2143. if( tVal != NULL ) {
  2144. Assoc::iterator it;
  2145. for(int i=0;i<result->size();i++) {
  2146. cArr = result->at(i);
  2147. it = cArr->find("profile_id");
  2148. if( it != cArr->end() ){
  2149. tVal->push_back( atoi( it->second.c_str() ));
  2150. };
  2151. };
  2152. };
  2153. };
  2154. };
  2155. deleteResult( result );
  2156. };
  2157. return tVal;
  2158. };
  2159. DBC_INT_LIST *mysqlDBC::listDetectionProfiles( uint32_t nodeID ){
  2160. DBC_INT_LIST * tVal = NULL;
  2161. if(m_bIsConnected){
  2162. char tQBuf[CTEXT];
  2163. AAssoc *result;
  2164. sprintf(tQBuf, "SELECT `id` FROM `lrf_detection_profiles` WHERE `aux_id`=%d ", nodeID );
  2165. #ifdef DEBUG_ALL
  2166. LOG(tQBuf);
  2167. #endif
  2168. result = m_pDatabase->Query( tQBuf );
  2169. if( result!= NULL ) {
  2170. if( result->size() > 0 ) {
  2171. Assoc *cArr;
  2172. tVal = new DBC_INT_LIST();
  2173. if( tVal != NULL ) {
  2174. Assoc::iterator it;
  2175. for(int i=0;i<result->size();i++) {
  2176. cArr = result->at(i);
  2177. it = cArr->find("id");
  2178. if( it != cArr->end() ){
  2179. tVal->push_back( atoi( it->second.c_str() ));
  2180. };
  2181. };
  2182. };
  2183. };
  2184. };
  2185. deleteResult( result );
  2186. };
  2187. return tVal;
  2188. };
  2189. /*
  2190. DBC_INT_LIST *mysqlDBC::listSockets( uint32_t NodeID ){
  2191. DBC_INT_LIST * tVal = NULL;
  2192. if(m_bIsConnected){
  2193. char tQBuf[CTEXT];
  2194. AAssoc *result;
  2195. sprintf(tQBuf, "SELECT id FROM sockets WHERE `node_id`=%d", NodeID );
  2196. #ifdef DEBUG
  2197. LOG(tQBuf);
  2198. #endif
  2199. result = m_pDatabase->Query( tQBuf );
  2200. if( result!= NULL ) {
  2201. if( result->size() > 0 ) {
  2202. Assoc *cArr;
  2203. tVal = new DBC_INT_LIST();
  2204. if( tVal != NULL ) {
  2205. Assoc::iterator it;
  2206. for(int i=0;i<result->size();i++) {
  2207. cArr = result->at(i);
  2208. it = cArr->find("id");
  2209. if( it != cArr->end() ){
  2210. tVal->push_back( atoi( it->second.c_str() ));
  2211. };
  2212. };
  2213. };
  2214. };
  2215. };
  2216. deleteResult( result );
  2217. };
  2218. return tVal;
  2219. };
  2220. */
  2221. DBC_INT_LIST *mysqlDBC::listResources( uint32_t NodeID ){
  2222. DBC_INT_LIST * tVal = NULL;
  2223. if(m_bIsConnected){
  2224. char tQBuf[CTEXT];
  2225. AAssoc *result;
  2226. if( NodeID ) {
  2227. sprintf(tQBuf, "SELECT `id` FROM `resources` WHERE `node_id`=%d AND `active`=1 AND `used`=1", NodeID );
  2228. } else {
  2229. sprintf(tQBuf, "SELECT `re`.`id` FROM `resources` `re` LEFT JOIN `nodes` `no` ON( `re`.`node_id` = `no`.`id` ) WHERE `no`.`site_id`=%d AND `re`.`used`=1", m_nSiteID );// AND `re`.`active`=1", m_nSiteID );
  2230. };
  2231. #ifdef DEBUG
  2232. LOG(tQBuf);
  2233. #endif
  2234. result = m_pDatabase->Query( tQBuf );
  2235. if( result!= NULL ) {
  2236. if( result->size() > 0 ) {
  2237. Assoc *cArr;
  2238. tVal = new DBC_INT_LIST();
  2239. if( tVal != NULL ) {
  2240. Assoc::iterator it;
  2241. for(int i=0;i<result->size();i++) {
  2242. cArr = result->at(i);
  2243. it = cArr->find("id");
  2244. if( it != cArr->end() ){
  2245. tVal->push_back( atoi( it->second.c_str() ));
  2246. };
  2247. };
  2248. };
  2249. };
  2250. };
  2251. deleteResult( result );
  2252. };
  2253. return tVal;
  2254. };
  2255. simplePolygone *mysqlDBC::loadLRFMaskVertex( uint32_t vid ){
  2256. simplePolygone *tVal = NULL;
  2257. if(m_bIsConnected){
  2258. char tQBuf[CTEXT];
  2259. AAssoc *result;
  2260. sprintf(tQBuf, "SELECT * FROM `lrf_mask_vertexes` WHERE `id`=%d", vid );
  2261. #ifdef DEBUG
  2262. LOG(tQBuf);
  2263. #endif
  2264. result = m_pDatabase->Query( tQBuf );
  2265. if( result!= NULL ) {
  2266. if( result->size() > 0 ) {
  2267. tVal = (simplePolygone *) malloc(sizeof(simplePolygone));
  2268. if ( tVal ) {
  2269. Assoc * cArr;
  2270. memset( tVal, 0, sizeof(simplePolygone));
  2271. Assoc::iterator it;
  2272. cArr = result->at(0);
  2273. it = cArr->find("r");
  2274. if( it != cArr->end() ){
  2275. tVal->color[0] = atoi( it->second.c_str() );
  2276. };
  2277. it = cArr->find("g");
  2278. if( it != cArr->end() ){
  2279. tVal->color[1] = atoi( it->second.c_str() );
  2280. };
  2281. it = cArr->find("b");
  2282. if( it != cArr->end() ){
  2283. tVal->color[2] = atoi( it->second.c_str() );
  2284. };
  2285. AAssoc *points;
  2286. sprintf(tQBuf, "SELECT * FROM `lrf_mask_vertex_points` WHERE `vertex_id`=%d ORDER BY `id`", vid );
  2287. #ifdef DEBUG
  2288. LOG(tQBuf);
  2289. #endif
  2290. points = m_pDatabase->Query( tQBuf );
  2291. if( points!= NULL ) {
  2292. if ( points->size() ) {
  2293. tVal->count = points->size();
  2294. tVal->points = (simplePoint *) calloc( points->size(), sizeof(simplePoint) );
  2295. if( tVal->points!= NULL ) {
  2296. for (int i = 0; i < points->size(); i++) {
  2297. cArr = points->at( i );
  2298. it = cArr->find("x");
  2299. if( it != cArr->end() ){
  2300. tVal->points[i].setX( atoi( it->second.c_str() ) );
  2301. };
  2302. it = cArr->find("y");
  2303. if( it != cArr->end() ){
  2304. tVal->points[i].setY( atoi( it->second.c_str() ) );
  2305. };
  2306. };
  2307. };
  2308. };
  2309. };
  2310. deleteResult( points );
  2311. };
  2312. };
  2313. };
  2314. deleteResult( result );
  2315. };
  2316. return tVal;
  2317. };
  2318. DBC_INT_LIST *mysqlDBC::listNetworks( uint32_t nif_id ){
  2319. DBC_INT_LIST * tVal = NULL;
  2320. if(m_bIsConnected){
  2321. char tQBuf[CTEXT];
  2322. AAssoc *result;
  2323. sprintf(tQBuf, "SELECT `id` FROM `networks` WHERE `nif_id`=%d", nif_id );
  2324. #ifdef DEBUG_ALL
  2325. LOG(tQBuf);
  2326. #endif
  2327. result = m_pDatabase->Query( tQBuf );
  2328. if( result!= NULL ) {
  2329. if( result->size() > 0 ) {
  2330. Assoc *cArr;
  2331. tVal = new DBC_INT_LIST();
  2332. if( tVal != NULL ) {
  2333. Assoc::iterator it;
  2334. for(int i=0;i<result->size();i++) {
  2335. cArr = result->at(i);
  2336. it = cArr->find("id");
  2337. if( it != cArr->end() ){
  2338. tVal->push_back( atoi( it->second.c_str() ));
  2339. };
  2340. };
  2341. };
  2342. };
  2343. };
  2344. deleteResult( result );
  2345. };
  2346. return tVal;
  2347. };
  2348. DBC_INT_LIST *mysqlDBC::listNewModules( DBC_INT_LIST * old_ids ){
  2349. DBC_INT_LIST * tVal = NULL;
  2350. char tParam[CTEXT];
  2351. //memset( tParam, 0, CTEXT );
  2352. sprintf(tParam,"0");
  2353. if( old_ids != NULL ) {
  2354. char tBuffer[CTEXT];
  2355. for(int i = 0; i< old_ids->size(); i++ ) {
  2356. sprintf( tBuffer, "%s,%d", tParam, old_ids->at(i) );
  2357. strncpy( tParam, tBuffer, CTEXT );
  2358. };
  2359. };
  2360. if(m_bIsConnected){
  2361. char tQBuf[CTEXT];
  2362. AAssoc *result;
  2363. sprintf(tQBuf, "SELECT `id` FROM `server_modules` WHERE `server_id`=%d AND `enabled`=1 AND `id` NOT IN (%s)", m_nServerID, tParam );
  2364. #ifdef DEBUG_ALL
  2365. LOG(tQBuf);
  2366. #endif
  2367. result = m_pDatabase->Query( tQBuf );
  2368. if( result!= NULL ) {
  2369. if( result->size() > 0 ) {
  2370. Assoc *cArr;
  2371. tVal = new DBC_INT_LIST();
  2372. if( tVal != NULL ) {
  2373. Assoc::iterator it;
  2374. for(int i=0;i<result->size();i++) {
  2375. cArr = result->at(i);
  2376. it = cArr->find("id");
  2377. if( it != cArr->end() ){
  2378. tVal->push_back( atoi( it->second.c_str() ));
  2379. };
  2380. };
  2381. };
  2382. };
  2383. };
  2384. deleteResult( result );
  2385. };
  2386. return tVal;
  2387. };
  2388. uint32_t mysqlDBC::getCamId( CSTR UUID ){
  2389. uint32_t RetVal = 0;
  2390. if(m_bIsConnected){
  2391. char tQBuf[CTEXT];
  2392. AAssoc *result;
  2393. sprintf(tQBuf, "SELECT id FROM cameras WHERE `uuid`='%s'", UUID );
  2394. #ifdef DEBUG_ALL
  2395. LOG(tQBuf);
  2396. #endif
  2397. result = m_pDatabase->Query( tQBuf );
  2398. if( result!= NULL ) {
  2399. if( result->size() > 0 ) {
  2400. Assoc *cArr;
  2401. Assoc::iterator it;
  2402. cArr = result->at(0);
  2403. it = cArr->find("id");
  2404. if( it != cArr->end() ){
  2405. RetVal = atoi( it->second.c_str() );
  2406. };
  2407. };
  2408. };
  2409. deleteResult( result );
  2410. };
  2411. return RetVal;
  2412. };
  2413. DBC_CAP_DATA *mysqlDBC::getCamCapPictureData( uint32_t PicID ){
  2414. DBC_CAP_DATA *tVal = NULL;
  2415. if(m_bIsConnected){
  2416. char tQBuf[CTEXT];
  2417. AAssoc *result;
  2418. sprintf(tQBuf, "SELECT md5, ext FROM pictures WHERE `id`=%d", PicID );
  2419. #ifdef DEBUG_ALL
  2420. LOG(tQBuf);
  2421. #endif
  2422. result = m_pDatabase->Query( tQBuf );
  2423. if( result!= NULL ) {
  2424. if( result->size() > 0 ) {
  2425. Assoc *cArr;
  2426. tVal = (DBC_CAP_DATA*) malloc(sizeof(DBC_CAP_DATA));
  2427. if( tVal != NULL ) {
  2428. memset( tVal, 0 , sizeof(DBC_CAP_DATA));
  2429. Assoc::iterator it;
  2430. cArr = result->at(0);
  2431. it = cArr->find("md5");
  2432. if( it != cArr->end() ){
  2433. strncpy(tVal->md5, it->second.c_str(), 32);
  2434. };
  2435. it = cArr->find("ext");
  2436. if( it != cArr->end() ){
  2437. strncpy(tVal->ext, it->second.c_str(), 3 );
  2438. };
  2439. };
  2440. };
  2441. };
  2442. deleteResult( result );
  2443. };
  2444. return tVal;
  2445. };
  2446. DBC_CAM_DATA *mysqlDBC::getCamData( uint32_t ID ){
  2447. DBC_CAM_DATA *tVal = NULL;
  2448. if(m_bIsConnected){
  2449. char tQBuf[CTEXT];
  2450. AAssoc *result;
  2451. sprintf(tQBuf, "SELECT * FROM cameras WHERE `id`=%d", ID );
  2452. #ifdef DEBUG_ALL
  2453. LOG(tQBuf);
  2454. #endif
  2455. result = m_pDatabase->Query( tQBuf );
  2456. if( result!= NULL ) {
  2457. if( result->size() > 0 ) {
  2458. Assoc *cArr;
  2459. tVal = (DBC_CAM_DATA*) malloc(sizeof(DBC_CAM_DATA));
  2460. if( tVal != NULL ) {
  2461. memset( tVal, 0 , sizeof(DBC_CAM_DATA));
  2462. tVal->id = ID;
  2463. Assoc::iterator it;
  2464. cArr = result->at(0);
  2465. it = cArr->find("type");
  2466. if( it != cArr->end() ){
  2467. tVal->type = atoi( it->second.c_str() );
  2468. };
  2469. it = cArr->find("online");
  2470. if( it != cArr->end() ){
  2471. tVal->online = (bool) atoi( it->second.c_str() );
  2472. };
  2473. it = cArr->find("stream_id");
  2474. if( it != cArr->end() ){
  2475. tVal->stream_id = atoi( it->second.c_str() );
  2476. };
  2477. it = cArr->find("hardware");
  2478. if( it != cArr->end() ){
  2479. strncpy( tVal->hardware, it->second.c_str(), 32 );
  2480. };
  2481. it = cArr->find("name");
  2482. if( it != cArr->end() ){
  2483. strncpy( tVal->name, it->second.c_str(), 64 );
  2484. };
  2485. it = cArr->find("status");
  2486. if( it != cArr->end() ){
  2487. tVal->status = atoi( it->second.c_str() );
  2488. };
  2489. it = cArr->find("session");
  2490. if( it != cArr->end() ){
  2491. strncpy( tVal->session, it->second.c_str(), 32 );
  2492. };
  2493. it = cArr->find("protocol");
  2494. if( it != cArr->end() ){
  2495. tVal->protocol = atoi( it->second.c_str() );
  2496. };
  2497. it = cArr->find("protocol_aux");
  2498. if( it != cArr->end() ){
  2499. tVal->protocol_aux = atoi( it->second.c_str() );
  2500. };
  2501. it = cArr->find("uart_id");
  2502. if( it != cArr->end() ){
  2503. tVal->uart_id = atoi( it->second.c_str() );
  2504. };
  2505. it = cArr->find("x");
  2506. if( it != cArr->end() ){
  2507. tVal->x = atof( it->second.c_str() );
  2508. };
  2509. it = cArr->find("y");
  2510. if( it != cArr->end() ){
  2511. tVal->y = atof( it->second.c_str() );
  2512. };
  2513. it = cArr->find("z");
  2514. if( it != cArr->end() ){
  2515. tVal->z = atof( it->second.c_str() );
  2516. };
  2517. it = cArr->find("x_rot");
  2518. if( it != cArr->end() ){
  2519. tVal->x_rot = atof( it->second.c_str() );
  2520. };
  2521. it = cArr->find("y_rot");
  2522. if( it != cArr->end() ){
  2523. tVal->y_rot = atof( it->second.c_str() );
  2524. };
  2525. it = cArr->find("z_rot");
  2526. if( it != cArr->end() ){
  2527. tVal->z_rot = atof( it->second.c_str() );
  2528. };
  2529. it = cArr->find("imager_type");
  2530. if( it != cArr->end() ){
  2531. tVal->imager_type = atoi( it->second.c_str() );
  2532. };
  2533. it = cArr->find("lens_f");
  2534. if( it != cArr->end() ){
  2535. tVal->lens_f = atoi( it->second.c_str() );
  2536. };
  2537. it = cArr->find("ptz_speed_step");
  2538. if( it != cArr->end() ){
  2539. tVal->ptz_speed_step = atof( it->second.c_str() );
  2540. };
  2541. it = cArr->find("pan_model");
  2542. if( it != cArr->end() ){
  2543. tVal->pan_model = atoi( it->second.c_str() );
  2544. };
  2545. it = cArr->find("pan_angles");
  2546. if( it != cArr->end() ){
  2547. tVal->pan_angles = atoi( it->second.c_str() );
  2548. };
  2549. it = cArr->find("tilt_model");
  2550. if( it != cArr->end() ){
  2551. tVal->tilt_model = atoi( it->second.c_str() );
  2552. };
  2553. it = cArr->find("tilt_angles");
  2554. if( it != cArr->end() ){
  2555. tVal->tilt_angles = atoi( it->second.c_str() );
  2556. };
  2557. it = cArr->find("zoom_model");
  2558. if( it != cArr->end() ){
  2559. tVal->zoom_model = atoi( it->second.c_str() );
  2560. };
  2561. it = cArr->find("zoom");
  2562. if( it != cArr->end() ){
  2563. tVal->zoom = atof( it->second.c_str() );
  2564. };
  2565. //it = cArr->find("max_range");
  2566. //if( it != cArr->end() ){
  2567. // tVal->max_range = atof( it->second.c_str() );
  2568. //};
  2569. it = cArr->find("access_login");
  2570. if( it != cArr->end() ){
  2571. strncpy( tVal->username, it->second.c_str(), 16 );
  2572. };
  2573. it = cArr->find("access_pass");
  2574. if( it != cArr->end() ){
  2575. strncpy( tVal->password, it->second.c_str(), 16 );
  2576. };
  2577. it = cArr->find("uuid");
  2578. if( it != cArr->end() ){
  2579. strncpy( tVal->uuid, it->second.c_str(), 64 );
  2580. };
  2581. it = cArr->find("mac");
  2582. if( it != cArr->end() ){
  2583. strncpy( tVal->mac, it->second.c_str(), 16 );
  2584. };
  2585. it = cArr->find("ip");
  2586. if( it != cArr->end() ){
  2587. strncpy( tVal->ip, it->second.c_str(), 16 );
  2588. };
  2589. it = cArr->find("port");
  2590. if( it != cArr->end() ){
  2591. tVal->port = atoi( it->second.c_str() );
  2592. };
  2593. it = cArr->find("onvif_access");
  2594. if( it != cArr->end() ){
  2595. strncpy( tVal->onvif_access, it->second.c_str(), 5);
  2596. };
  2597. it = cArr->find("onvif_ctrl");
  2598. if( it != cArr->end() ){
  2599. strncpy( tVal->onvif_ctrl, it->second.c_str(), 250);
  2600. };
  2601. it = cArr->find("ptz_token");
  2602. if( it != cArr->end() ){
  2603. strncpy( tVal->ptz_token, it->second.c_str(), 64);
  2604. };
  2605. it = cArr->find("trigger_mode");
  2606. if( it != cArr->end() ){
  2607. tVal->triggering_mode = atoi( it->second.c_str() );
  2608. };
  2609. it = cArr->find("auth_mode");
  2610. if( it != cArr->end() ){
  2611. tVal->auth_mode = atoi( it->second.c_str() );
  2612. };
  2613. };
  2614. };
  2615. };
  2616. deleteResult( result );
  2617. };
  2618. return tVal;
  2619. };
  2620. DBC_PUSHED_CMD *mysqlDBC::getActivePushedCMD( uint32_t NodeID ){
  2621. DBC_PUSHED_CMD *RetVal = NULL;
  2622. if(m_bIsConnected){
  2623. char tQBuf[CTEXT];
  2624. AAssoc *result;
  2625. sprintf(tQBuf, "SELECT * FROM `nodes_qcq` WHERE `node_id`=%d AND `status` > 0 AND `status` < 100", NodeID );
  2626. #ifdef DEBUG_ALL
  2627. LOG(tQBuf);
  2628. #endif
  2629. result = m_pDatabase->Query( tQBuf );
  2630. if( result!= NULL ) {
  2631. if( result->size() > 0 ) {
  2632. RetVal = (DBC_PUSHED_CMD*)malloc(sizeof(DBC_PUSHED_CMD));
  2633. if( RetVal ) {
  2634. Assoc * cArr;
  2635. Assoc::iterator it;
  2636. memset( RetVal, 0, sizeof(DBC_PUSHED_CMD));
  2637. cArr = result->at(0);
  2638. it = cArr->find("id");
  2639. if( it != cArr->end() ){
  2640. RetVal->id = atoi( it->second.c_str() );
  2641. };
  2642. it = cArr->find("cmd");
  2643. if( it != cArr->end() ){
  2644. RetVal->CMD = atoi( it->second.c_str() );
  2645. };
  2646. it = cArr->find("parameter");
  2647. if( it != cArr->end() ){
  2648. strncpy( RetVal->PARAM, it->second.c_str(), 256 );
  2649. RetVal->PARAM[255] = (char)0;
  2650. };
  2651. };
  2652. };
  2653. };
  2654. deleteResult( result );
  2655. };
  2656. return RetVal;
  2657. };
  2658. DBC_PUSHED_CMD *mysqlDBC::getPushedCMD( uint32_t CmdID ){
  2659. DBC_PUSHED_CMD *RetVal = NULL;
  2660. if(m_bIsConnected){
  2661. char tQBuf[CTEXT];
  2662. AAssoc *result;
  2663. sprintf(tQBuf, "SELECT * FROM `nodes_qcq` WHERE `id`=%d", CmdID );
  2664. #ifdef DEBUG_ALL
  2665. LOG(tQBuf);
  2666. #endif
  2667. result = m_pDatabase->Query( tQBuf );
  2668. if( result!= NULL ) {
  2669. if( result->size() > 0 ) {
  2670. RetVal = (DBC_PUSHED_CMD*)malloc(sizeof(DBC_PUSHED_CMD));
  2671. if( RetVal ) {
  2672. Assoc * cArr;
  2673. Assoc::iterator it;
  2674. memset( RetVal, 0, sizeof(DBC_PUSHED_CMD));
  2675. cArr = result->at(0);
  2676. it = cArr->find("id");
  2677. if( it != cArr->end() ){
  2678. RetVal->id = atoi( it->second.c_str() );
  2679. };
  2680. it = cArr->find("cmd");
  2681. if( it != cArr->end() ){
  2682. RetVal->CMD = atoi( it->second.c_str() );
  2683. };
  2684. it = cArr->find("parameter");
  2685. if( it != cArr->end() ){
  2686. strncpy( RetVal->PARAM, it->second.c_str(), 256 );
  2687. RetVal->PARAM[255] = (char)0;
  2688. };
  2689. };
  2690. };
  2691. };
  2692. deleteResult( result );
  2693. };
  2694. return RetVal;
  2695. };
  2696. DBC_PUSHED_CMD *mysqlDBC::getNodePushedCMD( uint32_t NodeID ){
  2697. DBC_PUSHED_CMD *RetVal = NULL;
  2698. if(m_bIsConnected){
  2699. char tQBuf[CTEXT];
  2700. AAssoc *result;
  2701. sprintf(tQBuf, "SELECT * FROM `nodes_qcq` WHERE `node_id`=%d AND `status`=0 LIMIT 1", NodeID );
  2702. #ifdef DEBUG_ALL
  2703. LOG(tQBuf);
  2704. #endif
  2705. result = m_pDatabase->Query( tQBuf );
  2706. if( result!= NULL ) {
  2707. if( result->size() > 0 ) {
  2708. RetVal = (DBC_PUSHED_CMD*)malloc(sizeof(DBC_PUSHED_CMD));
  2709. if( RetVal ) {
  2710. Assoc * cArr;
  2711. Assoc::iterator it;
  2712. memset( RetVal, 0, sizeof(DBC_PUSHED_CMD));
  2713. cArr = result->at(0);
  2714. it = cArr->find("id");
  2715. if( it != cArr->end() ){
  2716. RetVal->id = atoi( it->second.c_str() );
  2717. };
  2718. it = cArr->find("cmd");
  2719. if( it != cArr->end() ){
  2720. RetVal->CMD = atoi( it->second.c_str() );
  2721. };
  2722. it = cArr->find("parameter");
  2723. if( it != cArr->end() ){
  2724. strncpy( RetVal->PARAM, it->second.c_str(), 256 );
  2725. RetVal->PARAM[255] = (char)0;
  2726. };
  2727. //Only If Result is Fetched - Clear Current CMD
  2728. //sprintf(tQBuf, "DELETE FROM `nodes_qcq` WHERE `id`=%d", RetVal->id );
  2729. //m_pDatabase->SilentQuery( tQBuf );
  2730. };
  2731. };
  2732. };
  2733. deleteResult( result );
  2734. };
  2735. return RetVal;
  2736. };
  2737. bool mysqlDBC::updateNodePushedCMD( uint32_t CmdID, uint8_t status ){
  2738. if(m_bIsConnected){
  2739. char tQBuf[CTEXT];
  2740. sprintf(tQBuf, "UPDATE `nodes_qcq` SET `status`=%d WHERE `id`=%d ", status, CmdID );
  2741. #ifdef DEBUG_ALL
  2742. LOG(tQBuf);
  2743. #endif
  2744. m_pDatabase->SilentQuery( tQBuf );
  2745. return true;
  2746. };
  2747. return false;
  2748. };
  2749. DBC_MODULE_DATA *mysqlDBC::getModuleData( uint32_t ID ){
  2750. DBC_MODULE_DATA *tVal = NULL;
  2751. if(m_bIsConnected){
  2752. char tQBuf[CTEXT];
  2753. AAssoc *result;
  2754. sprintf(tQBuf, "SELECT * FROM server_modules WHERE `id`=%d", ID );
  2755. #ifdef DEBUG_ALL
  2756. LOG(tQBuf);
  2757. #endif
  2758. result = m_pDatabase->Query( tQBuf );
  2759. if( result!= NULL ) {
  2760. if( result->size() > 0 ) {
  2761. Assoc *cArr;
  2762. tVal = (DBC_MODULE_DATA*) malloc(sizeof(DBC_MODULE_DATA));
  2763. if( tVal != NULL ) {
  2764. Assoc::iterator it;
  2765. cArr = result->at(0);
  2766. it = cArr->find("id");
  2767. if( it != cArr->end() ){
  2768. tVal->module_id = atoi( it->second.c_str() );
  2769. };
  2770. it = cArr->find("aux_id");
  2771. if( it != cArr->end() ){
  2772. tVal->aux_id = atoi( it->second.c_str() );
  2773. };
  2774. it = cArr->find("type");
  2775. if( it != cArr->end() ){
  2776. tVal->type = atoi( it->second.c_str() );
  2777. };
  2778. it = cArr->find("enabled");
  2779. if( it != cArr->end() ){
  2780. tVal->enabled = (bool)atoi( it->second.c_str() );
  2781. };
  2782. };
  2783. };
  2784. };
  2785. deleteResult( result );
  2786. };
  2787. return tVal;
  2788. };
  2789. /*
  2790. DBC_SOCKET_DATA *mysqlDBC::getSocketData( uint32_t ID ){
  2791. DBC_SOCKET_DATA *tVal = NULL;
  2792. if(m_bIsConnected){
  2793. char tQBuf[CTEXT];
  2794. AAssoc *result;
  2795. sprintf(tQBuf, "SELECT * FROM sockets WHERE `id`=%d", ID );
  2796. #ifdef DEBUG
  2797. //LOG(tQBuf);
  2798. #endif
  2799. result = m_pDatabase->Query( tQBuf );
  2800. if( result!= NULL ) {
  2801. if( result->size() > 0 ) {
  2802. Assoc *cArr;
  2803. tVal = (DBC_SOCKET_DATA*) malloc(sizeof(DBC_SOCKET_DATA));
  2804. if( tVal != NULL ) {
  2805. Assoc::iterator it;
  2806. cArr = result->at(0);
  2807. it = cArr->find("id");
  2808. if( it != cArr->end() ){
  2809. tVal->socket_id = atoi( it->second.c_str() );
  2810. };
  2811. it = cArr->find("aux_id");
  2812. if( it != cArr->end() ){
  2813. tVal->aux_id = atoi( it->second.c_str() );
  2814. };
  2815. it = cArr->find("type");
  2816. if( it != cArr->end() ){
  2817. tVal->type = atoi( it->second.c_str() );
  2818. };
  2819. it = cArr->find("binded");
  2820. if( it != cArr->end() ){
  2821. tVal->binded = (bool)atoi( it->second.c_str() );
  2822. };
  2823. };
  2824. };
  2825. };
  2826. deleteResult( result );
  2827. };
  2828. return tVal;
  2829. };
  2830. */
  2831. DBC_MEDIA_STREAM_DATA *mysqlDBC::getMediaStreamData( uint32_t ID ){
  2832. DBC_MEDIA_STREAM_DATA *tVal = NULL;
  2833. if(m_bIsConnected){
  2834. char tQBuf[CTEXT];
  2835. AAssoc *result;
  2836. sprintf(tQBuf, "SELECT * FROM media_streams WHERE `id`=%d", ID );
  2837. #ifdef DEBUG_ALL
  2838. LOG(tQBuf);
  2839. #endif
  2840. result = m_pDatabase->Query( tQBuf );
  2841. if( result!= NULL ) {
  2842. if( result->size() > 0 ) {
  2843. Assoc *cArr;
  2844. tVal = (DBC_MEDIA_STREAM_DATA*) malloc(sizeof(DBC_MEDIA_STREAM_DATA));
  2845. if( tVal != NULL ) {
  2846. memset( tVal, 0, sizeof(DBC_MEDIA_STREAM_DATA) );
  2847. Assoc::iterator it;
  2848. cArr = result->at(0);
  2849. tVal->id = ID;
  2850. it = cArr->find("source_id");
  2851. if( it != cArr->end() ){
  2852. tVal->source_id = atoi( it->second.c_str() );
  2853. };
  2854. it = cArr->find("source_type");
  2855. if( it != cArr->end() ){
  2856. sprintf( tVal->source_type, it->second.c_str() );
  2857. };
  2858. it = cArr->find("valid");
  2859. if( it != cArr->end() ){
  2860. tVal->valid = (bool) atoi( it->second.c_str() );
  2861. };
  2862. it = cArr->find("token");
  2863. if( it != cArr->end() ){
  2864. sprintf( tVal->token, it->second.c_str() );
  2865. };
  2866. it = cArr->find("img_width");
  2867. if( it != cArr->end() ){
  2868. tVal->width = atoi( it->second.c_str() );
  2869. };
  2870. it = cArr->find("img_height");
  2871. if( it != cArr->end() ){
  2872. tVal->height = atoi( it->second.c_str() );
  2873. };
  2874. it = cArr->find("fps");
  2875. if( it != cArr->end() ){
  2876. tVal->fps = atoi( it->second.c_str() );
  2877. };
  2878. it = cArr->find("compression_type");
  2879. if( it != cArr->end() ){
  2880. sprintf(tVal->c_type, it->second.c_str());
  2881. };
  2882. it = cArr->find("mrl_proto");
  2883. if( it != cArr->end() ){
  2884. sprintf( tVal->mrl_proto, it->second.c_str() );
  2885. };
  2886. it = cArr->find("mrl_port");
  2887. if( it != cArr->end() ){
  2888. tVal->mrl_port = atoi( it->second.c_str() );
  2889. };
  2890. it = cArr->find("mrl");
  2891. if( it != cArr->end() ){
  2892. sprintf( tVal->mrl, it->second.c_str() );
  2893. };
  2894. };
  2895. };
  2896. };
  2897. deleteResult( result );
  2898. };
  2899. return tVal;
  2900. };
  2901. DBC_MEDIA_SERVER_DATA *mysqlDBC::getMediaServerData( uint32_t ID ){
  2902. DBC_MEDIA_SERVER_DATA *tVal = NULL;
  2903. if(m_bIsConnected){
  2904. char tQBuf[CTEXT];
  2905. AAssoc *result;
  2906. sprintf(tQBuf, "SELECT * FROM media_servers WHERE `id`=%d", ID );
  2907. #ifdef DEBUG_ALL
  2908. LOG(tQBuf);
  2909. #endif
  2910. result = m_pDatabase->Query( tQBuf );
  2911. if( result!= NULL ) {
  2912. if( result->size() > 0 ) {
  2913. Assoc *cArr;
  2914. tVal = (DBC_MEDIA_SERVER_DATA*) malloc(sizeof(DBC_MEDIA_SERVER_DATA));
  2915. if( tVal != NULL ) {
  2916. Assoc::iterator it;
  2917. cArr = result->at(0);
  2918. tVal->id = ID;
  2919. it = cArr->find("secret_key");
  2920. if( it != cArr->end() ){
  2921. sprintf( tVal->key, it->second.c_str() );
  2922. };
  2923. it = cArr->find("ip");
  2924. if( it != cArr->end() ){
  2925. sprintf( tVal->ip, it->second.c_str() );
  2926. };
  2927. it = cArr->find("REST_port");
  2928. if( it != cArr->end() ){
  2929. tVal->port = atoi( it->second.c_str() );
  2930. };
  2931. it = cArr->find("virtual_host");
  2932. if( it != cArr->end() ){
  2933. sprintf( tVal->host, it->second.c_str() );
  2934. };
  2935. it = cArr->find("recording");
  2936. if( it != cArr->end() ){
  2937. tVal->recording = (bool)atoi( it->second.c_str() );
  2938. };
  2939. it = cArr->find("local");
  2940. if( it != cArr->end() ){
  2941. tVal->local = (bool)atoi( it->second.c_str() );
  2942. };
  2943. it = cArr->find("docRoot");
  2944. if( it != cArr->end() ){
  2945. sprintf( tVal->docRoot, it->second.c_str() );
  2946. };
  2947. sprintf( tVal->name,"ZLMedia_%d", tVal->id );
  2948. };
  2949. };
  2950. };
  2951. deleteResult( result );
  2952. };
  2953. return tVal;
  2954. };
  2955. DBC_MEDIA_SERVER_STREAM_DATA *mysqlDBC::getMediaServerStreamDataBySource( uint32_t ID ){
  2956. DBC_MEDIA_SERVER_STREAM_DATA *tVal = NULL;
  2957. if(m_bIsConnected){
  2958. char tQBuf[MAX_PATH_LEN];
  2959. AAssoc *result;
  2960. sprintf(tQBuf, "SELECT `id`, `media_stream_id`, `online`, `key`, `mrl` FROM media_server_streams WHERE `media_stream_id`=%d", ID );
  2961. #ifdef DEBUG_ALL
  2962. LOG(tQBuf);
  2963. #endif
  2964. result = m_pDatabase->Query( tQBuf );
  2965. if( result!= NULL ) {
  2966. if( result->size() > 0 ) {
  2967. Assoc *cArr;
  2968. tVal = (DBC_MEDIA_SERVER_STREAM_DATA*) malloc(sizeof(DBC_MEDIA_SERVER_STREAM_DATA));
  2969. if( tVal != NULL ) {
  2970. Assoc::iterator it;
  2971. cArr = result->at(0);
  2972. tVal->id = ID;
  2973. it = cArr->find("media_stream_id");
  2974. if( it != cArr->end() ){
  2975. tVal->media_stream_id = atoi( it->second.c_str() );
  2976. };
  2977. it = cArr->find("online");
  2978. if( it != cArr->end() ){
  2979. tVal->online = atoi( it->second.c_str() );
  2980. };
  2981. it = cArr->find("key");
  2982. if( it != cArr->end() ){
  2983. sprintf( tVal->key, it->second.c_str() );
  2984. };
  2985. it = cArr->find("mrl");
  2986. if( it != cArr->end() ){
  2987. sprintf( tVal->mrl, it->second.c_str() );
  2988. };
  2989. };
  2990. };
  2991. };
  2992. deleteResult( result );
  2993. };
  2994. return tVal;
  2995. };
  2996. DBC_MEDIA_SERVER_STREAM_DATA *mysqlDBC::getMediaServerStreamData( uint32_t ID ){
  2997. DBC_MEDIA_SERVER_STREAM_DATA *tVal = NULL;
  2998. if(m_bIsConnected){
  2999. char tQBuf[MAX_PATH_LEN];
  3000. AAssoc *result;
  3001. sprintf(tQBuf, "SELECT `id`, `media_stream_id`, `online`, `key`, `mrl` FROM media_server_streams WHERE `id`=%d", ID );
  3002. #ifdef DEBUG_ALL
  3003. LOG(tQBuf);
  3004. #endif
  3005. result = m_pDatabase->Query( tQBuf );
  3006. if( result!= NULL ) {
  3007. if( result->size() > 0 ) {
  3008. Assoc *cArr;
  3009. tVal = (DBC_MEDIA_SERVER_STREAM_DATA*) malloc(sizeof(DBC_MEDIA_SERVER_STREAM_DATA));
  3010. if( tVal != NULL ) {
  3011. Assoc::iterator it;
  3012. cArr = result->at(0);
  3013. tVal->id = ID;
  3014. it = cArr->find("media_stream_id");
  3015. if( it != cArr->end() ){
  3016. tVal->media_stream_id = atoi( it->second.c_str() );
  3017. };
  3018. it = cArr->find("online");
  3019. if( it != cArr->end() ){
  3020. tVal->online = atoi( it->second.c_str() );
  3021. };
  3022. it = cArr->find("key");
  3023. if( it != cArr->end() ){
  3024. sprintf( tVal->key, it->second.c_str() );
  3025. };
  3026. it = cArr->find("mrl");
  3027. if( it != cArr->end() ){
  3028. sprintf( tVal->mrl, it->second.c_str() );
  3029. };
  3030. };
  3031. };
  3032. };
  3033. deleteResult( result );
  3034. };
  3035. return tVal;
  3036. };
  3037. void mysqlDBC::registerServer( uint32_t SiteID, CSTR identity, int PID, uint32_t *ServID, uint32_t *ServNode ){
  3038. if(m_bIsConnected){
  3039. m_nSiteID = SiteID;
  3040. char tQBuf[MAX_PATH_LEN];
  3041. sprintf( tQBuf, "INSERT INTO servers SET `site_id`=%d, `identity`='%s', `version_string`='%s', `online`=1, `ts`=UNIX_TIMESTAMP(now()), pid=%d ON DUPLICATE KEY UPDATE `version_string`='%s', `ts`=UNIX_TIMESTAMP(now()), `online`=1, pid=%d",
  3042. SiteID, identity, _BUILD_STRING_, PID, _BUILD_STRING_, PID );
  3043. #ifdef DEBUG
  3044. LOG(tQBuf);
  3045. #endif
  3046. m_pDatabase->SilentQuery( tQBuf );
  3047. *ServID = getServerID( identity );
  3048. m_nServerID = *ServID;
  3049. if( *ServID ) {
  3050. sprintf(tQBuf,"INSERT INTO nodes SET `site_id`=%d, `aux_id`='%d', `type`= 0, `online`=1, `name`='Server Node' ON DUPLICATE KEY UPDATE `online`=1", m_nSiteID, *ServID );
  3051. #ifdef DEBUG_ALL
  3052. LOG(tQBuf);
  3053. #endif
  3054. *ServNode = ( uint32_t ) m_pDatabase->QueryID( tQBuf );
  3055. if( *ServNode == 0 ){
  3056. *ServNode = getServerNode( *ServID );
  3057. };
  3058. m_nServerNodeID = *ServNode;
  3059. // Clenup Nodes and services ...
  3060. sprintf(tQBuf,"UPDATE nodes SET `online`=0 WHERE `server_id`=%d ", *ServID );
  3061. #ifdef DEBUG_ALL
  3062. LOG(tQBuf);
  3063. #endif
  3064. m_pDatabase->SilentQuery( tQBuf );
  3065. sprintf(tQBuf,"UPDATE cameras SET `online`=0 WHERE `site_id`=%d ", SiteID );
  3066. #ifdef DEBUG_ALL
  3067. LOG(tQBuf);
  3068. #endif
  3069. m_pDatabase->SilentQuery( tQBuf );
  3070. sprintf(tQBuf,"UPDATE media_streams SET `valid`=0 WHERE `site_id`=%d ", SiteID );
  3071. #ifdef DEBUG_ALL
  3072. LOG(tQBuf);
  3073. #endif
  3074. m_pDatabase->SilentQuery( tQBuf );
  3075. sprintf(tQBuf,"UPDATE media_server_streams SET `valid`=0, `online`=0 WHERE `site_id`=%d ", SiteID );
  3076. #ifdef DEBUG_ALL
  3077. LOG(tQBuf);
  3078. #endif
  3079. m_pDatabase->SilentQuery( tQBuf );
  3080. //cleanResources( tServerNodeID );
  3081. setNodeOnline( m_nServerNodeID );
  3082. }
  3083. };
  3084. };
  3085. void mysqlDBC::unregisterServer(){
  3086. if( setNodeOffline( m_nServerNodeID ) ){
  3087. char tQBuf[CTEXT];
  3088. sprintf(tQBuf,"UPDATE servers SET `online`=0, `ts`=UNIX_TIMESTAMP(now()) WHERE `id`=%d", m_nServerID );
  3089. #ifdef DEBUG_ALL
  3090. LOG(tQBuf);
  3091. #endif
  3092. m_pDatabase->SilentQuery( tQBuf );
  3093. };
  3094. };
  3095. bool mysqlDBC::setNodeOnline( uint32_t NodeID, uint8_t status ){
  3096. if(m_bIsConnected){
  3097. char tQBuf[CTEXT];
  3098. if( NodeID ) {
  3099. sprintf(tQBuf,"UPDATE nodes SET `online`=%d WHERE `id`=%d", status, NodeID );
  3100. #ifdef DEBUG_ALL
  3101. LOG(tQBuf);
  3102. #endif
  3103. m_pDatabase->SilentQuery( tQBuf );
  3104. sprintf(tQBuf,"UPDATE `resources` SET `active`=1 WHERE `node_id`=%d", NodeID );
  3105. #ifdef DEBUG_ALL
  3106. LOG(tQBuf);
  3107. #endif
  3108. m_pDatabase->SilentQuery( tQBuf );
  3109. return true;
  3110. };
  3111. };
  3112. return false;
  3113. };
  3114. bool mysqlDBC::setNodeOffline( uint32_t NodeID ){
  3115. if(m_bIsConnected){
  3116. char tQBuf[CTEXT];
  3117. if( NodeID ) {
  3118. sprintf(tQBuf,"UPDATE nodes SET `online`=0 WHERE `id` = %d", NodeID );
  3119. #ifdef DEBUG_ALL
  3120. LOG(tQBuf);
  3121. #endif
  3122. m_pDatabase->SilentQuery( tQBuf );
  3123. sprintf(tQBuf,"UPDATE `resources` SET `active`=0 WHERE `node_id` = %d", NodeID );
  3124. #ifdef DEBUG_ALL
  3125. LOG(tQBuf);
  3126. #endif
  3127. m_pDatabase->SilentQuery( tQBuf );
  3128. return true;
  3129. };
  3130. };
  3131. return false;
  3132. };
  3133. DBC_RESOURCE_DATA *mysqlDBC::getResourceData( uint32_t ResourceID ){
  3134. DBC_RESOURCE_DATA *tVal = NULL;
  3135. if( m_bIsConnected ){
  3136. char tQBuf[CTEXT];
  3137. AAssoc *result;
  3138. sprintf(tQBuf, "SELECT `node_id`, `type`, `aux_id`, `device` FROM resources WHERE `id`=%d", ResourceID );
  3139. #ifdef DEBUG_ALL
  3140. LOG(tQBuf);
  3141. #endif
  3142. result = m_pDatabase->Query( tQBuf );
  3143. if( result!= NULL ) {
  3144. if( result->size() > 0 ) {
  3145. Assoc *cArr;
  3146. tVal = (DBC_RESOURCE_DATA*) malloc(sizeof(DBC_RESOURCE_DATA));
  3147. if( tVal != NULL ) {
  3148. Assoc::iterator it;
  3149. cArr = result->at(0);
  3150. tVal->id = ResourceID;
  3151. it = cArr->find("node_id");
  3152. if( it != cArr->end() ){
  3153. tVal->node_id = atoi( it->second.c_str() );
  3154. };
  3155. it = cArr->find("type");
  3156. if( it != cArr->end() ){
  3157. tVal->type = atoi( it->second.c_str() );
  3158. };
  3159. it = cArr->find("aux_id");
  3160. if( it != cArr->end() ){
  3161. tVal->aux_id = atoi( it->second.c_str() );
  3162. };
  3163. it = cArr->find("device");
  3164. if( it != cArr->end() ){
  3165. strncpy( tVal->device, it->second.c_str(), 64 );
  3166. tVal->device[63] = (char)0;
  3167. };
  3168. };
  3169. };
  3170. };
  3171. deleteResult( result );
  3172. };
  3173. return tVal;
  3174. };
  3175. uint32_t mysqlDBC::getResourceID( uint32_t NodeID, uint8_t type, uint32_t auxID ){
  3176. uint32_t RetVal = 0;
  3177. if(m_bIsConnected){
  3178. char tQBuf[CTEXT];
  3179. sprintf(tQBuf,"SELECT `id` FROM `resources` WHERE `node_id`=%d AND `type`=%d AND `aux_id`=%d", NodeID, type, auxID );
  3180. #ifdef DEBUG_ALL
  3181. LOG(tQBuf);
  3182. #endif
  3183. AAssoc *result;
  3184. result = m_pDatabase->Query( tQBuf );
  3185. if( result!= NULL ) {
  3186. if( result->size() > 0 ) {
  3187. Assoc * cArr;
  3188. Assoc::iterator it;
  3189. cArr = result->at(0);
  3190. it = cArr->find("id");
  3191. if( it != cArr->end() ){
  3192. RetVal = atoi( it->second.c_str() );
  3193. };
  3194. };
  3195. };
  3196. deleteResult( result );
  3197. };
  3198. return RetVal;
  3199. };
  3200. uint32_t mysqlDBC::getServerID( CSTR identity ){
  3201. uint32_t RetVal = 0;
  3202. if(m_bIsConnected){
  3203. char tQBuf[CTEXT];
  3204. sprintf(tQBuf,"SELECT id FROM servers WHERE `identity`='%s'", identity );
  3205. #ifdef DEBUG_ALL
  3206. LOG(tQBuf);
  3207. #endif
  3208. AAssoc *result;
  3209. result = m_pDatabase->Query( tQBuf );
  3210. if( result!= NULL ) {
  3211. if( result->size() > 0 ) {
  3212. Assoc * cArr;
  3213. Assoc::iterator it;
  3214. cArr = result->at(0);
  3215. it = cArr->find("id");
  3216. if( it != cArr->end() ){
  3217. RetVal = atoi( it->second.c_str() );
  3218. };
  3219. };
  3220. };
  3221. deleteResult( result );
  3222. };
  3223. return RetVal;
  3224. };
  3225. uint32_t mysqlDBC::getServerNode( uint32_t SID ){
  3226. uint32_t RetVal = 0;
  3227. if(m_bIsConnected){
  3228. char tQBuf[CTEXT];
  3229. sprintf(tQBuf,"SELECT id FROM nodes WHERE `type`=0 AND `aux_id`=%d", SID );
  3230. #ifdef DEBUG_ALL
  3231. LOG(tQBuf);
  3232. #endif
  3233. AAssoc *result;
  3234. result = m_pDatabase->Query( tQBuf );
  3235. if( result!= NULL ) {
  3236. if( result->size() > 0 ) {
  3237. Assoc * cArr;
  3238. Assoc::iterator it;
  3239. cArr = result->at(0);
  3240. it = cArr->find("id");
  3241. if( it != cArr->end() ){
  3242. RetVal = atoi( it->second.c_str() );
  3243. };
  3244. };
  3245. };
  3246. deleteResult( result );
  3247. };
  3248. return RetVal;
  3249. };
  3250. uint32_t mysqlDBC::addLocalMediaSource( uint32_t SiteID, CSTR path, uint32_t width, uint32_t height ){
  3251. uint32_t RetVal = 0;
  3252. if(m_bIsConnected){
  3253. char tQBuf[1024];
  3254. char tM5[33];
  3255. CSTR tMD5 = MD5String( path );
  3256. if( tMD5 != NULL ) {
  3257. memcpy( tM5, tMD5, 33 );
  3258. tM5[32]=(char)0;
  3259. free( tMD5 );
  3260. sprintf( tQBuf, "INSERT INTO media_streams SET `site_id`=%d, `source_id`=0, source_type='A', `valid`=1, `name`='Local Frame Grabber', `token`='%s', `img_width`=%d, `img_height`=%d, `mrl_proto`='v4l2', `mrl_port`='', `picture_proto`='', mrl='%s' ON DUPLICATE KEY UPDATE id=id, `valid`=1",//, img_width=%d, img_height=%d",
  3261. SiteID, tM5, width, height, path );//, width, height );
  3262. #ifdef DEBUG_ALL
  3263. LOG(tQBuf);
  3264. #endif
  3265. RetVal = (uint32_t) m_pDatabase->QueryID( tQBuf );
  3266. };
  3267. };
  3268. return RetVal;
  3269. };
  3270. /*
  3271. uint32_t mysqlDBC::addNodeSocket( uint32_t NodeID, uint32_t auxID, uint8_t SocketType, uint8_t SocketMode, bool multidrop, CSTR path, CSTR name ){
  3272. uint32_t retVal = 0;
  3273. if(m_bIsConnected){
  3274. char tQBuf[2048];
  3275. char tM5[33];
  3276. CSTR tMD5 = MD5String( path );
  3277. if( tMD5 != NULL ) {
  3278. memcpy( tM5, tMD5, 33 );
  3279. free( tMD5 );
  3280. if( multidrop ) {
  3281. sprintf(tQBuf,"INSERT INTO `sockets` SET `node_id`=%d, `type`=%d, `mode`=%d, `multidrop`=1, `md5`='%s', `path`='%s', `name`='%s', `aux_id`=%d ON DUPLICATE KEY UPDATE `id`=`id`, `name`='%s'",
  3282. NodeID, SocketType, SocketMode, tM5, path, name, auxID, name );
  3283. } else {
  3284. sprintf(tQBuf,"INSERT INTO `sockets` SET `node_id`=%d, `type`=%d, `mode`=%d, `multidrop`=0, `md5`='%s', `path`='%s', `name`='%s', `aux_id`=%d ON DUPLICATE KEY UPDATE `id`=`id`, `name`='%s'",
  3285. NodeID, SocketType, SocketMode, tM5, path, name, auxID, name );
  3286. };
  3287. #ifdef DEBUG
  3288. LOG(tQBuf);
  3289. #endif
  3290. //m_pDatabase->SilentQuery( tQBuf );
  3291. retVal = (uint32_t) m_pDatabase->QueryID( tQBuf );
  3292. };
  3293. };
  3294. return retVal;
  3295. };
  3296. */
  3297. bool mysqlDBC::addNotification( uint32_t MSG_ID, uint8_t DIS_LVL, uint32_t OBJ_ID ){
  3298. if(m_bIsConnected){
  3299. char tQBuf[2048];
  3300. sprintf(tQBuf,"INSERT INTO `notifications` SET `site_id`=%d, `ts`=NOW(), `lvl`=%d, `type`=%d, `obj_id`=%d ON DUPLICATE KEY UPDATE `status`='A', `ts`=NOW()", m_nSiteID, DIS_LVL, MSG_ID, OBJ_ID );
  3301. #ifdef DEBUG_ALL
  3302. LOG(tQBuf);
  3303. #endif
  3304. m_pDatabase->SilentQuery( tQBuf );
  3305. return true;
  3306. };
  3307. return false;
  3308. };
  3309. uint32_t mysqlDBC::addResource( /*uint32_t NodeID,*/ uint8_t type, CSTR devName, uint32_t auxID ){
  3310. uint32_t RetVal = 0;
  3311. if( m_bIsConnected ){
  3312. char tQBuf[2048];
  3313. sprintf( tQBuf, "%d:%d:%s", m_nServerNodeID, type, devName );
  3314. CSTR tMD5 = MD5String( tQBuf );
  3315. if( tMD5 ) {
  3316. sprintf( tQBuf, "INSERT INTO `resources` SET `node_id`=%d, `type`=%d, `md5`='%s', `aux_id`=%d, `device`='%s', `active`=1 ON DUPLICATE KEY UPDATE `active`=1, `aux_id`=%d", m_nServerNodeID, type, tMD5, auxID, devName, auxID );
  3317. //sprintf( tQBuf, "INSERT INTO `resources` SET `node_id`=%d, `type`=%d, `aux_id`=%d, `device`='%s', `active`=1 ON DUPLICATE KEY UPDATE `active`=1, `aux_id`=%d, `device`='%s'", NodeID, type, auxID, devName, auxID, devName );
  3318. free( tMD5 );
  3319. #ifdef DEBUG_ALL
  3320. LOG(tQBuf);
  3321. #endif
  3322. RetVal = (uint32_t) m_pDatabase->QueryID( tQBuf );
  3323. if( RetVal == 0 ) {
  3324. RetVal = getResourceID( m_nServerNodeID, type, auxID );
  3325. };
  3326. };
  3327. };
  3328. return RetVal;
  3329. };
  3330. /*
  3331. uint32_t mysqlDBC::getNodeSocketID( uint32_t NodeID, uint32_t auxID, uint8_t SocketType, CSTR path ){
  3332. uint32_t retVal = 0;
  3333. if(m_bIsConnected){
  3334. char tQBuf[2048];
  3335. char tM5[33];
  3336. CSTR tMD5 = MD5String( path );
  3337. if( tMD5 != NULL ) {
  3338. memcpy( tM5, tMD5, 33 );
  3339. free( tMD5 );
  3340. sprintf( tQBuf,"SELECT id FROM `sockets` WHERE `node_id`=%d AND `type`=%d AND `md5`='%s' AND `aux_id`=%d", NodeID, SocketType, tM5, auxID );
  3341. #ifdef DEBUG
  3342. LOG(tQBuf);
  3343. #endif
  3344. AAssoc *result;
  3345. result = m_pDatabase->Query( tQBuf );
  3346. if( result!= NULL ) {
  3347. if( result->size() > 0 ) {
  3348. Assoc * cArr;
  3349. Assoc::iterator it;
  3350. cArr = result->at(0);
  3351. it = cArr->find("id");
  3352. if( it != cArr->end() ){
  3353. retVal = atoi( it->second.c_str() );
  3354. };
  3355. };
  3356. };
  3357. deleteResult( result );
  3358. };
  3359. };
  3360. return retVal;
  3361. };
  3362. */
  3363. /*
  3364. CSTR mysqlDBC::getSocketName( uint32_t NodeID, uint32_t Type ){
  3365. if(m_bIsConnected){
  3366. char tQBuf[CTEXT];
  3367. sprintf( tQBuf, "SELECT `name` FROM `sockets` WHERE `node_id`=%d AND `type`=%d LIMIT 1",
  3368. NodeID, Type );
  3369. #ifdef DEBUG
  3370. LOG(tQBuf);
  3371. #endif
  3372. AAssoc *result;
  3373. result = m_pDatabase->Query( tQBuf );
  3374. if( result!= NULL ) {
  3375. if( result->size() > 0 ) {
  3376. Assoc * cArr;
  3377. Assoc::iterator it;
  3378. cArr = result->at(0);
  3379. it = cArr->find("name");
  3380. if( it != cArr->end() ){
  3381. strncpy( tQBuf, it->second.c_str(), CTEXT );
  3382. };
  3383. };
  3384. };
  3385. deleteResult( result );
  3386. return strdup(tQBuf);
  3387. };
  3388. return NULL;
  3389. };
  3390. */
  3391. KAFKA_SETTINGS *mysqlDBC::getSettingsKAFKA( uint32_t ModuleID ){
  3392. KAFKA_SETTINGS *tVal = NULL;
  3393. if( m_bIsConnected ) {
  3394. char tQBuf[CTEXT];
  3395. AAssoc *result;
  3396. sprintf( tQBuf, "SELECT * FROM modules_kafka WHERE module_id = %d", ModuleID );
  3397. #ifdef DEBUG_ALL
  3398. LOG(tQBuf);
  3399. #endif
  3400. result = m_pDatabase->Query( tQBuf );
  3401. if( result!= NULL ) {
  3402. if( result->size() > 0 ) {
  3403. Assoc *cArr;
  3404. tVal = (KAFKA_SETTINGS*) malloc(sizeof(KAFKA_SETTINGS));
  3405. if( tVal != NULL ) {
  3406. memset( tVal, 0, sizeof(KAFKA_SETTINGS) );
  3407. Assoc::iterator it;
  3408. cArr = result->at(0);
  3409. it = cArr->find("brocker_address");
  3410. if( it != cArr->end() ){
  3411. strncpy( tVal->brocker_addr, it->second.c_str(), 255 );
  3412. };
  3413. it = cArr->find("brocker_port");
  3414. if( it != cArr->end() ){
  3415. tVal->brocker_port = atoi( it->second.c_str() );
  3416. };
  3417. it = cArr->find("use_ssl");
  3418. if( it != cArr->end() ){
  3419. tVal->use_ssl = (bool)atoi( it->second.c_str() );
  3420. };
  3421. it = cArr->find("auth_cert");
  3422. if( it != cArr->end() ){
  3423. tVal->auth_by_cert = (bool)atoi( it->second.c_str() );
  3424. };
  3425. it = cArr->find("auth_cred");
  3426. if( it != cArr->end() ){
  3427. tVal->auth_by_cred = (bool)atoi( it->second.c_str() );
  3428. };
  3429. it = cArr->find("vault_md5");
  3430. if( it != cArr->end() ){
  3431. strncpy( tVal->vault_md5, it->second.c_str(), 32 );
  3432. };
  3433. it = cArr->find("truststore");
  3434. if( it != cArr->end() ){
  3435. tVal->truststore = (bool)atoi( it->second.c_str() );
  3436. };
  3437. it = cArr->find("certstore");
  3438. if( it != cArr->end() ){
  3439. tVal->certstore = (bool)atoi( it->second.c_str() );
  3440. };
  3441. it = cArr->find("keystore");
  3442. if( it != cArr->end() ){
  3443. tVal->keystore = (bool)atoi( it->second.c_str() );
  3444. };
  3445. it = cArr->find("cred_username");
  3446. if( it != cArr->end() ){
  3447. strncpy( tVal->cred_username, it->second.c_str(), 32 );
  3448. };
  3449. it = cArr->find("cred_password");
  3450. if( it != cArr->end() ){
  3451. strncpy( tVal->cred_password, it->second.c_str(), 32 );
  3452. };
  3453. };
  3454. };
  3455. };
  3456. deleteResult( result );
  3457. };
  3458. return tVal;
  3459. };
  3460. KAFKA_TEMPLATE *mysqlDBC::getKafkaTemplateForEvent( uint32_t ModuleID, uint32_t ClassID, uint32_t EventID ){
  3461. KAFKA_TEMPLATE *tVal = NULL;
  3462. if( m_bIsConnected ) {
  3463. char tQBuf[CTEXT];
  3464. AAssoc *result;
  3465. sprintf( tQBuf, "SELECT topic, template FROM module_kafka_settings WHERE module_id=%d AND class_id=%d AND event_id=%d", ModuleID, ClassID, EventID );
  3466. #ifdef DEBUG_ALL
  3467. LOG(tQBuf);
  3468. #endif
  3469. result = m_pDatabase->Query( tQBuf );
  3470. if( result!= NULL ) {
  3471. if( result->size() > 0 ) {
  3472. Assoc *cArr;
  3473. tVal = (KAFKA_TEMPLATE*) malloc(sizeof(KAFKA_TEMPLATE));
  3474. if( tVal != NULL ) {
  3475. Assoc::iterator it;
  3476. cArr = result->at(0);
  3477. it = cArr->find("topic");
  3478. if( it != cArr->end() ){
  3479. memset( tVal->topic, 0, 128 );
  3480. strncpy( tVal->topic , it->second.c_str(), 127 );
  3481. };
  3482. it = cArr->find("template");
  3483. if( it != cArr->end() ){
  3484. tVal->tpl = (CSTR)malloc( it->second.length() + 1 );
  3485. if( tVal->tpl!= NULL) {
  3486. memset( tVal->tpl, 0, it->second.length() + 1 );
  3487. strncpy( tVal->tpl, it->second.c_str(), it->second.length() );
  3488. };
  3489. };
  3490. };
  3491. };
  3492. };
  3493. deleteResult( result );
  3494. };
  3495. return tVal;
  3496. };
  3497. DBC_UART_DATA *mysqlDBC::getUartData( uint32_t UartID ){
  3498. DBC_UART_DATA *tVal = NULL;
  3499. if( m_bIsConnected ) {
  3500. char tQBuf[MAX_PATH_LEN];
  3501. AAssoc *result;
  3502. sprintf( tQBuf, "SELECT * FROM uart_settings WHERE id = %d", UartID );
  3503. #ifdef DEBUG_ALL
  3504. LOG(tQBuf);
  3505. #endif
  3506. result = m_pDatabase->Query( tQBuf );
  3507. if( result!= NULL ) {
  3508. if( result->size() > 0 ) {
  3509. Assoc *cArr;
  3510. tVal = (DBC_UART_DATA*) malloc(sizeof(DBC_UART_DATA));
  3511. if( tVal != NULL ) {
  3512. Assoc::iterator it;
  3513. cArr = result->at(0);
  3514. it = cArr->find("type");
  3515. if( it != cArr->end() ){
  3516. tVal->type = atoi( it->second.c_str() );
  3517. };
  3518. it = cArr->find("speed");
  3519. if( it != cArr->end() ){
  3520. tVal->speed = atoi( it->second.c_str() );
  3521. };
  3522. it = cArr->find("mode");
  3523. if( it != cArr->end() ){
  3524. tVal->mode = atoi( it->second.c_str() );
  3525. };
  3526. it = cArr->find("port");
  3527. if( it != cArr->end() ){
  3528. tVal->port = atoi( it->second.c_str() );
  3529. };
  3530. it = cArr->find("path");
  3531. if( it != cArr->end() ){
  3532. strncpy( tVal->path, it->second.c_str(), 128 );
  3533. };
  3534. };
  3535. };
  3536. };
  3537. deleteResult( result );
  3538. };
  3539. return tVal;
  3540. };
  3541. uint32_t mysqlDBC::getUartID( uint32_t NodeID, uint8_t Type, CSTR path ){
  3542. uint32_t RetVal = 0;
  3543. if(m_bIsConnected){
  3544. char tQBuf[CTEXT];
  3545. sprintf(tQBuf,"SELECT `id` FROM `uart_settings` WHERE `node_id`=%d AND `type`=%d AND `path`='%s' ", NodeID, Type, path );
  3546. #ifdef DEBUG_ALL
  3547. LOG(tQBuf);
  3548. #endif
  3549. AAssoc *result;
  3550. result = m_pDatabase->Query( tQBuf );
  3551. if( result!= NULL ) {
  3552. if( result->size() > 0 ) {
  3553. Assoc * cArr;
  3554. Assoc::iterator it;
  3555. cArr = result->at(0);
  3556. it = cArr->find("id");
  3557. if( it != cArr->end() ){
  3558. RetVal = atoi( it->second.c_str() );
  3559. };
  3560. };
  3561. };
  3562. deleteResult( result );
  3563. };
  3564. return RetVal;
  3565. };
  3566. bool mysqlDBC::updateMediaServerStream( uint32_t id, CSTR mrl, CSTR key ){
  3567. if( m_bIsConnected ) {
  3568. char tQBuf[MAX_PATH_LEN];
  3569. if( key == NULL ) {
  3570. if( mrl == NULL ) {
  3571. sprintf( tQBuf,"UPDATE media_server_streams SET `online`=0, `key`='', mrl='', `valid`=0 WHERE `id`=%d", id );
  3572. } else {
  3573. sprintf( tQBuf,"UPDATE media_server_streams SET `online`=0, `key`='', `mrl`='%s', `valid`=1 WHERE `id`=%d", mrl, id );
  3574. };
  3575. } else {
  3576. sprintf( tQBuf,"UPDATE media_server_streams SET `online`=1, `key`='%s', `mrl`='%s', `valid`=1 WHERE `id`=%d",
  3577. key,
  3578. mrl,
  3579. id
  3580. );
  3581. };
  3582. #ifdef DEBUG_ALL
  3583. LOG(tQBuf);
  3584. #endif
  3585. m_pDatabase->SilentQuery( tQBuf );
  3586. return true;
  3587. };
  3588. return false;
  3589. };
  3590. bool mysqlDBC::updateResourceAUX( uint32_t ResID, uint32_t AUX ){
  3591. if( m_bIsConnected ) {
  3592. char tQBuf[MAX_PATH_LEN];
  3593. sprintf( tQBuf, "UPDATE `resources` SET `aux_id`=%d WHERE `id`=%d", AUX, ResID );
  3594. #ifdef DEBUG
  3595. LOG(tQBuf);
  3596. #endif
  3597. m_pDatabase->SilentQuery( tQBuf );
  3598. return true;
  3599. };
  3600. return false;
  3601. };
  3602. //bool mysqlDBC::updateServerUtilisation( uint32_t ServerID, uint32_t nCores, float cpu1, float cpu5, float cpu15, float mem, float disk, uint64_t dtsize, uint64_t dcsize, uint64_t mtsize, uint64_t mcsize ){
  3603. bool mysqlDBC::updateServerUtilisation( DBC_SYS_LOAD_INFO *ptr ){
  3604. if( m_bIsConnected ) {
  3605. char tQBuf[MAX_PATH_LEN];
  3606. sprintf( tQBuf, "UPDATE `servers` SET `ts`=UNIX_TIMESTAMP(now()), `cpu_cores`=%d, `stat_cpu1`=%0.2f, `stat_cpu5`=%0.2f, `stat_cpu15`=%0.2f, `stat_mem`=%0.2f, `stat_disk`=%0.2f, `temp0`=%0.1f, `val_mem_tottal`=%" PRIu64 ", `val_mem_current`=%" PRIu64 ", `val_disk_tottal`=%" PRIu64 ", `val_disk_current`=%" PRIu64 " WHERE `id`=%d",
  3607. ptr->CPU_CORES,
  3608. ptr->cpu1,
  3609. ptr->cpu5,
  3610. ptr->cpu15,
  3611. ptr->mem,
  3612. ptr->disk,
  3613. ptr->temperature,
  3614. ptr->T_DISK,
  3615. ptr->C_DISK,
  3616. ptr->T_MEM,
  3617. ptr->C_MEM,
  3618. m_nServerID
  3619. );
  3620. #ifdef DEBUG_ALL
  3621. LOG(tQBuf);
  3622. #endif
  3623. m_pDatabase->SilentQuery( tQBuf );
  3624. return true;
  3625. };
  3626. return false;
  3627. };
  3628. uint32_t mysqlDBC::addLocalDCB( uint32_t SiteID, CSTR PATH, CSTR SERIAL, uint8_t CNT, uint32_t status ){
  3629. uint32_t RetVal = 0;
  3630. if( m_bIsConnected ) {
  3631. char tQBuf[MAX_PATH_LEN];
  3632. sprintf( tQBuf, "INSERT INTO modules_dcr SET site_id=%d, status=%d, channels=%d, serial_id='%s' ON DUPLICATE KEY UPDATE status=%d, channels=%d",
  3633. SiteID,
  3634. status,
  3635. CNT,
  3636. SERIAL,
  3637. status,
  3638. CNT
  3639. );
  3640. #ifdef DEBUG_ALL
  3641. LOG(tQBuf);
  3642. #endif
  3643. uint64_t cid = m_pDatabase->QueryID( tQBuf );
  3644. if( cid == 0 ) {
  3645. AAssoc *result;
  3646. sprintf( tQBuf, "SELECT id FROM modules_dcr WHERE site_id=%d AND serial_id='%s'",
  3647. SiteID,
  3648. SERIAL
  3649. );
  3650. #ifdef DEBUG_ALL
  3651. LOG(tQBuf);
  3652. #endif
  3653. result = m_pDatabase->Query( tQBuf );
  3654. if( result!= NULL ) {
  3655. if( result->size() > 0 ) {
  3656. Assoc * cArr;
  3657. Assoc::iterator it;
  3658. cArr = result->at(0);
  3659. it = cArr->find("id");
  3660. if( it != cArr->end() ){
  3661. cid = atoi( it->second.c_str() );
  3662. };
  3663. };
  3664. deleteResult( result );
  3665. };
  3666. };
  3667. if( cid!= 0 ) {
  3668. for( uint8_t idx = 0; idx < CNT; idx++ ) {
  3669. if( status & ( 1 << idx ) ){
  3670. sprintf( tQBuf, "INSERT INTO module_dcr_chanels SET dcr_id=%d, channel_id=%d, mode='O', status='C' ON DUPLICATE KEY UPDATE status='C'",
  3671. (uint32_t) cid,
  3672. idx
  3673. );
  3674. } else {
  3675. sprintf( tQBuf, "INSERT INTO module_dcr_chanels SET dcr_id=%d, channel_id=%d, mode='O', status='O' ON DUPLICATE KEY UPDATE status='O'",
  3676. (uint32_t) cid,
  3677. idx
  3678. );
  3679. }
  3680. #ifdef DEBUG_ALL
  3681. LOG(tQBuf);
  3682. #endif
  3683. m_pDatabase->SilentQuery( tQBuf );
  3684. };
  3685. };
  3686. };
  3687. return RetVal;
  3688. };
  3689. uint32_t mysqlDBC::addLocalUART( /*uint32_t NodeID,*/ uint8_t utype, uint32_t speed, uint8_t bit, char parity, float stop_bit, CSTR PATH, uint8_t mode, uint16_t port ){
  3690. uint32_t RetVal = 0;
  3691. if( m_bIsConnected ) {
  3692. char tQBuf[MAX_PATH_LEN];
  3693. sprintf( tQBuf, "INSERT INTO `uart_settings` SET `node_id`=%d, `type`=%d, `speed`=%d, `bit`=%d, `parity`='%c', `stop_bit`=%.1f, `mode`=%d, `port`=%d, `path`='%s' ON DUPLICATE KEY UPDATE `id`=`id`",
  3694. m_nServerNodeID,
  3695. utype,
  3696. speed,
  3697. bit,
  3698. parity,
  3699. stop_bit,
  3700. mode,
  3701. port,
  3702. PATH
  3703. );
  3704. #ifdef DEBUG_ALL
  3705. LOG(tQBuf);
  3706. #endif
  3707. RetVal = m_pDatabase->QueryID( tQBuf );
  3708. if( RetVal == 0 ) {
  3709. RetVal = getUartID( m_nServerNodeID, utype, PATH );
  3710. };
  3711. };
  3712. return RetVal;
  3713. };
  3714. uint32_t mysqlDBC::addLocalNIF( CSTR device, CSTR mac, NIF_TYPE dtype, NIF_MODE dmode, uint32_t aux_id ){
  3715. uint32_t RetVal = 0;
  3716. if( m_bIsConnected ) {
  3717. char tQBuf[MAX_PATH_LEN];
  3718. char * tKey = MD5String( device );
  3719. if( tKey != NULL ) {
  3720. sprintf( tQBuf, "INSERT INTO `network_interfaces` SET `type`=%d, `key`='%s', `device_name`='%s', `mac`='%s', `mode`=%d, `aux_id`=%d ON DUPLICATE KEY UPDATE `mode`=%d, `aux_id`=%d, `mac`='%s'",
  3721. dtype,
  3722. tKey,
  3723. device,
  3724. mac,
  3725. dmode,
  3726. aux_id,
  3727. dmode,
  3728. aux_id,
  3729. mac
  3730. );
  3731. #ifdef DEBUG
  3732. LOG(tQBuf);
  3733. #endif
  3734. RetVal = m_pDatabase->QueryID( tQBuf );
  3735. if( RetVal == 0 ) {
  3736. RetVal = getNIF_ID( tKey );
  3737. };
  3738. free( tKey );
  3739. };
  3740. };
  3741. return RetVal;
  3742. };
  3743. uint32_t mysqlDBC::addLocalWiFi( uint32_t NIF_ID, WIFI_MODE mode, CSTR SSID, CSTR password, WIFI_ENCRIPTION encryption, uint32_t router_id ){
  3744. uint32_t RetVal = 0;
  3745. if( m_bIsConnected ) {
  3746. char tQBuf[MAX_PATH_LEN];
  3747. sprintf( tQBuf, "INSERT INTO `wifis` SET `nif_id`=%d, `mode`=%d, `aux_id`=%d, `SSID`='%s', `password`='%s', `encryption_type`=%d ON DUPLICATE KEY UPDATE `mode`=%d, `aux_id`=%d, `SSID`='%s', `password`='%s', `encryption_type`=%d",
  3748. NIF_ID,
  3749. mode,
  3750. router_id,
  3751. SSID,
  3752. password,
  3753. encryption,
  3754. mode,
  3755. router_id,
  3756. SSID,
  3757. password,
  3758. encryption
  3759. );
  3760. #ifdef DEBUG
  3761. LOG(tQBuf);
  3762. #endif
  3763. RetVal = m_pDatabase->QueryID( tQBuf );
  3764. if( RetVal == 0 ) {
  3765. RetVal = getWiFi_ID( NIF_ID );
  3766. };
  3767. };
  3768. return RetVal;
  3769. };
  3770. uint32_t mysqlDBC::addLRFMask( uint32_t devID, uint8_t lrfID, uint8_t layerID ){
  3771. uint32_t RetVal = 0;
  3772. if( m_bIsConnected ) {
  3773. char tQBuf[MAX_PATH_LEN];
  3774. sprintf( tQBuf, "INSERT INTO `lrf_masks` SET `sensor_id`=%d, `lrf_id`=%d, `layer`=%d ON DUPLICATE KEY UPDATE `id`=`id`",
  3775. devID,
  3776. lrfID,
  3777. layerID
  3778. );
  3779. #ifdef DEBUG
  3780. LOG(tQBuf);
  3781. #endif
  3782. RetVal = m_pDatabase->QueryID( tQBuf );
  3783. if( RetVal == 0 ) {
  3784. RetVal = getLRFMaskID( devID, lrfID, layerID );
  3785. };
  3786. };
  3787. return RetVal;
  3788. };
  3789. uint32_t mysqlDBC::addLRFMaskPolygone( uint32_t maskID, uint8_t r, uint8_t g, uint8_t b ){
  3790. uint32_t RetVal = 0;
  3791. if( m_bIsConnected ) {
  3792. char tQBuf[MAX_PATH_LEN];
  3793. sprintf( tQBuf, "INSERT INTO `lrf_mask_vertexes` SET `mask_id`=%d, `r`=%d, `g`=%d, `b`=%d",
  3794. maskID,
  3795. r,
  3796. g,
  3797. b
  3798. );
  3799. #ifdef DEBUG
  3800. LOG(tQBuf);
  3801. #endif
  3802. RetVal = m_pDatabase->QueryID( tQBuf );
  3803. };
  3804. return RetVal;
  3805. };
  3806. bool mysqlDBC::addLRFMaskPolygonePoint( uint32_t polyID, int16_t x, int16_t y ){
  3807. if( m_bIsConnected ) {
  3808. char tQBuf[MAX_PATH_LEN];
  3809. sprintf( tQBuf, "INSERT INTO `lrf_mask_vertex_points` SET `vertex_id`=%d, `x`=%d, `y`=%d",
  3810. polyID,
  3811. x,
  3812. y
  3813. );
  3814. #ifdef DEBUG
  3815. LOG(tQBuf);
  3816. #endif
  3817. m_pDatabase->SilentQuery( tQBuf );
  3818. return true;
  3819. };
  3820. return false;
  3821. };
  3822. uint32_t mysqlDBC::addLocalNetwork( uint32_t NIF_ID, NETWORK_TYPE net_type, CSTR address, CSTR mask, CSTR gateway, CSTR broadcast ){
  3823. uint32_t RetVal = 0;
  3824. if( m_bIsConnected ) {
  3825. char tQBuf[MAX_PATH_LEN];
  3826. sprintf( tQBuf, "INSERT INTO `networks` SET `nif_id`=%d, `type`=%d, `address`='%s', `gateway`='%s', `mask`='%s', `broadcast`='%s' ON DUPLICATE KEY UPDATE `address`='%s', `gateway`='%s', `mask`='%s', `broadcast`='%s'",
  3827. NIF_ID,
  3828. net_type,
  3829. address,
  3830. gateway,
  3831. mask,
  3832. broadcast,
  3833. address,
  3834. gateway,
  3835. mask,
  3836. broadcast
  3837. );
  3838. #ifdef DEBUG
  3839. LOG(tQBuf);
  3840. #endif
  3841. RetVal = m_pDatabase->QueryID( tQBuf );
  3842. // On Update IF data no need to return ID
  3843. //if( RetVal == 0 ) {
  3844. // RetVal = getNetworkInterfaceID( tKey );
  3845. //};
  3846. };
  3847. return RetVal;
  3848. };
  3849. uint32_t mysqlDBC::addLocalNetworkInfrastructure( uint32_t NIF_ID, uint32_t OUTBOUND_NIF, bool ena_dhcp, CSTR BRANG, CSTR ERANG, CSTR MASK, CSTR LEASE_TIME ){
  3850. uint32_t RetVal = 0;
  3851. if( m_bIsConnected ) {
  3852. char tQBuf[MAX_PATH_LEN];
  3853. bool ena_routing = true;
  3854. if( OUTBOUND_NIF == 0 ){
  3855. ena_routing = false;
  3856. };
  3857. if( ena_dhcp ){
  3858. if ( BRANG == NULL || ERANG == NULL || MASK == NULL || LEASE_TIME == NULL ) {
  3859. LOG_ERROR("Wrong DHCP parameters to create Network Infrastructure!");
  3860. return 0;
  3861. };
  3862. sprintf(tQBuf, "INSERT INTO `network_infrastructure` SET `nif_id`=%d, `enable_routing`=%d, `outbond_nif`=%d, `enable_dhcp`=1, `dhcp_range_begin`='%s', `dhcp_range_end`='%s', `dhcp_range_mask`='%s', `dhcp_lease_time`='%s' ON DUPLICATE KEY UPDATE `enable_routing`=%d, `outbond_nif`=%d, `enable_dhcp`=1, `dhcp_range_begin`='%s', `dhcp_range_end`='%s', `dhcp_range_mask`='%s', `dhcp_lease_time`='%s'",
  3863. NIF_ID,
  3864. ena_routing,
  3865. OUTBOUND_NIF,
  3866. BRANG,
  3867. ERANG,
  3868. MASK,
  3869. LEASE_TIME,
  3870. ena_routing,
  3871. OUTBOUND_NIF,
  3872. BRANG,
  3873. ERANG,
  3874. MASK,
  3875. LEASE_TIME
  3876. );
  3877. } else {
  3878. if( ena_routing ){
  3879. sprintf(tQBuf, "INSERT INTO `network_infrastructure` SET `nif_id`=%d, `enable_routing`=1, `outbond_nif`=%d ON DUPLICATE KEY UPDATE `enable_routing`=1, `outbond_nif`=%d",
  3880. NIF_ID,
  3881. OUTBOUND_NIF,
  3882. OUTBOUND_NIF
  3883. );
  3884. } else {
  3885. LOG_ERROR("No Special Service Defined To Network Infrastructure!");
  3886. return 0;
  3887. };
  3888. };
  3889. #ifdef DEBUG_ALL
  3890. LOG(tQBuf);
  3891. #endif
  3892. RetVal = m_pDatabase->QueryID( tQBuf );
  3893. // On Update IF data no need to return ID
  3894. if( RetVal == 0 ) {
  3895. RetVal = getNetworkInfrastructureID( NIF_ID );
  3896. };
  3897. };
  3898. return RetVal;
  3899. };
  3900. bool mysqlDBC::addLRFDraw( uint32_t DBID, uint32_t SIZE, CSTR ID, uint8_t kID, uint8_t type, bool rendered ){
  3901. if( m_bIsConnected ) {
  3902. char tQBuf[MAX_PATH_LEN];
  3903. if ( rendered ) {
  3904. sprintf(tQBuf, "INSERT INTO `lrf_draw` SET `node_id`=%d,`ts`=NOW(),`md5`='%s',`size`=%d, `lrf_id`=%d, `type`=%d, `rendered`='Y' ON DUPLICATE KEY UPDATE `ts`=NOW(),`md5`='%s',`size`=%d, `rendered`='Y'",
  3905. DBID,
  3906. ID,
  3907. SIZE,
  3908. kID,
  3909. type,
  3910. ID,
  3911. SIZE
  3912. );
  3913. } else {
  3914. sprintf(tQBuf, "INSERT INTO `lrf_draw` SET `node_id`=%d,`ts`=NOW(),`md5`='%s',`size`=%d, `lrf_id`=%d, `type`=%d ON DUPLICATE KEY UPDATE `ts`=NOW(),`md5`='%s',`size`=%d, `rendered`='N'",
  3915. DBID,
  3916. ID,
  3917. SIZE,
  3918. kID,
  3919. type,
  3920. ID,
  3921. SIZE
  3922. );
  3923. };
  3924. #ifdef DEBUG
  3925. LOG(tQBuf);
  3926. #endif
  3927. m_pDatabase->SilentQuery( tQBuf );
  3928. return true;
  3929. };
  3930. return false;
  3931. };
  3932. uint32_t mysqlDBC::addEvent( uint32_t SRC, CSTR UUID, uint32_t tss, uint32_t tsms, uint8_t evt_type, uint8_t k_id, uint16_t dig_r, float EL, float AZ, float RANGE, float AREA, float lat, float lon, float alt, uint32_t RefID, CSTR RefUUID ){
  3933. uint32_t RetVal = 0;
  3934. if( m_bIsConnected ) {
  3935. char tQBuf[MAX_PATH_LEN];
  3936. if( RefUUID == NULL ) {
  3937. sprintf( tQBuf,"INSERT INTO events_archive SET node_id=%d, uuid='%s', ts=%d, ts_ms=%d, evt_type=%d, lrf_id=%d, range_digital=%d, azimuth=%0.6f, elevation=%0.6f, `range`=%0.2f, area=%0.3f, lat=%0.6f, lon=%0.6f, alt=%0.3f",
  3938. SRC,
  3939. UUID,
  3940. tss,
  3941. tsms,
  3942. evt_type,
  3943. k_id,
  3944. dig_r,
  3945. AZ,
  3946. EL,
  3947. RANGE,
  3948. AREA,
  3949. lat,
  3950. lon,
  3951. alt
  3952. );
  3953. } else {
  3954. sprintf( tQBuf,"INSERT INTO events_archive SET node_id=%d, uuid='%s', ts=%d, ts_ms=%d, evt_type=%d, lrf_id=%d, range_digital=%d, azimuth=%0.6f, elevation=%0.6f, `range`=%0.2f, area=%0.3f, lat=%0.6f, lon=%0.6f, alt=%0.3f, ref_uuid='%s'",
  3955. SRC,
  3956. UUID,
  3957. tss,
  3958. tsms,
  3959. evt_type,
  3960. k_id,
  3961. dig_r,
  3962. AZ,
  3963. EL,
  3964. RANGE,
  3965. AREA,
  3966. lat,
  3967. lon,
  3968. alt,
  3969. RefUUID
  3970. );
  3971. };
  3972. #ifdef DEBUG_ALL
  3973. LOG(tQBuf);
  3974. #endif
  3975. RetVal = (uint32_t) m_pDatabase->QueryID( tQBuf );
  3976. if( RetVal ) {
  3977. if (RefUUID == NULL) {
  3978. sprintf( tQBuf,"INSERT INTO events_cloud SET id=%d, node_id=%d, uuid='%s', ts=%d, ts_ms=%d, evt_type=%d, lrf_id=%d, range_digital=%d, azimuth=%0.6f, elevation=%0.6f, `range`=%0.2f, area=%0.3f, lat=%0.6f, lon=%0.6f, alt=%0.3f",
  3979. RetVal,
  3980. SRC,
  3981. UUID,
  3982. tss,
  3983. tsms,
  3984. evt_type,
  3985. k_id,
  3986. dig_r,
  3987. AZ,
  3988. EL,
  3989. RANGE,
  3990. AREA,
  3991. lat,
  3992. lon,
  3993. alt
  3994. );
  3995. } else {
  3996. sprintf( tQBuf,"INSERT INTO events_cloud SET id=%d, node_id=%d, uuid='%s', ts=%d, ts_ms=%d, evt_type=%d, lrf_id=%d, range_digital=%d, azimuth=%0.6f, elevation=%0.6f, `range`=%0.2f, area=%0.3f, lat=%0.6f, lon=%0.6f, alt=%0.3f, ref_uuid='%s'",
  3997. RetVal,
  3998. SRC,
  3999. UUID,
  4000. tss,
  4001. tsms,
  4002. evt_type,
  4003. k_id,
  4004. dig_r,
  4005. AZ,
  4006. EL,
  4007. RANGE,
  4008. AREA,
  4009. lat,
  4010. lon,
  4011. alt,
  4012. RefUUID
  4013. );
  4014. };
  4015. m_pDatabase->SilentQuery( tQBuf );
  4016. };
  4017. // Cleanup Mem Targets Older then 1 Hour
  4018. sprintf( tQBuf, "DELETE FROM events_cloud WHERE ts < ( UNIX_TIMESTAMP(NOW()) - 3600 )" );
  4019. m_pDatabase->SilentQuery( tQBuf );
  4020. };
  4021. return RetVal;
  4022. };
  4023. bool mysqlDBC::addDeviceDraw( uint32_t DBID, uint8_t type, uint8_t lrf, void *th_data, uint32_t th_size ){
  4024. bool rVal = false;
  4025. if( th_data != NULL && th_size ){
  4026. if( m_bIsConnected ){
  4027. CSTR tPData = m_pDatabase->escapeBinary( (uint8_t *) th_data, th_size );
  4028. if ( tPData ) {
  4029. CSTR tQBuf = (CSTR)malloc(BUF_4MB);
  4030. if( tQBuf ) {
  4031. sprintf( tQBuf, "DELETE FROM `lrf_draw` WHERE `node_id`=%d AND `lrf_id`=%d AND `type`=%d", DBID, lrf, type );
  4032. LOG( tQBuf );
  4033. m_pDatabase->SilentQuery( tQBuf );
  4034. sprintf( tQBuf, "INSERT INTO lrf_draw(node_id,ts,lrf_id,type,size,data) VALUES(%d,NOW(),%d,%d,%d,'%s')", DBID, lrf, type, th_size, tPData );
  4035. m_pDatabase->SilentQuery( tQBuf );
  4036. LOG( "Inserted Draw OK!" );
  4037. free( tQBuf );
  4038. rVal = true;
  4039. } else {
  4040. LOG_ERROR("Error Allocating Query Buffer!");
  4041. };
  4042. free( tPData );
  4043. } else {
  4044. LOG_ERROR( "Error escaping Pic Data!");
  4045. };
  4046. };
  4047. };
  4048. return rVal;
  4049. };
  4050. bool mysqlDBC::addVideoEvent( uint32_t evtID, uint32_t videoID, uint32_t clen ){
  4051. if( m_bIsConnected ) {
  4052. char tQBuf[MAX_PATH_LEN];
  4053. sprintf( tQBuf, "INSERT INTO `events_2_videos` SET `evt_id`=%d, `video_id`=%d, `frame`=%d", evtID, videoID, clen );
  4054. #ifdef DEBUG_ALL
  4055. LOG(tQBuf);
  4056. #endif
  4057. m_pDatabase->SilentQuery( tQBuf );
  4058. return true;
  4059. };
  4060. return true;
  4061. };
  4062. /*
  4063. bool mysqlDBC::addPictureEvent( uint32_t evtID, uint32_t pictureoID ){
  4064. if( m_bIsConnected ) {
  4065. char tQBuf[MAX_PATH_LEN];
  4066. sprintf( tQBuf, "INSERT INTO `events_2_pictures` SET `evt_id`=%d, `picture_id`=%d", evtID, pictureoID );
  4067. #ifdef DEBUG_ALL
  4068. LOG(tQBuf);
  4069. #endif
  4070. m_pDatabase->SilentQuery( tQBuf );
  4071. return true;
  4072. };
  4073. return true;
  4074. };
  4075. */
  4076. uint32_t mysqlDBC::addVideoRecord( uint32_t streamID, CSTR md5, CSTR ext, uint32_t ts, uint32_t tsms, uint32_t fps ){
  4077. uint32_t tID = 0;
  4078. if( m_bIsConnected ) {
  4079. char tQBuf[MAX_PATH_LEN];
  4080. sprintf( tQBuf, "INSERT INTO `videos` SET `media_stream_id`=%d, `uts`=%d, `uts_ms`=%d, `md5`='%s', `ext`='%s', `fps`=%d ", streamID, ts, tsms, md5, ext, fps );
  4081. #ifdef DEBUG_ALL
  4082. LOG(tQBuf);
  4083. #endif
  4084. tID = (uint32_t) m_pDatabase->QueryID( tQBuf );
  4085. }
  4086. return tID;
  4087. };
  4088. bool mysqlDBC::addPicture( DBC_SNAPSHOT_DATA *ptr, CSTR ext ){
  4089. bool rVal = false;
  4090. if( ptr != NULL ){
  4091. if( m_bIsConnected ){
  4092. CSTR tPData = m_pDatabase->escapeBinary( ptr->data, ptr->data_size );
  4093. if ( tPData ) {
  4094. uint32_t pic_id;
  4095. CSTR tQBuf = (CSTR)malloc(BUF_4MB);
  4096. if( tQBuf ) {
  4097. //sprintf( tQBuf, "INSERT INTO `pictures` SET `media_stream_id`=%d, `ts`=NOW(), `md5`='%s', `ext`='%s'",
  4098. sprintf( tQBuf, "INSERT INTO pictures(media_stream_id,ts,md5,ext,data) VALUES(%d,NOW(),'%s','%s','%s')",
  4099. ptr->stream_id, ptr->md5, ext, tPData );
  4100. pic_id = (uint32_t) m_pDatabase->QueryID( tQBuf );
  4101. if ( pic_id ) {
  4102. for( DBC_INT_LIST::iterator idx = ptr->assoc_event_ids.begin(); idx < ptr->assoc_event_ids.end(); idx++ ) {
  4103. sprintf( tQBuf, "INSERT INTO `events_2_pictures` SET `evt_id`=%d, `picture_id`=%d", (*idx), pic_id );
  4104. m_pDatabase->SilentQuery( tQBuf );
  4105. };
  4106. rVal = true;
  4107. };
  4108. free( tQBuf );
  4109. } else {
  4110. LOG_ERROR("Error Allocating Query Buffer!");
  4111. };
  4112. free( tPData );
  4113. } else {
  4114. LOG_ERROR( "Error escaping Pic Data!");
  4115. };
  4116. };
  4117. };
  4118. return rVal;
  4119. };
  4120. bool mysqlDBC::updateLRFDetectionProfile( uint32_t lrfID, uint8_t profileID, bool master, uint16_t nOrder, uint16_t nOffset, uint16_t nDelta, uint16_t nWidth, uint16_t nFlip, uint16_t nSun, uint8_t bSST, uint32_t GP, uint32_t spikes ){
  4121. if( m_bIsConnected ) {
  4122. char tQBuf[MAX_PATH_LEN];
  4123. if( master ) {
  4124. sprintf( tQBuf, "INSERT INTO `lrf_detection_profiles` SET `aux_id`=%d, `profile_id`=%d, `master`=b'1', `order`=%d, `offset`=%d, `delta`=%d, `flip`=%d, `width`=%d, `sst`=%d, `sun`=%d, `gp`=%d, `spikes`=%d ON DUPLICATE KEY UPDATE `order`=%d, `offset`=%d, `delta`=%d, `flip`=%d, `width`=%d, `sst`=%d, `sun`=%d, `gp`=%d, `spikes`=%d",
  4125. lrfID,
  4126. profileID,
  4127. nOrder,
  4128. nOffset,
  4129. nDelta,
  4130. nFlip,
  4131. nWidth,
  4132. bSST,
  4133. nSun,
  4134. GP,
  4135. spikes,
  4136. nOrder,
  4137. nOffset,
  4138. nDelta,
  4139. nFlip,
  4140. nWidth,
  4141. bSST,
  4142. nSun,
  4143. GP,
  4144. spikes );
  4145. } else {
  4146. sprintf( tQBuf, "INSERT INTO `lrf_detection_profiles` SET `aux_id`=%d, `profile_id`=%d, `master`=b'0', `order`=%d, `offset`=%d, `delta`=%d, `flip`=%d, `width`=%d, `sst`=%d, `sun`=%d, `gp`=%d, `spikes`=%d ON DUPLICATE KEY UPDATE `order`=%d, `offset`=%d, `delta`=%d, `flip`=%d, `width`=%d, `sst`=%d, `sun`=%d, `gp`=%d, `spikes`=%d",
  4147. lrfID,
  4148. profileID,
  4149. nOrder,
  4150. nOffset,
  4151. nDelta,
  4152. nFlip,
  4153. nWidth,
  4154. bSST,
  4155. nSun,
  4156. GP,
  4157. spikes,
  4158. nOrder,
  4159. nOffset,
  4160. nDelta,
  4161. nFlip,
  4162. nWidth,
  4163. bSST,
  4164. nSun,
  4165. GP,
  4166. spikes );
  4167. };
  4168. #ifdef DEBUG_ALL
  4169. LOG(tQBuf);
  4170. #endif
  4171. m_pDatabase->SilentQuery( tQBuf );
  4172. return true;
  4173. };
  4174. return false;
  4175. };
  4176. bool mysqlDBC::updateLRFSerial( uint32_t lrfID, CSTR Serial ){
  4177. if( m_bIsConnected ) {
  4178. char tQBuf[MAX_PATH_LEN];
  4179. CSTR tES = m_pDatabase->escapeString( Serial );
  4180. if( tES ) {
  4181. sprintf( tQBuf, "UPDATE `lrf_sensors` SET `serial`='%s' WHERE `id`=%d", tES, lrfID );
  4182. free( tES );
  4183. #ifdef DEBUG_ALL
  4184. LOG(tQBuf);
  4185. #endif
  4186. m_pDatabase->SilentQuery( tQBuf );
  4187. return true;
  4188. };
  4189. };
  4190. return false;
  4191. };
  4192. bool mysqlDBC::updateLRFVerison( uint32_t lrfID, CSTR version ){
  4193. if( m_bIsConnected ) {
  4194. char tQBuf[MAX_PATH_LEN];
  4195. CSTR tES = m_pDatabase->escapeString( version );
  4196. if( tES ) {
  4197. sprintf( tQBuf, "UPDATE `lrf_sensors` SET `version`='%s' WHERE `id`=%d", tES, lrfID );
  4198. free( tES );
  4199. #ifdef DEBUG_ALL
  4200. LOG(tQBuf);
  4201. #endif
  4202. m_pDatabase->SilentQuery( tQBuf );
  4203. return true;
  4204. };
  4205. };
  4206. return false;
  4207. };
  4208. bool mysqlDBC::update3DRuntimeStatus( uint32_t lrfID, ALG_RUN_STATUS *ptr ){
  4209. if( m_bIsConnected ) {
  4210. char tQBuf[MAX_PATH_LEN];
  4211. sprintf( tQBuf, "INSERT INTO `lrf_runtime_status` SET `lrf_id`=%d ON DUPLICATE KEY UPDATE `lrf_id`=`lrf_id`", lrfID );
  4212. #ifdef DEBUG_ALL
  4213. LOG(tQBuf);
  4214. #endif
  4215. m_pDatabase->SilentQuery( tQBuf );
  4216. sprintf( tQBuf,
  4217. "UPDATE `lrf_runtime_status` SET "
  4218. "`hw_status`=%d,"
  4219. "`detecting_kernels`=%d,"
  4220. "`th_ready`=%d,"
  4221. "`master_flips`=%d,"
  4222. "`slave_flips`=%d,"
  4223. "`twinc`=%d,"
  4224. "`master_mp_0`=%d,"
  4225. "`master_mp_1`=%d,"
  4226. "`master_mp_2`=%d,"
  4227. "`master_mp_3`=%d,"
  4228. "`master_mp_4`=%d,"
  4229. "`master_mp_5`=%d,"
  4230. "`master_mp_6`=%d,"
  4231. "`master_mp_7`=%d,"
  4232. "`master_gp_0`=%d,"
  4233. "`master_gp_1`=%d,"
  4234. "`master_gp_2`=%d,"
  4235. "`master_gp_3`=%d,"
  4236. "`master_gp_4`=%d,"
  4237. "`master_gp_5`=%d,"
  4238. "`master_gp_6`=%d,"
  4239. "`master_gp_7`=%d,"
  4240. "`master_wp_0`=%d,"
  4241. "`master_wp_1`=%d,"
  4242. "`master_wp_2`=%d,"
  4243. "`master_wp_3`=%d,"
  4244. "`master_wp_4`=%d,"
  4245. "`master_wp_5`=%d,"
  4246. "`master_wp_6`=%d,"
  4247. "`master_wp_7`=%d,"
  4248. "`slave_mp_0`=%d,"
  4249. "`slave_mp_1`=%d,"
  4250. "`slave_mp_2`=%d,"
  4251. "`slave_mp_3`=%d,"
  4252. "`slave_mp_4`=%d,"
  4253. "`slave_mp_5`=%d,"
  4254. "`slave_mp_6`=%d,"
  4255. "`slave_mp_7`=%d,"
  4256. "`slave_gp_0`=%d,"
  4257. "`slave_gp_1`=%d,"
  4258. "`slave_gp_2`=%d,"
  4259. "`slave_gp_3`=%d,"
  4260. "`slave_gp_4`=%d,"
  4261. "`slave_gp_5`=%d,"
  4262. "`slave_gp_6`=%d,"
  4263. "`slave_gp_7`=%d,"
  4264. "`slave_wp_0`=%d,"
  4265. "`slave_wp_1`=%d,"
  4266. "`slave_wp_2`=%d,"
  4267. "`slave_wp_3`=%d,"
  4268. "`slave_wp_4`=%d,"
  4269. "`slave_wp_5`=%d,"
  4270. "`slave_wp_6`=%d,"
  4271. "`slave_wp_7`=%d"
  4272. " WHERE `lrf_id`=%d",
  4273. ptr->HW_STATUS,
  4274. ptr->DETECTING_LRF,
  4275. ptr->TH_READY,
  4276. ptr->MASTER_FLIP_CNT,
  4277. ptr->SLAVE_FLIP_CNT,
  4278. ptr->TWINC_STATUS,
  4279. ptr->MASTER_MP[0],
  4280. ptr->MASTER_MP[1],
  4281. ptr->MASTER_MP[2],
  4282. ptr->MASTER_MP[3],
  4283. ptr->MASTER_MP[4],
  4284. ptr->MASTER_MP[5],
  4285. ptr->MASTER_MP[6],
  4286. ptr->MASTER_MP[7],
  4287. ptr->MASTER_GP[0],
  4288. ptr->MASTER_GP[1],
  4289. ptr->MASTER_GP[2],
  4290. ptr->MASTER_GP[3],
  4291. ptr->MASTER_GP[4],
  4292. ptr->MASTER_GP[5],
  4293. ptr->MASTER_GP[6],
  4294. ptr->MASTER_GP[7],
  4295. ptr->MASTER_WP[0],
  4296. ptr->MASTER_WP[1],
  4297. ptr->MASTER_WP[2],
  4298. ptr->MASTER_WP[3],
  4299. ptr->MASTER_WP[4],
  4300. ptr->MASTER_WP[5],
  4301. ptr->MASTER_WP[6],
  4302. ptr->MASTER_WP[7],
  4303. ptr->SLAVE_MP[0],
  4304. ptr->SLAVE_MP[1],
  4305. ptr->SLAVE_MP[2],
  4306. ptr->SLAVE_MP[3],
  4307. ptr->SLAVE_MP[4],
  4308. ptr->SLAVE_MP[5],
  4309. ptr->SLAVE_MP[6],
  4310. ptr->SLAVE_MP[7],
  4311. ptr->SLAVE_GP[0],
  4312. ptr->SLAVE_GP[1],
  4313. ptr->SLAVE_GP[2],
  4314. ptr->SLAVE_GP[3],
  4315. ptr->SLAVE_GP[4],
  4316. ptr->SLAVE_GP[5],
  4317. ptr->SLAVE_GP[6],
  4318. ptr->SLAVE_GP[7],
  4319. ptr->SLAVE_WP[0],
  4320. ptr->SLAVE_WP[1],
  4321. ptr->SLAVE_WP[2],
  4322. ptr->SLAVE_WP[3],
  4323. ptr->SLAVE_WP[4],
  4324. ptr->SLAVE_WP[5],
  4325. ptr->SLAVE_WP[6],
  4326. ptr->SLAVE_WP[7],
  4327. lrfID
  4328. );
  4329. #ifdef DEBUG_ALL
  4330. LOG(tQBuf);
  4331. #endif
  4332. m_pDatabase->SilentQuery( tQBuf );
  4333. return true;
  4334. };
  4335. return false;
  4336. };
  4337. bool mysqlDBC::setLRFDataStatus( uint32_t lrfID, uint8_t ST ){
  4338. if( m_bIsConnected ) {
  4339. char tQBuf[MAX_PATH_LEN];
  4340. sprintf( tQBuf, "UPDATE `lrf_sensors` SET `data_status`=%d WHERE `id`=%d", ST, lrfID );
  4341. #ifdef DEBUG_ALL
  4342. LOG(tQBuf);
  4343. #endif
  4344. m_pDatabase->SilentQuery( tQBuf );
  4345. return true;
  4346. };
  4347. return false;
  4348. };
  4349. bool mysqlDBC::setLRFDetectionProfile( uint32_t lrfID, uint8_t profileID ){
  4350. if( m_bIsConnected ) {
  4351. char tQBuf[MAX_PATH_LEN];
  4352. sprintf( tQBuf, "UPDATE `lrf_sensors` SET `detection_profile_id`=%d WHERE `id`=%d", profileID, lrfID );
  4353. #ifdef DEBUG_ALL
  4354. LOG(tQBuf);
  4355. #endif
  4356. m_pDatabase->SilentQuery( tQBuf );
  4357. return true;
  4358. };
  4359. return false;
  4360. };
  4361. bool mysqlDBC::setLRFMaskStatus( uint32_t maskID, bool status ){
  4362. if( m_bIsConnected ) {
  4363. char tQBuf[MAX_PATH_LEN];
  4364. char S[2];
  4365. if (status ) {
  4366. S[0] = 'E';
  4367. S[1] = (char)0;
  4368. } else {
  4369. S[0] = 'D';
  4370. S[1] = (char)0;
  4371. };
  4372. sprintf( tQBuf, "UPDATE `lrf_masks` SET `status`='%s' WHERE `id`=%d", S, maskID );
  4373. #ifdef DEBUG_ALL
  4374. LOG(tQBuf);
  4375. #endif
  4376. m_pDatabase->SilentQuery( tQBuf );
  4377. return true;
  4378. };
  4379. return false;
  4380. };
  4381. bool mysqlDBC::setLRFAltSerial( uint32_t lrfID, CSTR Serial ){
  4382. if( m_bIsConnected ) {
  4383. char tQBuf[MAX_PATH_LEN];
  4384. sprintf( tQBuf, "UPDATE `lrf_sensors` SET `alt_serial`='%s' WHERE `id`=%d", Serial, lrfID );
  4385. #ifdef DEBUG_ALL
  4386. LOG(tQBuf);
  4387. #endif
  4388. m_pDatabase->SilentQuery( tQBuf );
  4389. return true;
  4390. };
  4391. return false;
  4392. };
  4393. bool mysqlDBC::setLRFAltVerison( uint32_t lrfID, CSTR version ){
  4394. if( m_bIsConnected ) {
  4395. char tQBuf[MAX_PATH_LEN];
  4396. sprintf( tQBuf, "UPDATE `lrf_sensors` SET `alt_version`='%s' WHERE `id`=%d", version, lrfID );
  4397. #ifdef DEBUG_ALL
  4398. LOG(tQBuf);
  4399. #endif
  4400. m_pDatabase->SilentQuery( tQBuf );
  4401. return true;
  4402. };
  4403. return false;
  4404. };
  4405. bool mysqlDBC::setStreamValid( uint32_t streamID, bool status ){
  4406. if( m_bIsConnected ) {
  4407. char tQBuf[MAX_PATH_LEN];
  4408. if ( status ) {
  4409. sprintf(tQBuf, "UPDATE `media_streams` SET `valid`=1 WHERE `id`=%d", streamID);
  4410. } else {
  4411. sprintf(tQBuf, "UPDATE `media_streams` SET `valid`=0 WHERE `id`=%d", streamID);
  4412. };
  4413. #ifdef DEBUG_ALL
  4414. LOG(tQBuf);
  4415. #endif
  4416. m_pDatabase->SilentQuery( tQBuf );
  4417. return true;
  4418. };
  4419. return false;
  4420. };
  4421. bool mysqlDBC::updateAFPBox( uint32_t filterID, CSTR Tag, float x, float y, float z ){
  4422. if( m_bIsConnected ) {
  4423. char tQBuf[MAX_PATH_LEN];
  4424. sprintf( tQBuf, "INSERT INTO `target_filter_apf_boxes` SET `filter_id`=%d, `tag`='%s', `ts`=NOW(), `x`=%0.3f, `y`=%0.3f, `z`=%0.3f ON DUPLICATE KEY UPDATE `ts`=NOW(), `x`=%0.3f, `y`=%0.3f, `z`=%0.3f",
  4425. filterID,
  4426. Tag,
  4427. x,y,z,
  4428. x,y,z
  4429. );
  4430. #ifdef DEBUG_ALL
  4431. LOG(tQBuf);
  4432. #endif
  4433. m_pDatabase->SilentQuery( tQBuf );
  4434. return true;
  4435. };
  4436. return false;
  4437. };
  4438. DBC_MODULE_EMBED_VIDEO_DATA *mysqlDBC::getEmbedVideoData( uint32_t ID ){
  4439. DBC_MODULE_EMBED_VIDEO_DATA *tPtr = NULL;
  4440. if( m_bIsConnected ) {
  4441. char tQBuf[MAX_PATH_LEN];
  4442. AAssoc *result;
  4443. sprintf( tQBuf, "SELECT * FROM `module_eve` WHERE `id`=%d", ID );
  4444. #ifdef DEBUG_ALL
  4445. LOG(tQBuf);
  4446. #endif
  4447. result = m_pDatabase->Query( tQBuf );
  4448. if( result!= NULL ) {
  4449. if( result->size() > 0 ) {
  4450. Assoc *cArr;
  4451. tPtr = (DBC_MODULE_EMBED_VIDEO_DATA*)malloc(sizeof(DBC_MODULE_EMBED_VIDEO_DATA));
  4452. if( tPtr!= NULL ) {
  4453. Assoc::iterator it;
  4454. memset(tPtr,0,sizeof(DBC_MODULE_EMBED_VIDEO_DATA));
  4455. cArr = result->at(0);
  4456. it = cArr->find("output_mode");
  4457. if( it != cArr->end() ){
  4458. tPtr->output_mode = atoi( it->second.c_str() );
  4459. };
  4460. it = cArr->find("web_port");
  4461. if( it != cArr->end() ){
  4462. tPtr->port = atoi( it->second.c_str() );
  4463. };
  4464. it = cArr->find("width");
  4465. if( it != cArr->end() ){
  4466. tPtr->width = atoi( it->second.c_str() );
  4467. };
  4468. it = cArr->find("height");
  4469. if( it != cArr->end() ){
  4470. tPtr->height = atoi( it->second.c_str() );
  4471. };
  4472. it = cArr->find("compression_quality");
  4473. if( it != cArr->end() ){
  4474. tPtr->compression_quality = atoi( it->second.c_str() );
  4475. };
  4476. it = cArr->find("show_ts");
  4477. if( it != cArr->end() ){
  4478. tPtr->show_ts = (bool)atoi( it->second.c_str() );
  4479. };
  4480. it = cArr->find("ts_x");
  4481. if( it != cArr->end() ){
  4482. tPtr->ts_x = atoi( it->second.c_str() );
  4483. };
  4484. it = cArr->find("ts_y");
  4485. if( it != cArr->end() ){
  4486. tPtr->ts_y = atoi( it->second.c_str() );
  4487. };
  4488. it = cArr->find("ts_font_face");
  4489. if( it != cArr->end() ){
  4490. tPtr->ts_font_face = atoi( it->second.c_str() );
  4491. };
  4492. it = cArr->find("ts_font_scale");
  4493. if( it != cArr->end() ){
  4494. tPtr->ts_font_scale = atof( it->second.c_str() );
  4495. };
  4496. it = cArr->find("ts_font_thickness");
  4497. if( it != cArr->end() ){
  4498. tPtr->ts_font_thickness = atoi( it->second.c_str() );
  4499. };
  4500. it = cArr->find("ts_line_type");
  4501. if( it != cArr->end() ){
  4502. tPtr->ts_line_type = atoi( it->second.c_str() );
  4503. };
  4504. it = cArr->find("ts_transperant");
  4505. if( it != cArr->end() ){
  4506. tPtr->ts_transperant = (bool)atoi( it->second.c_str() );
  4507. };
  4508. it = cArr->find("show_label");
  4509. if( it != cArr->end() ){
  4510. tPtr->show_label = (bool)atoi( it->second.c_str() );
  4511. };
  4512. it = cArr->find("label_x");
  4513. if( it != cArr->end() ){
  4514. tPtr->label_x = atoi( it->second.c_str() );
  4515. };
  4516. it = cArr->find("label_y");
  4517. if( it != cArr->end() ){
  4518. tPtr->label_y = atoi( it->second.c_str() );
  4519. };
  4520. it = cArr->find("label_font_face");
  4521. if( it != cArr->end() ){
  4522. tPtr->label_font_face = atoi( it->second.c_str() );
  4523. };
  4524. it = cArr->find("label_font_scale");
  4525. if( it != cArr->end() ){
  4526. tPtr->label_font_scale = atof( it->second.c_str() );
  4527. };
  4528. it = cArr->find("label_font_thickness");
  4529. if( it != cArr->end() ){
  4530. tPtr->label_font_thickness = atoi( it->second.c_str() );
  4531. };
  4532. it = cArr->find("label_line_type");
  4533. if( it != cArr->end() ){
  4534. tPtr->label_line_type = atoi( it->second.c_str() );
  4535. };
  4536. it = cArr->find("label_transperant");
  4537. if( it != cArr->end() ){
  4538. tPtr->label_transperant = (bool) atoi( it->second.c_str() );
  4539. };
  4540. it = cArr->find("show_logo");
  4541. if( it != cArr->end() ){
  4542. tPtr->show_logo = (bool) atoi( it->second.c_str() );
  4543. };
  4544. it = cArr->find("logo_w");
  4545. if( it != cArr->end() ){
  4546. tPtr->logo_w = atoi( it->second.c_str() );
  4547. };
  4548. it = cArr->find("logo_h");
  4549. if( it != cArr->end() ){
  4550. tPtr->logo_h = atoi( it->second.c_str() );
  4551. };
  4552. it = cArr->find("logo_x");
  4553. if( it != cArr->end() ){
  4554. tPtr->logo_x = atoi( it->second.c_str() );
  4555. };
  4556. it = cArr->find("logo_y");
  4557. if( it != cArr->end() ){
  4558. tPtr->logo_y = atoi( it->second.c_str() );
  4559. };
  4560. it = cArr->find("logo_md5");
  4561. if( it != cArr->end() ){
  4562. strncpy( tPtr->logo_md5, it->second.c_str(),32);
  4563. tPtr->logo_md5[32]=(char)0;
  4564. };
  4565. };
  4566. };
  4567. };
  4568. deleteResult( result );
  4569. };
  4570. return tPtr;
  4571. };
  4572. DBC_EVT_RECORD *mysqlDBC::getEventByUUID( CSTR UUID ){
  4573. DBC_EVT_RECORD *tPtr = NULL;
  4574. if( m_bIsConnected ) {
  4575. char tQBuf[MAX_PATH_LEN];
  4576. AAssoc *result;
  4577. sprintf( tQBuf, "SELECT * FROM events_cloud WHERE uuid = '%s'", UUID );
  4578. #ifdef DEBUG_ALL
  4579. LOG(tQBuf);
  4580. #endif
  4581. result = m_pDatabase->Query( tQBuf );
  4582. if( result!= NULL ) {
  4583. if( result->size() > 0 ) {
  4584. Assoc *cArr;
  4585. tPtr = (DBC_EVT_RECORD*)malloc(sizeof(DBC_EVT_RECORD));
  4586. if( tPtr!= NULL ) {
  4587. Assoc::iterator it;
  4588. memset(tPtr,0,sizeof(DBC_EVT_RECORD));
  4589. cArr = result->at(0);
  4590. it = cArr->find("id");
  4591. if( it != cArr->end() ){
  4592. tPtr->id = atoi( it->second.c_str() );
  4593. };
  4594. it = cArr->find("node_id");
  4595. if( it != cArr->end() ){
  4596. tPtr->node_id = atoi( it->second.c_str() );
  4597. };
  4598. it = cArr->find("uuid");
  4599. if( it != cArr->end() ){
  4600. strncpy( tPtr->uuid, it->second.c_str(),64 );
  4601. };
  4602. it = cArr->find("ts");
  4603. if( it != cArr->end() ){
  4604. tPtr->ts_s = atoi( it->second.c_str() );
  4605. };
  4606. it = cArr->find("ts_ms");
  4607. if( it != cArr->end() ){
  4608. tPtr->ts_ms = atoi( it->second.c_str() );
  4609. };
  4610. it = cArr->find("evt_type");
  4611. if( it != cArr->end() ){
  4612. tPtr->type = atoi( it->second.c_str() );
  4613. };
  4614. it = cArr->find("range_digital");
  4615. if( it != cArr->end() ){
  4616. tPtr->range_digital = atoi( it->second.c_str() );
  4617. };
  4618. it = cArr->find("azimuth");
  4619. if( it != cArr->end() ){
  4620. tPtr->az = atof( it->second.c_str() );
  4621. };
  4622. it = cArr->find("elevation");
  4623. if( it != cArr->end() ){
  4624. tPtr->el = atof( it->second.c_str() );
  4625. };
  4626. it = cArr->find("range");
  4627. if( it != cArr->end() ){
  4628. tPtr->ra = atof( it->second.c_str() );
  4629. };
  4630. it = cArr->find("area");
  4631. if( it != cArr->end() ){
  4632. tPtr->area = atof( it->second.c_str() );
  4633. };
  4634. it = cArr->find("lat");
  4635. if( it != cArr->end() ){
  4636. tPtr->lat = atof( it->second.c_str() );
  4637. };
  4638. it = cArr->find("lon");
  4639. if( it != cArr->end() ){
  4640. tPtr->lon = atof( it->second.c_str() );
  4641. };
  4642. it = cArr->find("alt");
  4643. if( it != cArr->end() ){
  4644. tPtr->alt = atof( it->second.c_str() );
  4645. };
  4646. it = cArr->find("ref_id");
  4647. if( it != cArr->end() ){
  4648. tPtr->ref_id = atoi( it->second.c_str() );
  4649. };
  4650. it = cArr->find("ref_uuid");
  4651. if( it != cArr->end() ){
  4652. strncpy( tPtr->ref_uuid, it->second.c_str(),64 );
  4653. };
  4654. };
  4655. };
  4656. };
  4657. deleteResult( result );
  4658. };
  4659. return tPtr;
  4660. };
  4661. #undef LOG
  4662. #undef LOG_ERROR