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.

4885 lines
182 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
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_INI *mysqlDBC::getINIData( uint32_t lrfID ){
  1626. DBC_LRF_INI * tVal = NULL;
  1627. if(m_bIsConnected){
  1628. char tQBuf[CTEXT];
  1629. AAssoc *result;
  1630. sprintf(tQBuf, "SELECT * FROM lrf_ini_settings WHERE `sensor_id`=%d", lrfID );
  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_INI*) malloc(sizeof(DBC_LRF_INI));
  1639. if( tVal != NULL ) {
  1640. memset( tVal, 0 , sizeof(DBC_LRF_INI));
  1641. Assoc::iterator it;
  1642. cArr = result->at(0);
  1643. it = cArr->find("AUTORESET_ENABLE");
  1644. if( it != cArr->end() ){
  1645. tVal->_AUTO_RESET_ENABLE = (bool) atoi( it->second.c_str() );
  1646. };
  1647. it = cArr->find("AUTORESET_INTERLEAVE");
  1648. if( it != cArr->end() ){
  1649. tVal->_AUTO_RESET_INTERLEAVE = atoi( it->second.c_str() );
  1650. };
  1651. it = cArr->find("AUTORESET_TIMEOUT");
  1652. if( it != cArr->end() ){
  1653. tVal->_AUTO_RESET_TIMEOUT = atoi( it->second.c_str() );
  1654. };
  1655. it = cArr->find("BOARD_TEMPERATURE");
  1656. if( it != cArr->end() ){
  1657. tVal->_BOARD_TEMPERATURE = atoi( it->second.c_str() );
  1658. };
  1659. it = cArr->find("BOARD_ZEROSHIFT");
  1660. if( it != cArr->end() ){
  1661. tVal->_BOARD_ZEROSHIFT = atoi( it->second.c_str() );
  1662. };
  1663. it = cArr->find("BOARD_SPEED");
  1664. if( it != cArr->end() ){
  1665. tVal->_BOARD_SPEED = atoi( it->second.c_str() );
  1666. };
  1667. it = cArr->find("RUN_DIR");
  1668. if( it != cArr->end() ){
  1669. tVal->_RUN_DIR = atoi( it->second.c_str() );
  1670. };
  1671. it = cArr->find("JUST_MOVING_TARGETS");
  1672. if( it != cArr->end() ){
  1673. tVal->_JUST_MOVING_TARGETS = (bool) atoi( it->second.c_str() );
  1674. };
  1675. it = cArr->find("JUST_MOVING_RADIAL");
  1676. if( it != cArr->end() ){
  1677. tVal->_JUST_MOVING_RADIAL = (bool) atoi( it->second.c_str() );
  1678. };
  1679. it = cArr->find("JUST_MOVING_DISTANCE");
  1680. if( it != cArr->end() ){
  1681. tVal->_JUST_MOVING_DISTANCE = (bool) atoi( it->second.c_str() );
  1682. };
  1683. it = cArr->find("FREEZ_FIRST_TH");
  1684. if( it != cArr->end() ){
  1685. tVal->_FREEZ_FIRST_TH = (bool) atoi( it->second.c_str() );
  1686. };
  1687. it = cArr->find("SAVE_FIRST_TH");
  1688. if( it != cArr->end() ){
  1689. tVal->_SAVE_FIRST_TH = (bool) atoi( it->second.c_str() );
  1690. };
  1691. };
  1692. };
  1693. };
  1694. deleteResult( result );
  1695. };
  1696. return tVal;
  1697. };
  1698. DBC_LRF_DATA *mysqlDBC::getLRFData( uint32_t ID ){
  1699. DBC_LRF_DATA * tVal = NULL;
  1700. if(m_bIsConnected){
  1701. char tQBuf[CTEXT];
  1702. AAssoc *result;
  1703. sprintf(tQBuf, "SELECT * FROM lrf_sensors WHERE `id`=%d", ID );
  1704. #ifdef DEBUG
  1705. LOG(tQBuf);
  1706. #endif
  1707. result = m_pDatabase->Query( tQBuf );
  1708. if( result!= NULL ) {
  1709. if( result->size() > 0 ) {
  1710. Assoc *cArr;
  1711. tVal = (DBC_LRF_DATA*) malloc(sizeof(DBC_LRF_DATA));
  1712. if( tVal != NULL ) {
  1713. memset( tVal, 0 , sizeof(DBC_LRF_DATA));
  1714. Assoc::iterator it;
  1715. tVal->id = ID;
  1716. cArr = result->at(0);
  1717. it = cArr->find("data_status");
  1718. if( it != cArr->end() ){
  1719. tVal->data_status = atoi( it->second.c_str() );
  1720. };
  1721. it = cArr->find("serial");
  1722. if( it != cArr->end() ){
  1723. strncpy( tVal->serial, it->second.c_str(), sizeof(tVal->serial)-1 );
  1724. tVal->serial[sizeof(tVal->serial)-1]=(char)0;
  1725. };
  1726. it = cArr->find("version");
  1727. if( it != cArr->end() ){
  1728. strncpy( tVal->version, it->second.c_str(), sizeof(tVal->version)-1 );
  1729. tVal->version[sizeof(tVal->version)-1]=(char)0;
  1730. };
  1731. it = cArr->find("x");
  1732. if( it != cArr->end() ){
  1733. tVal->x = atof( it->second.c_str() );
  1734. };
  1735. it = cArr->find("y");
  1736. if( it != cArr->end() ){
  1737. tVal->y = atof( it->second.c_str() );
  1738. };
  1739. it = cArr->find("z");
  1740. if( it != cArr->end() ){
  1741. tVal->z = atof( it->second.c_str() );
  1742. };
  1743. it = cArr->find("x_rot");
  1744. if( it != cArr->end() ){
  1745. tVal->x_rot = atof( it->second.c_str() );
  1746. };
  1747. it = cArr->find("y_rot");
  1748. if( it != cArr->end() ){
  1749. tVal->y_rot = atof( it->second.c_str() );
  1750. };
  1751. it = cArr->find("z_rot");
  1752. if( it != cArr->end() ){
  1753. tVal->z_rot = atof( it->second.c_str() );
  1754. };
  1755. it = cArr->find("uart_id");
  1756. if( it != cArr->end() ){
  1757. tVal->uart_id = atoi( it->second.c_str() );
  1758. };
  1759. it = cArr->find("device_id");
  1760. if( it != cArr->end() ){
  1761. tVal->device_id = atoi( it->second.c_str() );
  1762. };
  1763. it = cArr->find("ip_address");
  1764. if( it != cArr->end() ){
  1765. sprintf( tVal->master_host, it->second.c_str() );
  1766. };
  1767. it = cArr->find("aux_ip_address");
  1768. if( it != cArr->end() ){
  1769. sprintf( tVal->slave_host, it->second.c_str() );
  1770. };
  1771. it = cArr->find("port");
  1772. if( it != cArr->end() ){
  1773. tVal->master_port = atoi( it->second.c_str() );
  1774. };
  1775. it = cArr->find("aux_port");
  1776. if( it != cArr->end() ){
  1777. tVal->slave_port = atoi( it->second.c_str() );
  1778. };
  1779. it = cArr->find("auto_draw");
  1780. if( it != cArr->end() ){
  1781. tVal->auto_draw = atoi( it->second.c_str() );
  1782. };
  1783. it = cArr->find("filter_id");
  1784. if( it != cArr->end() ){
  1785. tVal->filter_id = atoi( it->second.c_str() );
  1786. };
  1787. //it = cArr->find("enabled_lrf");
  1788. //if( it != cArr->end() ){
  1789. // tVal->enabled_lrf = atoi( it->second.c_str() );
  1790. //};
  1791. it = cArr->find("max_range");
  1792. if( it != cArr->end() ){
  1793. tVal->max_range = atof( it->second.c_str() );
  1794. };
  1795. it = cArr->find("base_shift");
  1796. if( it != cArr->end() ){
  1797. tVal->base_shift = atoi( it->second.c_str() );
  1798. };
  1799. it = cArr->find("mirror_shift");
  1800. if( it != cArr->end() ){
  1801. tVal->mirror_shift = atoi( it->second.c_str() );
  1802. };
  1803. it = cArr->find("detection_profile_id");
  1804. if( it != cArr->end() ){
  1805. tVal->detection_profile_id = atoi( it->second.c_str() );
  1806. };
  1807. it = cArr->find("draw_lrf_id");
  1808. if( it != cArr->end() ){
  1809. tVal->draw_lrf_id = atoi( it->second.c_str() );
  1810. };
  1811. it = cArr->find("width_table_id");
  1812. if( it != cArr->end() ){
  1813. tVal->width_table_id = atoi( it->second.c_str() );
  1814. };
  1815. it = cArr->find("zoom_table_id");
  1816. if( it != cArr->end() ){
  1817. tVal->zoom_table_id = atoi( it->second.c_str() );
  1818. };
  1819. it = cArr->find("embd_cam");
  1820. if( it != cArr->end() ){
  1821. tVal->embd_cam = atoi( it->second.c_str() );
  1822. };
  1823. it = cArr->find("embd_cam_auto");
  1824. if( it != cArr->end() ){
  1825. tVal->embd_cam_auto = (bool)atoi( it->second.c_str() );
  1826. };
  1827. it = cArr->find("embd_dc");
  1828. if( it != cArr->end() ){
  1829. tVal->embd_dc = atoi( it->second.c_str() );
  1830. };
  1831. it = cArr->find("autoreset");
  1832. if( it != cArr->end() ){
  1833. tVal->autoreset = (bool)atoi( it->second.c_str() );
  1834. };
  1835. it = cArr->find("force_settings");
  1836. if( it != cArr->end() ){
  1837. tVal->force_settings = (bool)atoi( it->second.c_str() );
  1838. };
  1839. };
  1840. };
  1841. };
  1842. deleteResult( result );
  1843. };
  1844. return tVal;
  1845. };
  1846. uint8_t mysqlDBC::getLRFDataStatus( uint32_t ID ){
  1847. uint8_t RetVal = 0;
  1848. if(m_bIsConnected){
  1849. char tQBuf[CTEXT];
  1850. AAssoc *result;
  1851. sprintf(tQBuf, "SELECT `data_status` FROM `lrf_sensors` WHERE `id`=%d", ID );
  1852. #ifdef DEBUG
  1853. LOG(tQBuf);
  1854. #endif
  1855. result = m_pDatabase->Query( tQBuf );
  1856. if( result!= NULL ) {
  1857. if( result->size() > 0 ) {
  1858. Assoc *cArr;
  1859. Assoc::iterator it;
  1860. cArr = result->at(0);
  1861. it = cArr->find("data_status");
  1862. if( it != cArr->end() ){
  1863. RetVal = atoi( it->second.c_str() );
  1864. };
  1865. };
  1866. };
  1867. deleteResult( result );
  1868. };
  1869. return RetVal;
  1870. };
  1871. PLGS_2D_PARAMETERS mysqlDBC::getLRFDetectionProfile( uint32_t lrfID, uint8_t profileID, bool master ){
  1872. PLGS_2D_PARAMETERS retVal = NULL;
  1873. if(m_bIsConnected){
  1874. char tQBuf[CTEXT];
  1875. AAssoc *result;
  1876. sprintf(tQBuf, "SELECT * FROM `lrf_detection_profiles` WHERE `aux_id`=%d AND `profile_id`=%d AND `master`=b'%c'", lrfID, profileID,((master)?'1':'0') );
  1877. #ifdef DEBUG
  1878. LOG(tQBuf);
  1879. #endif
  1880. result = m_pDatabase->Query( tQBuf );
  1881. if( result!= NULL ) {
  1882. if( result->size() > 0 ) {
  1883. retVal = (PLGS_2D_PARAMETERS) malloc(sizeof(LGS_2D_PARAMETERS));
  1884. memset( retVal, 0, sizeof(LGS_2D_PARAMETERS));
  1885. Assoc *cArr;
  1886. Assoc::iterator it;
  1887. cArr = result->at(0);
  1888. it = cArr->find("order");
  1889. if( it != cArr->end() ){
  1890. retVal->nOrder = atoi(it->second.c_str());
  1891. };
  1892. it = cArr->find("offset");
  1893. if( it != cArr->end() ){
  1894. retVal->nOffset = atoi(it->second.c_str());
  1895. };
  1896. it = cArr->find("delta");
  1897. if( it != cArr->end() ){
  1898. retVal->nDelta = atoi(it->second.c_str());
  1899. };
  1900. it = cArr->find("flip");
  1901. if( it != cArr->end() ){
  1902. retVal->nFlip = atoi(it->second.c_str());
  1903. };
  1904. it = cArr->find("width");
  1905. if( it != cArr->end() ){
  1906. retVal->nWidth = atoi(it->second.c_str());
  1907. };
  1908. it = cArr->find("sst");
  1909. if( it != cArr->end() ){
  1910. retVal->bSST = atoi(it->second.c_str());
  1911. };
  1912. it = cArr->find("sun");
  1913. if( it != cArr->end() ){
  1914. retVal->nSun = atoi(it->second.c_str());
  1915. };
  1916. };
  1917. };
  1918. deleteResult( result );
  1919. };
  1920. return retVal;
  1921. };
  1922. CSTR mysqlDBC::getLRFDraw( uint32_t DBID ){
  1923. CSTR RetVal = NULL;
  1924. if(m_bIsConnected){
  1925. char tQBuf[CTEXT];
  1926. AAssoc *result;
  1927. sprintf(tQBuf, "SELECT `md5` FROM `lrf_draw` WHERE `node_id`=%d", DBID );
  1928. #ifdef DEBUG
  1929. LOG(tQBuf);
  1930. #endif
  1931. result = m_pDatabase->Query( tQBuf );
  1932. if( result!= NULL ) {
  1933. if( result->size() > 0 ) {
  1934. Assoc *cArr;
  1935. Assoc::iterator it;
  1936. cArr = result->at(0);
  1937. it = cArr->find("md5");
  1938. if( it != cArr->end() ){
  1939. RetVal = strdup( it->second.c_str() );
  1940. };
  1941. };
  1942. };
  1943. deleteResult( result );
  1944. };
  1945. return RetVal;
  1946. };
  1947. uint32_t mysqlDBC::getLRFMaskID( uint32_t deviceID, uint8_t lrfID, uint8_t layer ){
  1948. uint32_t RetVal = 0;
  1949. if(m_bIsConnected){
  1950. char tQBuf[CTEXT];
  1951. AAssoc *result;
  1952. sprintf(tQBuf, "SELECT `id` FROM `lrf_masks` WHERE `sensor_id`=%d AND `lrf_id`=%d AND `layer`=%d ", deviceID, lrfID, layer );
  1953. #ifdef DEBUG
  1954. LOG(tQBuf);
  1955. #endif
  1956. result = m_pDatabase->Query( tQBuf );
  1957. if( result!= NULL ) {
  1958. if( result->size() > 0 ) {
  1959. Assoc *cArr;
  1960. Assoc::iterator it;
  1961. cArr = result->at(0);
  1962. it = cArr->find("id");
  1963. if( it != cArr->end() ){
  1964. RetVal = atoi( it->second.c_str() );
  1965. };
  1966. };
  1967. };
  1968. deleteResult( result );
  1969. };
  1970. return RetVal;
  1971. };
  1972. /*
  1973. DBC_PUSHED_CMD *mysqlDBC::getLRFPushedCMD( uint32_t ID ){
  1974. DBC_PUSHED_CMD *RetVal = NULL;
  1975. if(m_bIsConnected){
  1976. char tQBuf[CTEXT];
  1977. AAssoc *result;
  1978. sprintf(tQBuf, "SELECT `pushed_cmd`, `pushed_param` FROM `lrf_sensors` WHERE `id`=%d AND `pushed_cmd` > 0", ID );
  1979. #ifdef DEBUG
  1980. //LOG(tQBuf);
  1981. #endif
  1982. result = m_pDatabase->Query( tQBuf );
  1983. if( result!= NULL ) {
  1984. if( result->size() > 0 ) {
  1985. RetVal = (DBC_PUSHED_CMD*)malloc(sizeof(DBC_PUSHED_CMD));
  1986. if( RetVal ) {
  1987. Assoc *cArr;
  1988. Assoc::iterator it;
  1989. cArr = result->at(0);
  1990. it = cArr->find("pushed_cmd");
  1991. if( it != cArr->end() ){
  1992. RetVal->CMD = atoi( it->second.c_str() );
  1993. };
  1994. it = cArr->find("pushed_param");
  1995. if( it != cArr->end() ){
  1996. RetVal->PARAM = atoi( it->second.c_str() );
  1997. };
  1998. };
  1999. };
  2000. //Only If Result is Fetched - Clear Current CMD
  2001. sprintf(tQBuf, "UPDATE `lrf_sensors` SET `pushed_cmd`=0, `pushed_param`=0 WHERE `id`=%d", ID );
  2002. m_pDatabase->SilentQuery( tQBuf );
  2003. };
  2004. deleteResult( result );
  2005. };
  2006. return RetVal;
  2007. };
  2008. */
  2009. DBC_INT_LIST *mysqlDBC::listModules(){
  2010. DBC_INT_LIST * tVal = NULL;
  2011. if(m_bIsConnected){
  2012. char tQBuf[CTEXT];
  2013. AAssoc *result;
  2014. sprintf(tQBuf, "SELECT `id` FROM `server_modules` WHERE `server_id`=%d AND `enabled`=1", m_nServerID );
  2015. #ifdef DEBUG_ALL
  2016. LOG(tQBuf);
  2017. #endif
  2018. result = m_pDatabase->Query( tQBuf );
  2019. if( result!= NULL ) {
  2020. if( result->size() > 0 ) {
  2021. Assoc *cArr;
  2022. tVal = new DBC_INT_LIST();
  2023. if( tVal != NULL ) {
  2024. Assoc::iterator it;
  2025. for(int i=0;i<result->size();i++) {
  2026. cArr = result->at(i);
  2027. it = cArr->find("id");
  2028. if( it != cArr->end() ){
  2029. tVal->push_back( atoi( it->second.c_str() ));
  2030. };
  2031. };
  2032. };
  2033. };
  2034. };
  2035. deleteResult( result );
  2036. };
  2037. return tVal;
  2038. };
  2039. DBC_INT_LIST *mysqlDBC::listFilters( uint32_t ServerID ){
  2040. DBC_INT_LIST * tVal = NULL;
  2041. if(m_bIsConnected){
  2042. char tQBuf[CTEXT];
  2043. AAssoc *result;
  2044. sprintf(tQBuf, "SELECT `id` FROM `target_filters` WHERE `server_id`=%d AND `enabled`=1", ServerID );
  2045. #ifdef DEBUG_ALL
  2046. LOG(tQBuf);
  2047. #endif
  2048. result = m_pDatabase->Query( tQBuf );
  2049. if( result!= NULL ) {
  2050. if( result->size() > 0 ) {
  2051. Assoc *cArr;
  2052. tVal = new DBC_INT_LIST();
  2053. if( tVal != NULL ) {
  2054. Assoc::iterator it;
  2055. for(int i=0;i<result->size();i++) {
  2056. cArr = result->at(i);
  2057. it = cArr->find("id");
  2058. if( it != cArr->end() ){
  2059. tVal->push_back( atoi( it->second.c_str() ));
  2060. };
  2061. };
  2062. };
  2063. };
  2064. };
  2065. deleteResult( result );
  2066. };
  2067. return tVal;
  2068. };
  2069. DBC_INT_LIST *mysqlDBC::listLRFMaskVertexes( uint32_t MaskID ){
  2070. DBC_INT_LIST * tVal = NULL;
  2071. if(m_bIsConnected){
  2072. char tQBuf[CTEXT];
  2073. AAssoc *result;
  2074. sprintf(tQBuf, "SELECT `id` FROM `lrf_mask_vertexes` WHERE `mask_id`=%d", MaskID );
  2075. #ifdef DEBUG_ALL
  2076. LOG(tQBuf);
  2077. #endif
  2078. result = m_pDatabase->Query( tQBuf );
  2079. if( result!= NULL ) {
  2080. if( result->size() > 0 ) {
  2081. Assoc *cArr;
  2082. tVal = new DBC_INT_LIST();
  2083. if( tVal != NULL ) {
  2084. Assoc::iterator it;
  2085. for(int i=0;i<result->size();i++) {
  2086. cArr = result->at(i);
  2087. it = cArr->find("id");
  2088. if( it != cArr->end() ){
  2089. tVal->push_back( atoi( it->second.c_str() ));
  2090. };
  2091. };
  2092. };
  2093. };
  2094. };
  2095. deleteResult( result );
  2096. };
  2097. return tVal;
  2098. };
  2099. DBC_INT_LIST *mysqlDBC::listLRFMaskVertexPoints( uint32_t VertexID ){
  2100. DBC_INT_LIST * tVal = NULL;
  2101. if(m_bIsConnected){
  2102. char tQBuf[CTEXT];
  2103. AAssoc *result;
  2104. sprintf(tQBuf, "SELECT `id` FROM `lrf_mask_vertex_points` WHERE `vertex_id`=%d ORDER BY `id`", VertexID );
  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::listMediaServerStreams( uint32_t SiteId, uint32_t MediaServerID, uint8_t listMode ){
  2130. DBC_INT_LIST * tVal = NULL;
  2131. if(m_bIsConnected){
  2132. char tQBuf[CTEXT];
  2133. AAssoc *result;
  2134. switch( listMode ){
  2135. 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;
  2136. 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;
  2137. default: sprintf(tQBuf, "SELECT id FROM media_server_streams WHERE `site_id`=%d AND `media_server_id`=%d", SiteId, MediaServerID );
  2138. };
  2139. #ifdef DEBUG_ALL
  2140. LOG(tQBuf);
  2141. #endif
  2142. result = m_pDatabase->Query( tQBuf );
  2143. if( result!= NULL ) {
  2144. if( result->size() > 0 ) {
  2145. Assoc *cArr;
  2146. tVal = new DBC_INT_LIST();
  2147. if( tVal != NULL ) {
  2148. Assoc::iterator it;
  2149. for(int i=0;i<result->size();i++) {
  2150. cArr = result->at(i);
  2151. it = cArr->find("id");
  2152. if( it != cArr->end() ){
  2153. tVal->push_back( atoi( it->second.c_str() ));
  2154. };
  2155. };
  2156. };
  2157. };
  2158. };
  2159. deleteResult( result );
  2160. };
  2161. return tVal;
  2162. };
  2163. DBC_INT_LIST *mysqlDBC::listMediaStreams( uint32_t SiteId, uint8_t listMode ){
  2164. DBC_INT_LIST * tVal = NULL;
  2165. if(m_bIsConnected){
  2166. char tQBuf[CTEXT];
  2167. AAssoc *result;
  2168. switch( listMode ){
  2169. case LIST_VALID_RECORDS:
  2170. 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 );
  2171. break;
  2172. case LIST_INVALID_RECORDS:
  2173. 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 );
  2174. break;
  2175. default:
  2176. 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 );
  2177. };
  2178. #ifdef DEBUG_ALL
  2179. LOG(tQBuf);
  2180. #endif
  2181. result = m_pDatabase->Query( tQBuf );
  2182. if( result!= NULL ) {
  2183. if( result->size() > 0 ) {
  2184. Assoc *cArr;
  2185. tVal = new DBC_INT_LIST();
  2186. if( tVal != NULL ) {
  2187. Assoc::iterator it;
  2188. for(int i=0;i<result->size();i++) {
  2189. cArr = result->at(i);
  2190. it = cArr->find("id");
  2191. if( it != cArr->end() ){
  2192. tVal->push_back( atoi( it->second.c_str() ));
  2193. };
  2194. };
  2195. };
  2196. };
  2197. };
  2198. deleteResult( result );
  2199. };
  2200. return tVal;
  2201. };
  2202. DBC_INT_LIST *mysqlDBC::listDetectionProfileIDs( uint32_t nodeID ){
  2203. DBC_INT_LIST * tVal = NULL;
  2204. if(m_bIsConnected){
  2205. char tQBuf[CTEXT];
  2206. AAssoc *result;
  2207. sprintf(tQBuf, "SELECT `profile_id` FROM `lrf_detection_profiles` WHERE `aux_id`=%d ", nodeID );
  2208. #ifdef DEBUG_ALL
  2209. LOG(tQBuf);
  2210. #endif
  2211. result = m_pDatabase->Query( tQBuf );
  2212. if( result!= NULL ) {
  2213. if( result->size() > 0 ) {
  2214. Assoc *cArr;
  2215. tVal = new DBC_INT_LIST();
  2216. if( tVal != NULL ) {
  2217. Assoc::iterator it;
  2218. for(int i=0;i<result->size();i++) {
  2219. cArr = result->at(i);
  2220. it = cArr->find("profile_id");
  2221. if( it != cArr->end() ){
  2222. tVal->push_back( atoi( it->second.c_str() ));
  2223. };
  2224. };
  2225. };
  2226. };
  2227. };
  2228. deleteResult( result );
  2229. };
  2230. return tVal;
  2231. };
  2232. DBC_INT_LIST *mysqlDBC::listDetectionProfiles( uint32_t nodeID ){
  2233. DBC_INT_LIST * tVal = NULL;
  2234. if(m_bIsConnected){
  2235. char tQBuf[CTEXT];
  2236. AAssoc *result;
  2237. sprintf(tQBuf, "SELECT `id` FROM `lrf_detection_profiles` WHERE `aux_id`=%d ", nodeID );
  2238. #ifdef DEBUG_ALL
  2239. LOG(tQBuf);
  2240. #endif
  2241. result = m_pDatabase->Query( tQBuf );
  2242. if( result!= NULL ) {
  2243. if( result->size() > 0 ) {
  2244. Assoc *cArr;
  2245. tVal = new DBC_INT_LIST();
  2246. if( tVal != NULL ) {
  2247. Assoc::iterator it;
  2248. for(int i=0;i<result->size();i++) {
  2249. cArr = result->at(i);
  2250. it = cArr->find("id");
  2251. if( it != cArr->end() ){
  2252. tVal->push_back( atoi( it->second.c_str() ));
  2253. };
  2254. };
  2255. };
  2256. };
  2257. };
  2258. deleteResult( result );
  2259. };
  2260. return tVal;
  2261. };
  2262. /*
  2263. DBC_INT_LIST *mysqlDBC::listSockets( uint32_t NodeID ){
  2264. DBC_INT_LIST * tVal = NULL;
  2265. if(m_bIsConnected){
  2266. char tQBuf[CTEXT];
  2267. AAssoc *result;
  2268. sprintf(tQBuf, "SELECT id FROM sockets WHERE `node_id`=%d", NodeID );
  2269. #ifdef DEBUG
  2270. LOG(tQBuf);
  2271. #endif
  2272. result = m_pDatabase->Query( tQBuf );
  2273. if( result!= NULL ) {
  2274. if( result->size() > 0 ) {
  2275. Assoc *cArr;
  2276. tVal = new DBC_INT_LIST();
  2277. if( tVal != NULL ) {
  2278. Assoc::iterator it;
  2279. for(int i=0;i<result->size();i++) {
  2280. cArr = result->at(i);
  2281. it = cArr->find("id");
  2282. if( it != cArr->end() ){
  2283. tVal->push_back( atoi( it->second.c_str() ));
  2284. };
  2285. };
  2286. };
  2287. };
  2288. };
  2289. deleteResult( result );
  2290. };
  2291. return tVal;
  2292. };
  2293. */
  2294. DBC_INT_LIST *mysqlDBC::listResources( uint32_t NodeID ){
  2295. DBC_INT_LIST * tVal = NULL;
  2296. if(m_bIsConnected){
  2297. char tQBuf[CTEXT];
  2298. AAssoc *result;
  2299. if( NodeID ) {
  2300. sprintf(tQBuf, "SELECT `id` FROM `resources` WHERE `node_id`=%d AND `active`=1 AND `used`=1", NodeID );
  2301. } else {
  2302. 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 );
  2303. };
  2304. #ifdef DEBUG
  2305. LOG(tQBuf);
  2306. #endif
  2307. result = m_pDatabase->Query( tQBuf );
  2308. if( result!= NULL ) {
  2309. if( result->size() > 0 ) {
  2310. Assoc *cArr;
  2311. tVal = new DBC_INT_LIST();
  2312. if( tVal != NULL ) {
  2313. Assoc::iterator it;
  2314. for(int i=0;i<result->size();i++) {
  2315. cArr = result->at(i);
  2316. it = cArr->find("id");
  2317. if( it != cArr->end() ){
  2318. tVal->push_back( atoi( it->second.c_str() ));
  2319. };
  2320. };
  2321. };
  2322. };
  2323. };
  2324. deleteResult( result );
  2325. };
  2326. return tVal;
  2327. };
  2328. simplePolygone *mysqlDBC::loadLRFMaskVertex( uint32_t vid ){
  2329. simplePolygone *tVal = NULL;
  2330. if(m_bIsConnected){
  2331. char tQBuf[CTEXT];
  2332. AAssoc *result;
  2333. sprintf(tQBuf, "SELECT * FROM `lrf_mask_vertexes` WHERE `id`=%d", vid );
  2334. #ifdef DEBUG
  2335. LOG(tQBuf);
  2336. #endif
  2337. result = m_pDatabase->Query( tQBuf );
  2338. if( result!= NULL ) {
  2339. if( result->size() > 0 ) {
  2340. tVal = (simplePolygone *) malloc(sizeof(simplePolygone));
  2341. if ( tVal ) {
  2342. Assoc * cArr;
  2343. memset( tVal, 0, sizeof(simplePolygone));
  2344. Assoc::iterator it;
  2345. cArr = result->at(0);
  2346. it = cArr->find("r");
  2347. if( it != cArr->end() ){
  2348. tVal->color[0] = atoi( it->second.c_str() );
  2349. };
  2350. it = cArr->find("g");
  2351. if( it != cArr->end() ){
  2352. tVal->color[1] = atoi( it->second.c_str() );
  2353. };
  2354. it = cArr->find("b");
  2355. if( it != cArr->end() ){
  2356. tVal->color[2] = atoi( it->second.c_str() );
  2357. };
  2358. AAssoc *points;
  2359. sprintf(tQBuf, "SELECT * FROM `lrf_mask_vertex_points` WHERE `vertex_id`=%d ORDER BY `id`", vid );
  2360. #ifdef DEBUG
  2361. LOG(tQBuf);
  2362. #endif
  2363. points = m_pDatabase->Query( tQBuf );
  2364. if( points!= NULL ) {
  2365. if ( points->size() ) {
  2366. tVal->count = points->size();
  2367. tVal->points = (simplePoint *) calloc( points->size(), sizeof(simplePoint) );
  2368. if( tVal->points!= NULL ) {
  2369. for (int i = 0; i < points->size(); i++) {
  2370. cArr = points->at( i );
  2371. it = cArr->find("x");
  2372. if( it != cArr->end() ){
  2373. tVal->points[i].setX( atoi( it->second.c_str() ) );
  2374. };
  2375. it = cArr->find("y");
  2376. if( it != cArr->end() ){
  2377. tVal->points[i].setY( atoi( it->second.c_str() ) );
  2378. };
  2379. };
  2380. };
  2381. };
  2382. };
  2383. deleteResult( points );
  2384. };
  2385. };
  2386. };
  2387. deleteResult( result );
  2388. };
  2389. return tVal;
  2390. };
  2391. DBC_INT_LIST *mysqlDBC::listNetworks( uint32_t nif_id ){
  2392. DBC_INT_LIST * tVal = NULL;
  2393. if(m_bIsConnected){
  2394. char tQBuf[CTEXT];
  2395. AAssoc *result;
  2396. sprintf(tQBuf, "SELECT `id` FROM `networks` WHERE `nif_id`=%d", nif_id );
  2397. #ifdef DEBUG_ALL
  2398. LOG(tQBuf);
  2399. #endif
  2400. result = m_pDatabase->Query( tQBuf );
  2401. if( result!= NULL ) {
  2402. if( result->size() > 0 ) {
  2403. Assoc *cArr;
  2404. tVal = new DBC_INT_LIST();
  2405. if( tVal != NULL ) {
  2406. Assoc::iterator it;
  2407. for(int i=0;i<result->size();i++) {
  2408. cArr = result->at(i);
  2409. it = cArr->find("id");
  2410. if( it != cArr->end() ){
  2411. tVal->push_back( atoi( it->second.c_str() ));
  2412. };
  2413. };
  2414. };
  2415. };
  2416. };
  2417. deleteResult( result );
  2418. };
  2419. return tVal;
  2420. };
  2421. DBC_INT_LIST *mysqlDBC::listNewModules( DBC_INT_LIST * old_ids ){
  2422. DBC_INT_LIST * tVal = NULL;
  2423. char tParam[CTEXT];
  2424. //memset( tParam, 0, CTEXT );
  2425. sprintf(tParam,"0");
  2426. if( old_ids != NULL ) {
  2427. char tBuffer[CTEXT];
  2428. for(int i = 0; i< old_ids->size(); i++ ) {
  2429. sprintf( tBuffer, "%s,%d", tParam, old_ids->at(i) );
  2430. strncpy( tParam, tBuffer, CTEXT );
  2431. };
  2432. };
  2433. if(m_bIsConnected){
  2434. char tQBuf[CTEXT];
  2435. AAssoc *result;
  2436. sprintf(tQBuf, "SELECT `id` FROM `server_modules` WHERE `server_id`=%d AND `enabled`=1 AND `id` NOT IN (%s)", m_nServerID, tParam );
  2437. #ifdef DEBUG_ALL
  2438. LOG(tQBuf);
  2439. #endif
  2440. result = m_pDatabase->Query( tQBuf );
  2441. if( result!= NULL ) {
  2442. if( result->size() > 0 ) {
  2443. Assoc *cArr;
  2444. tVal = new DBC_INT_LIST();
  2445. if( tVal != NULL ) {
  2446. Assoc::iterator it;
  2447. for(int i=0;i<result->size();i++) {
  2448. cArr = result->at(i);
  2449. it = cArr->find("id");
  2450. if( it != cArr->end() ){
  2451. tVal->push_back( atoi( it->second.c_str() ));
  2452. };
  2453. };
  2454. };
  2455. };
  2456. };
  2457. deleteResult( result );
  2458. };
  2459. return tVal;
  2460. };
  2461. uint32_t mysqlDBC::getCamId( CSTR UUID ){
  2462. uint32_t RetVal = 0;
  2463. if(m_bIsConnected){
  2464. char tQBuf[CTEXT];
  2465. AAssoc *result;
  2466. sprintf(tQBuf, "SELECT id FROM cameras WHERE `uuid`='%s'", UUID );
  2467. #ifdef DEBUG_ALL
  2468. LOG(tQBuf);
  2469. #endif
  2470. result = m_pDatabase->Query( tQBuf );
  2471. if( result!= NULL ) {
  2472. if( result->size() > 0 ) {
  2473. Assoc *cArr;
  2474. Assoc::iterator it;
  2475. cArr = result->at(0);
  2476. it = cArr->find("id");
  2477. if( it != cArr->end() ){
  2478. RetVal = atoi( it->second.c_str() );
  2479. };
  2480. };
  2481. };
  2482. deleteResult( result );
  2483. };
  2484. return RetVal;
  2485. };
  2486. DBC_CAP_DATA *mysqlDBC::getCamCapPictureData( uint32_t PicID ){
  2487. DBC_CAP_DATA *tVal = NULL;
  2488. if(m_bIsConnected){
  2489. char tQBuf[CTEXT];
  2490. AAssoc *result;
  2491. sprintf(tQBuf, "SELECT md5, ext FROM pictures WHERE `id`=%d", PicID );
  2492. #ifdef DEBUG_ALL
  2493. LOG(tQBuf);
  2494. #endif
  2495. result = m_pDatabase->Query( tQBuf );
  2496. if( result!= NULL ) {
  2497. if( result->size() > 0 ) {
  2498. Assoc *cArr;
  2499. tVal = (DBC_CAP_DATA*) malloc(sizeof(DBC_CAP_DATA));
  2500. if( tVal != NULL ) {
  2501. memset( tVal, 0 , sizeof(DBC_CAP_DATA));
  2502. Assoc::iterator it;
  2503. cArr = result->at(0);
  2504. it = cArr->find("md5");
  2505. if( it != cArr->end() ){
  2506. strncpy(tVal->md5, it->second.c_str(), 32);
  2507. };
  2508. it = cArr->find("ext");
  2509. if( it != cArr->end() ){
  2510. strncpy(tVal->ext, it->second.c_str(), 3 );
  2511. };
  2512. };
  2513. };
  2514. };
  2515. deleteResult( result );
  2516. };
  2517. return tVal;
  2518. };
  2519. DBC_CAM_DATA *mysqlDBC::getCamData( uint32_t ID ){
  2520. DBC_CAM_DATA *tVal = NULL;
  2521. if(m_bIsConnected){
  2522. char tQBuf[CTEXT];
  2523. AAssoc *result;
  2524. sprintf(tQBuf, "SELECT * FROM cameras WHERE `id`=%d", ID );
  2525. #ifdef DEBUG_ALL
  2526. LOG(tQBuf);
  2527. #endif
  2528. result = m_pDatabase->Query( tQBuf );
  2529. if( result!= NULL ) {
  2530. if( result->size() > 0 ) {
  2531. Assoc *cArr;
  2532. tVal = (DBC_CAM_DATA*) malloc(sizeof(DBC_CAM_DATA));
  2533. if( tVal != NULL ) {
  2534. memset( tVal, 0 , sizeof(DBC_CAM_DATA));
  2535. tVal->id = ID;
  2536. Assoc::iterator it;
  2537. cArr = result->at(0);
  2538. it = cArr->find("type");
  2539. if( it != cArr->end() ){
  2540. tVal->type = atoi( it->second.c_str() );
  2541. };
  2542. it = cArr->find("online");
  2543. if( it != cArr->end() ){
  2544. tVal->online = (bool) atoi( it->second.c_str() );
  2545. };
  2546. it = cArr->find("stream_id");
  2547. if( it != cArr->end() ){
  2548. tVal->stream_id = atoi( it->second.c_str() );
  2549. };
  2550. it = cArr->find("hardware");
  2551. if( it != cArr->end() ){
  2552. strncpy( tVal->hardware, it->second.c_str(), 32 );
  2553. };
  2554. it = cArr->find("name");
  2555. if( it != cArr->end() ){
  2556. strncpy( tVal->name, it->second.c_str(), 64 );
  2557. };
  2558. it = cArr->find("status");
  2559. if( it != cArr->end() ){
  2560. tVal->status = atoi( it->second.c_str() );
  2561. };
  2562. it = cArr->find("session");
  2563. if( it != cArr->end() ){
  2564. strncpy( tVal->session, it->second.c_str(), 32 );
  2565. };
  2566. it = cArr->find("protocol");
  2567. if( it != cArr->end() ){
  2568. tVal->protocol = atoi( it->second.c_str() );
  2569. };
  2570. it = cArr->find("protocol_aux");
  2571. if( it != cArr->end() ){
  2572. tVal->protocol_aux = atoi( it->second.c_str() );
  2573. };
  2574. it = cArr->find("uart_id");
  2575. if( it != cArr->end() ){
  2576. tVal->uart_id = atoi( it->second.c_str() );
  2577. };
  2578. it = cArr->find("x");
  2579. if( it != cArr->end() ){
  2580. tVal->x = atof( it->second.c_str() );
  2581. };
  2582. it = cArr->find("y");
  2583. if( it != cArr->end() ){
  2584. tVal->y = atof( it->second.c_str() );
  2585. };
  2586. it = cArr->find("z");
  2587. if( it != cArr->end() ){
  2588. tVal->z = atof( it->second.c_str() );
  2589. };
  2590. it = cArr->find("x_rot");
  2591. if( it != cArr->end() ){
  2592. tVal->x_rot = atof( it->second.c_str() );
  2593. };
  2594. it = cArr->find("y_rot");
  2595. if( it != cArr->end() ){
  2596. tVal->y_rot = atof( it->second.c_str() );
  2597. };
  2598. it = cArr->find("z_rot");
  2599. if( it != cArr->end() ){
  2600. tVal->z_rot = atof( it->second.c_str() );
  2601. };
  2602. it = cArr->find("imager_type");
  2603. if( it != cArr->end() ){
  2604. tVal->imager_type = atoi( it->second.c_str() );
  2605. };
  2606. it = cArr->find("lens_f");
  2607. if( it != cArr->end() ){
  2608. tVal->lens_f = atoi( it->second.c_str() );
  2609. };
  2610. it = cArr->find("ptz_speed_step");
  2611. if( it != cArr->end() ){
  2612. tVal->ptz_speed_step = atof( it->second.c_str() );
  2613. };
  2614. it = cArr->find("pan_model");
  2615. if( it != cArr->end() ){
  2616. tVal->pan_model = atoi( it->second.c_str() );
  2617. };
  2618. it = cArr->find("pan_angles");
  2619. if( it != cArr->end() ){
  2620. tVal->pan_angles = atoi( it->second.c_str() );
  2621. };
  2622. it = cArr->find("tilt_model");
  2623. if( it != cArr->end() ){
  2624. tVal->tilt_model = atoi( it->second.c_str() );
  2625. };
  2626. it = cArr->find("tilt_angles");
  2627. if( it != cArr->end() ){
  2628. tVal->tilt_angles = atoi( it->second.c_str() );
  2629. };
  2630. it = cArr->find("zoom_model");
  2631. if( it != cArr->end() ){
  2632. tVal->zoom_model = atoi( it->second.c_str() );
  2633. };
  2634. it = cArr->find("zoom");
  2635. if( it != cArr->end() ){
  2636. tVal->zoom = atof( it->second.c_str() );
  2637. };
  2638. //it = cArr->find("max_range");
  2639. //if( it != cArr->end() ){
  2640. // tVal->max_range = atof( it->second.c_str() );
  2641. //};
  2642. it = cArr->find("access_login");
  2643. if( it != cArr->end() ){
  2644. strncpy( tVal->username, it->second.c_str(), 16 );
  2645. };
  2646. it = cArr->find("access_pass");
  2647. if( it != cArr->end() ){
  2648. strncpy( tVal->password, it->second.c_str(), 16 );
  2649. };
  2650. it = cArr->find("uuid");
  2651. if( it != cArr->end() ){
  2652. strncpy( tVal->uuid, it->second.c_str(), 64 );
  2653. };
  2654. it = cArr->find("mac");
  2655. if( it != cArr->end() ){
  2656. strncpy( tVal->mac, it->second.c_str(), 16 );
  2657. };
  2658. it = cArr->find("ip");
  2659. if( it != cArr->end() ){
  2660. strncpy( tVal->ip, it->second.c_str(), 16 );
  2661. };
  2662. it = cArr->find("port");
  2663. if( it != cArr->end() ){
  2664. tVal->port = atoi( it->second.c_str() );
  2665. };
  2666. it = cArr->find("onvif_access");
  2667. if( it != cArr->end() ){
  2668. strncpy( tVal->onvif_access, it->second.c_str(), 5);
  2669. };
  2670. it = cArr->find("onvif_ctrl");
  2671. if( it != cArr->end() ){
  2672. strncpy( tVal->onvif_ctrl, it->second.c_str(), 250);
  2673. };
  2674. it = cArr->find("ptz_token");
  2675. if( it != cArr->end() ){
  2676. strncpy( tVal->ptz_token, it->second.c_str(), 64);
  2677. };
  2678. it = cArr->find("trigger_mode");
  2679. if( it != cArr->end() ){
  2680. tVal->triggering_mode = atoi( it->second.c_str() );
  2681. };
  2682. it = cArr->find("auth_mode");
  2683. if( it != cArr->end() ){
  2684. tVal->auth_mode = atoi( it->second.c_str() );
  2685. };
  2686. };
  2687. };
  2688. };
  2689. deleteResult( result );
  2690. };
  2691. return tVal;
  2692. };
  2693. DBC_PUSHED_CMD *mysqlDBC::getActivePushedCMD( uint32_t NodeID ){
  2694. DBC_PUSHED_CMD *RetVal = NULL;
  2695. if(m_bIsConnected){
  2696. char tQBuf[CTEXT];
  2697. AAssoc *result;
  2698. sprintf(tQBuf, "SELECT * FROM `nodes_qcq` WHERE `node_id`=%d AND `status` > 0 AND `status` < 100", NodeID );
  2699. #ifdef DEBUG_ALL
  2700. LOG(tQBuf);
  2701. #endif
  2702. result = m_pDatabase->Query( tQBuf );
  2703. if( result!= NULL ) {
  2704. if( result->size() > 0 ) {
  2705. RetVal = (DBC_PUSHED_CMD*)malloc(sizeof(DBC_PUSHED_CMD));
  2706. if( RetVal ) {
  2707. Assoc * cArr;
  2708. Assoc::iterator it;
  2709. memset( RetVal, 0, sizeof(DBC_PUSHED_CMD));
  2710. cArr = result->at(0);
  2711. it = cArr->find("id");
  2712. if( it != cArr->end() ){
  2713. RetVal->id = atoi( it->second.c_str() );
  2714. };
  2715. it = cArr->find("cmd");
  2716. if( it != cArr->end() ){
  2717. RetVal->CMD = atoi( it->second.c_str() );
  2718. };
  2719. it = cArr->find("parameter");
  2720. if( it != cArr->end() ){
  2721. strncpy( RetVal->PARAM, it->second.c_str(), 256 );
  2722. RetVal->PARAM[255] = (char)0;
  2723. };
  2724. };
  2725. };
  2726. };
  2727. deleteResult( result );
  2728. };
  2729. return RetVal;
  2730. };
  2731. DBC_PUSHED_CMD *mysqlDBC::getPushedCMD( uint32_t CmdID ){
  2732. DBC_PUSHED_CMD *RetVal = NULL;
  2733. if(m_bIsConnected){
  2734. char tQBuf[CTEXT];
  2735. AAssoc *result;
  2736. sprintf(tQBuf, "SELECT * FROM `nodes_qcq` WHERE `id`=%d", CmdID );
  2737. #ifdef DEBUG_ALL
  2738. LOG(tQBuf);
  2739. #endif
  2740. result = m_pDatabase->Query( tQBuf );
  2741. if( result!= NULL ) {
  2742. if( result->size() > 0 ) {
  2743. RetVal = (DBC_PUSHED_CMD*)malloc(sizeof(DBC_PUSHED_CMD));
  2744. if( RetVal ) {
  2745. Assoc * cArr;
  2746. Assoc::iterator it;
  2747. memset( RetVal, 0, sizeof(DBC_PUSHED_CMD));
  2748. cArr = result->at(0);
  2749. it = cArr->find("id");
  2750. if( it != cArr->end() ){
  2751. RetVal->id = atoi( it->second.c_str() );
  2752. };
  2753. it = cArr->find("cmd");
  2754. if( it != cArr->end() ){
  2755. RetVal->CMD = atoi( it->second.c_str() );
  2756. };
  2757. it = cArr->find("parameter");
  2758. if( it != cArr->end() ){
  2759. strncpy( RetVal->PARAM, it->second.c_str(), 256 );
  2760. RetVal->PARAM[255] = (char)0;
  2761. };
  2762. };
  2763. };
  2764. };
  2765. deleteResult( result );
  2766. };
  2767. return RetVal;
  2768. };
  2769. DBC_PUSHED_CMD *mysqlDBC::getNodePushedCMD( uint32_t NodeID ){
  2770. DBC_PUSHED_CMD *RetVal = NULL;
  2771. if(m_bIsConnected){
  2772. char tQBuf[CTEXT];
  2773. AAssoc *result;
  2774. sprintf(tQBuf, "SELECT * FROM `nodes_qcq` WHERE `node_id`=%d AND `status`=0 LIMIT 1", NodeID );
  2775. #ifdef DEBUG_ALL
  2776. LOG(tQBuf);
  2777. #endif
  2778. result = m_pDatabase->Query( tQBuf );
  2779. if( result!= NULL ) {
  2780. if( result->size() > 0 ) {
  2781. RetVal = (DBC_PUSHED_CMD*)malloc(sizeof(DBC_PUSHED_CMD));
  2782. if( RetVal ) {
  2783. Assoc * cArr;
  2784. Assoc::iterator it;
  2785. memset( RetVal, 0, sizeof(DBC_PUSHED_CMD));
  2786. cArr = result->at(0);
  2787. it = cArr->find("id");
  2788. if( it != cArr->end() ){
  2789. RetVal->id = atoi( it->second.c_str() );
  2790. };
  2791. it = cArr->find("cmd");
  2792. if( it != cArr->end() ){
  2793. RetVal->CMD = atoi( it->second.c_str() );
  2794. };
  2795. it = cArr->find("parameter");
  2796. if( it != cArr->end() ){
  2797. strncpy( RetVal->PARAM, it->second.c_str(), 256 );
  2798. RetVal->PARAM[255] = (char)0;
  2799. };
  2800. //Only If Result is Fetched - Clear Current CMD
  2801. //sprintf(tQBuf, "DELETE FROM `nodes_qcq` WHERE `id`=%d", RetVal->id );
  2802. //m_pDatabase->SilentQuery( tQBuf );
  2803. };
  2804. };
  2805. };
  2806. deleteResult( result );
  2807. };
  2808. return RetVal;
  2809. };
  2810. bool mysqlDBC::updateNodePushedCMD( uint32_t CmdID, uint8_t status ){
  2811. if(m_bIsConnected){
  2812. char tQBuf[CTEXT];
  2813. sprintf(tQBuf, "UPDATE `nodes_qcq` SET `status`=%d WHERE `id`=%d ", status, CmdID );
  2814. #ifdef DEBUG_ALL
  2815. LOG(tQBuf);
  2816. #endif
  2817. m_pDatabase->SilentQuery( tQBuf );
  2818. return true;
  2819. };
  2820. return false;
  2821. };
  2822. DBC_MODULE_DATA *mysqlDBC::getModuleData( uint32_t ID ){
  2823. DBC_MODULE_DATA *tVal = NULL;
  2824. if(m_bIsConnected){
  2825. char tQBuf[CTEXT];
  2826. AAssoc *result;
  2827. sprintf(tQBuf, "SELECT * FROM server_modules WHERE `id`=%d", ID );
  2828. #ifdef DEBUG_ALL
  2829. LOG(tQBuf);
  2830. #endif
  2831. result = m_pDatabase->Query( tQBuf );
  2832. if( result!= NULL ) {
  2833. if( result->size() > 0 ) {
  2834. Assoc *cArr;
  2835. tVal = (DBC_MODULE_DATA*) malloc(sizeof(DBC_MODULE_DATA));
  2836. if( tVal != NULL ) {
  2837. Assoc::iterator it;
  2838. cArr = result->at(0);
  2839. it = cArr->find("id");
  2840. if( it != cArr->end() ){
  2841. tVal->module_id = atoi( it->second.c_str() );
  2842. };
  2843. it = cArr->find("aux_id");
  2844. if( it != cArr->end() ){
  2845. tVal->aux_id = atoi( it->second.c_str() );
  2846. };
  2847. it = cArr->find("type");
  2848. if( it != cArr->end() ){
  2849. tVal->type = atoi( it->second.c_str() );
  2850. };
  2851. it = cArr->find("enabled");
  2852. if( it != cArr->end() ){
  2853. tVal->enabled = (bool)atoi( it->second.c_str() );
  2854. };
  2855. };
  2856. };
  2857. };
  2858. deleteResult( result );
  2859. };
  2860. return tVal;
  2861. };
  2862. /*
  2863. DBC_SOCKET_DATA *mysqlDBC::getSocketData( uint32_t ID ){
  2864. DBC_SOCKET_DATA *tVal = NULL;
  2865. if(m_bIsConnected){
  2866. char tQBuf[CTEXT];
  2867. AAssoc *result;
  2868. sprintf(tQBuf, "SELECT * FROM sockets WHERE `id`=%d", ID );
  2869. #ifdef DEBUG
  2870. //LOG(tQBuf);
  2871. #endif
  2872. result = m_pDatabase->Query( tQBuf );
  2873. if( result!= NULL ) {
  2874. if( result->size() > 0 ) {
  2875. Assoc *cArr;
  2876. tVal = (DBC_SOCKET_DATA*) malloc(sizeof(DBC_SOCKET_DATA));
  2877. if( tVal != NULL ) {
  2878. Assoc::iterator it;
  2879. cArr = result->at(0);
  2880. it = cArr->find("id");
  2881. if( it != cArr->end() ){
  2882. tVal->socket_id = atoi( it->second.c_str() );
  2883. };
  2884. it = cArr->find("aux_id");
  2885. if( it != cArr->end() ){
  2886. tVal->aux_id = atoi( it->second.c_str() );
  2887. };
  2888. it = cArr->find("type");
  2889. if( it != cArr->end() ){
  2890. tVal->type = atoi( it->second.c_str() );
  2891. };
  2892. it = cArr->find("binded");
  2893. if( it != cArr->end() ){
  2894. tVal->binded = (bool)atoi( it->second.c_str() );
  2895. };
  2896. };
  2897. };
  2898. };
  2899. deleteResult( result );
  2900. };
  2901. return tVal;
  2902. };
  2903. */
  2904. DBC_MEDIA_STREAM_DATA *mysqlDBC::getMediaStreamData( uint32_t ID ){
  2905. DBC_MEDIA_STREAM_DATA *tVal = NULL;
  2906. if(m_bIsConnected){
  2907. char tQBuf[CTEXT];
  2908. AAssoc *result;
  2909. sprintf(tQBuf, "SELECT * FROM media_streams WHERE `id`=%d", ID );
  2910. #ifdef DEBUG_ALL
  2911. LOG(tQBuf);
  2912. #endif
  2913. result = m_pDatabase->Query( tQBuf );
  2914. if( result!= NULL ) {
  2915. if( result->size() > 0 ) {
  2916. Assoc *cArr;
  2917. tVal = (DBC_MEDIA_STREAM_DATA*) malloc(sizeof(DBC_MEDIA_STREAM_DATA));
  2918. if( tVal != NULL ) {
  2919. memset( tVal, 0, sizeof(DBC_MEDIA_STREAM_DATA) );
  2920. Assoc::iterator it;
  2921. cArr = result->at(0);
  2922. tVal->id = ID;
  2923. it = cArr->find("source_id");
  2924. if( it != cArr->end() ){
  2925. tVal->source_id = atoi( it->second.c_str() );
  2926. };
  2927. it = cArr->find("source_type");
  2928. if( it != cArr->end() ){
  2929. sprintf( tVal->source_type, it->second.c_str() );
  2930. };
  2931. it = cArr->find("valid");
  2932. if( it != cArr->end() ){
  2933. tVal->valid = (bool) atoi( it->second.c_str() );
  2934. };
  2935. it = cArr->find("token");
  2936. if( it != cArr->end() ){
  2937. sprintf( tVal->token, it->second.c_str() );
  2938. };
  2939. it = cArr->find("img_width");
  2940. if( it != cArr->end() ){
  2941. tVal->width = atoi( it->second.c_str() );
  2942. };
  2943. it = cArr->find("img_height");
  2944. if( it != cArr->end() ){
  2945. tVal->height = atoi( it->second.c_str() );
  2946. };
  2947. it = cArr->find("fps");
  2948. if( it != cArr->end() ){
  2949. tVal->fps = atoi( it->second.c_str() );
  2950. };
  2951. it = cArr->find("compression_type");
  2952. if( it != cArr->end() ){
  2953. sprintf(tVal->c_type, it->second.c_str());
  2954. };
  2955. it = cArr->find("mrl_proto");
  2956. if( it != cArr->end() ){
  2957. sprintf( tVal->mrl_proto, it->second.c_str() );
  2958. };
  2959. it = cArr->find("mrl_port");
  2960. if( it != cArr->end() ){
  2961. tVal->mrl_port = atoi( it->second.c_str() );
  2962. };
  2963. it = cArr->find("mrl");
  2964. if( it != cArr->end() ){
  2965. sprintf( tVal->mrl, it->second.c_str() );
  2966. };
  2967. };
  2968. };
  2969. };
  2970. deleteResult( result );
  2971. };
  2972. return tVal;
  2973. };
  2974. DBC_MEDIA_SERVER_DATA *mysqlDBC::getMediaServerData( uint32_t ID ){
  2975. DBC_MEDIA_SERVER_DATA *tVal = NULL;
  2976. if(m_bIsConnected){
  2977. char tQBuf[CTEXT];
  2978. AAssoc *result;
  2979. sprintf(tQBuf, "SELECT * FROM media_servers WHERE `id`=%d", ID );
  2980. #ifdef DEBUG_ALL
  2981. LOG(tQBuf);
  2982. #endif
  2983. result = m_pDatabase->Query( tQBuf );
  2984. if( result!= NULL ) {
  2985. if( result->size() > 0 ) {
  2986. Assoc *cArr;
  2987. tVal = (DBC_MEDIA_SERVER_DATA*) malloc(sizeof(DBC_MEDIA_SERVER_DATA));
  2988. if( tVal != NULL ) {
  2989. Assoc::iterator it;
  2990. cArr = result->at(0);
  2991. tVal->id = ID;
  2992. it = cArr->find("secret_key");
  2993. if( it != cArr->end() ){
  2994. sprintf( tVal->key, it->second.c_str() );
  2995. };
  2996. it = cArr->find("ip");
  2997. if( it != cArr->end() ){
  2998. sprintf( tVal->ip, it->second.c_str() );
  2999. };
  3000. it = cArr->find("REST_port");
  3001. if( it != cArr->end() ){
  3002. tVal->port = atoi( it->second.c_str() );
  3003. };
  3004. it = cArr->find("virtual_host");
  3005. if( it != cArr->end() ){
  3006. sprintf( tVal->host, it->second.c_str() );
  3007. };
  3008. it = cArr->find("recording");
  3009. if( it != cArr->end() ){
  3010. tVal->recording = (bool)atoi( it->second.c_str() );
  3011. };
  3012. it = cArr->find("local");
  3013. if( it != cArr->end() ){
  3014. tVal->local = (bool)atoi( it->second.c_str() );
  3015. };
  3016. it = cArr->find("docRoot");
  3017. if( it != cArr->end() ){
  3018. sprintf( tVal->docRoot, it->second.c_str() );
  3019. };
  3020. sprintf( tVal->name,"ZLMedia_%d", tVal->id );
  3021. };
  3022. };
  3023. };
  3024. deleteResult( result );
  3025. };
  3026. return tVal;
  3027. };
  3028. DBC_MEDIA_SERVER_STREAM_DATA *mysqlDBC::getMediaServerStreamDataBySource( uint32_t ID ){
  3029. DBC_MEDIA_SERVER_STREAM_DATA *tVal = NULL;
  3030. if(m_bIsConnected){
  3031. char tQBuf[MAX_PATH_LEN];
  3032. AAssoc *result;
  3033. sprintf(tQBuf, "SELECT `id`, `media_stream_id`, `online`, `key`, `mrl` FROM media_server_streams WHERE `media_stream_id`=%d", ID );
  3034. #ifdef DEBUG_ALL
  3035. LOG(tQBuf);
  3036. #endif
  3037. result = m_pDatabase->Query( tQBuf );
  3038. if( result!= NULL ) {
  3039. if( result->size() > 0 ) {
  3040. Assoc *cArr;
  3041. tVal = (DBC_MEDIA_SERVER_STREAM_DATA*) malloc(sizeof(DBC_MEDIA_SERVER_STREAM_DATA));
  3042. if( tVal != NULL ) {
  3043. Assoc::iterator it;
  3044. cArr = result->at(0);
  3045. tVal->id = ID;
  3046. it = cArr->find("media_stream_id");
  3047. if( it != cArr->end() ){
  3048. tVal->media_stream_id = atoi( it->second.c_str() );
  3049. };
  3050. it = cArr->find("online");
  3051. if( it != cArr->end() ){
  3052. tVal->online = atoi( it->second.c_str() );
  3053. };
  3054. it = cArr->find("key");
  3055. if( it != cArr->end() ){
  3056. sprintf( tVal->key, it->second.c_str() );
  3057. };
  3058. it = cArr->find("mrl");
  3059. if( it != cArr->end() ){
  3060. sprintf( tVal->mrl, it->second.c_str() );
  3061. };
  3062. };
  3063. };
  3064. };
  3065. deleteResult( result );
  3066. };
  3067. return tVal;
  3068. };
  3069. DBC_MEDIA_SERVER_STREAM_DATA *mysqlDBC::getMediaServerStreamData( uint32_t ID ){
  3070. DBC_MEDIA_SERVER_STREAM_DATA *tVal = NULL;
  3071. if(m_bIsConnected){
  3072. char tQBuf[MAX_PATH_LEN];
  3073. AAssoc *result;
  3074. sprintf(tQBuf, "SELECT `id`, `media_stream_id`, `online`, `key`, `mrl` FROM media_server_streams WHERE `id`=%d", ID );
  3075. #ifdef DEBUG_ALL
  3076. LOG(tQBuf);
  3077. #endif
  3078. result = m_pDatabase->Query( tQBuf );
  3079. if( result!= NULL ) {
  3080. if( result->size() > 0 ) {
  3081. Assoc *cArr;
  3082. tVal = (DBC_MEDIA_SERVER_STREAM_DATA*) malloc(sizeof(DBC_MEDIA_SERVER_STREAM_DATA));
  3083. if( tVal != NULL ) {
  3084. Assoc::iterator it;
  3085. cArr = result->at(0);
  3086. tVal->id = ID;
  3087. it = cArr->find("media_stream_id");
  3088. if( it != cArr->end() ){
  3089. tVal->media_stream_id = atoi( it->second.c_str() );
  3090. };
  3091. it = cArr->find("online");
  3092. if( it != cArr->end() ){
  3093. tVal->online = atoi( it->second.c_str() );
  3094. };
  3095. it = cArr->find("key");
  3096. if( it != cArr->end() ){
  3097. sprintf( tVal->key, it->second.c_str() );
  3098. };
  3099. it = cArr->find("mrl");
  3100. if( it != cArr->end() ){
  3101. sprintf( tVal->mrl, it->second.c_str() );
  3102. };
  3103. };
  3104. };
  3105. };
  3106. deleteResult( result );
  3107. };
  3108. return tVal;
  3109. };
  3110. void mysqlDBC::registerServer( uint32_t SiteID, CSTR identity, int PID, uint32_t *ServID, uint32_t *ServNode ){
  3111. if(m_bIsConnected){
  3112. m_nSiteID = SiteID;
  3113. char tQBuf[MAX_PATH_LEN];
  3114. 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",
  3115. SiteID, identity, _BUILD_STRING_, PID, _BUILD_STRING_, PID );
  3116. #ifdef DEBUG
  3117. LOG(tQBuf);
  3118. #endif
  3119. m_pDatabase->SilentQuery( tQBuf );
  3120. *ServID = getServerID( identity );
  3121. m_nServerID = *ServID;
  3122. if( *ServID ) {
  3123. 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 );
  3124. #ifdef DEBUG_ALL
  3125. LOG(tQBuf);
  3126. #endif
  3127. *ServNode = ( uint32_t ) m_pDatabase->QueryID( tQBuf );
  3128. if( *ServNode == 0 ){
  3129. *ServNode = getServerNode( *ServID );
  3130. };
  3131. m_nServerNodeID = *ServNode;
  3132. // Clenup Nodes and services ...
  3133. sprintf(tQBuf,"UPDATE nodes SET `online`=0 WHERE `server_id`=%d ", *ServID );
  3134. #ifdef DEBUG_ALL
  3135. LOG(tQBuf);
  3136. #endif
  3137. m_pDatabase->SilentQuery( tQBuf );
  3138. sprintf(tQBuf,"UPDATE cameras SET `online`=0 WHERE `site_id`=%d ", SiteID );
  3139. #ifdef DEBUG_ALL
  3140. LOG(tQBuf);
  3141. #endif
  3142. m_pDatabase->SilentQuery( tQBuf );
  3143. sprintf(tQBuf,"UPDATE media_streams SET `valid`=0 WHERE `site_id`=%d ", SiteID );
  3144. #ifdef DEBUG_ALL
  3145. LOG(tQBuf);
  3146. #endif
  3147. m_pDatabase->SilentQuery( tQBuf );
  3148. sprintf(tQBuf,"UPDATE media_server_streams SET `valid`=0, `online`=0 WHERE `site_id`=%d ", SiteID );
  3149. #ifdef DEBUG_ALL
  3150. LOG(tQBuf);
  3151. #endif
  3152. m_pDatabase->SilentQuery( tQBuf );
  3153. //cleanResources( tServerNodeID );
  3154. setNodeOnline( m_nServerNodeID );
  3155. }
  3156. };
  3157. };
  3158. void mysqlDBC::unregisterServer(){
  3159. if( setNodeOffline( m_nServerNodeID ) ){
  3160. char tQBuf[CTEXT];
  3161. sprintf(tQBuf,"UPDATE servers SET `online`=0, `ts`=UNIX_TIMESTAMP(now()) WHERE `id`=%d", m_nServerID );
  3162. #ifdef DEBUG_ALL
  3163. LOG(tQBuf);
  3164. #endif
  3165. m_pDatabase->SilentQuery( tQBuf );
  3166. };
  3167. };
  3168. bool mysqlDBC::setNodeOnline( uint32_t NodeID, uint8_t status ){
  3169. if(m_bIsConnected){
  3170. char tQBuf[CTEXT];
  3171. if( NodeID ) {
  3172. sprintf(tQBuf,"UPDATE nodes SET `online`=%d WHERE `id`=%d", status, NodeID );
  3173. #ifdef DEBUG_ALL
  3174. LOG(tQBuf);
  3175. #endif
  3176. m_pDatabase->SilentQuery( tQBuf );
  3177. sprintf(tQBuf,"UPDATE `resources` SET `active`=1 WHERE `node_id`=%d", NodeID );
  3178. #ifdef DEBUG_ALL
  3179. LOG(tQBuf);
  3180. #endif
  3181. m_pDatabase->SilentQuery( tQBuf );
  3182. return true;
  3183. };
  3184. };
  3185. return false;
  3186. };
  3187. bool mysqlDBC::setNodeOffline( uint32_t NodeID ){
  3188. if(m_bIsConnected){
  3189. char tQBuf[CTEXT];
  3190. if( NodeID ) {
  3191. sprintf(tQBuf,"UPDATE nodes SET `online`=0 WHERE `id` = %d", NodeID );
  3192. #ifdef DEBUG_ALL
  3193. LOG(tQBuf);
  3194. #endif
  3195. m_pDatabase->SilentQuery( tQBuf );
  3196. sprintf(tQBuf,"UPDATE `resources` SET `active`=0 WHERE `node_id` = %d", NodeID );
  3197. #ifdef DEBUG_ALL
  3198. LOG(tQBuf);
  3199. #endif
  3200. m_pDatabase->SilentQuery( tQBuf );
  3201. return true;
  3202. };
  3203. };
  3204. return false;
  3205. };
  3206. DBC_RESOURCE_DATA *mysqlDBC::getResourceData( uint32_t ResourceID ){
  3207. DBC_RESOURCE_DATA *tVal = NULL;
  3208. if( m_bIsConnected ){
  3209. char tQBuf[CTEXT];
  3210. AAssoc *result;
  3211. sprintf(tQBuf, "SELECT `node_id`, `type`, `aux_id`, `device` FROM resources WHERE `id`=%d", ResourceID );
  3212. #ifdef DEBUG_ALL
  3213. LOG(tQBuf);
  3214. #endif
  3215. result = m_pDatabase->Query( tQBuf );
  3216. if( result!= NULL ) {
  3217. if( result->size() > 0 ) {
  3218. Assoc *cArr;
  3219. tVal = (DBC_RESOURCE_DATA*) malloc(sizeof(DBC_RESOURCE_DATA));
  3220. if( tVal != NULL ) {
  3221. Assoc::iterator it;
  3222. cArr = result->at(0);
  3223. tVal->id = ResourceID;
  3224. it = cArr->find("node_id");
  3225. if( it != cArr->end() ){
  3226. tVal->node_id = atoi( it->second.c_str() );
  3227. };
  3228. it = cArr->find("type");
  3229. if( it != cArr->end() ){
  3230. tVal->type = atoi( it->second.c_str() );
  3231. };
  3232. it = cArr->find("aux_id");
  3233. if( it != cArr->end() ){
  3234. tVal->aux_id = atoi( it->second.c_str() );
  3235. };
  3236. it = cArr->find("device");
  3237. if( it != cArr->end() ){
  3238. strncpy( tVal->device, it->second.c_str(), 64 );
  3239. tVal->device[63] = (char)0;
  3240. };
  3241. };
  3242. };
  3243. };
  3244. deleteResult( result );
  3245. };
  3246. return tVal;
  3247. };
  3248. uint32_t mysqlDBC::getResourceID( uint32_t NodeID, uint8_t type, uint32_t auxID ){
  3249. uint32_t RetVal = 0;
  3250. if(m_bIsConnected){
  3251. char tQBuf[CTEXT];
  3252. sprintf(tQBuf,"SELECT `id` FROM `resources` WHERE `node_id`=%d AND `type`=%d AND `aux_id`=%d", NodeID, type, auxID );
  3253. #ifdef DEBUG_ALL
  3254. LOG(tQBuf);
  3255. #endif
  3256. AAssoc *result;
  3257. result = m_pDatabase->Query( tQBuf );
  3258. if( result!= NULL ) {
  3259. if( result->size() > 0 ) {
  3260. Assoc * cArr;
  3261. Assoc::iterator it;
  3262. cArr = result->at(0);
  3263. it = cArr->find("id");
  3264. if( it != cArr->end() ){
  3265. RetVal = atoi( it->second.c_str() );
  3266. };
  3267. };
  3268. };
  3269. deleteResult( result );
  3270. };
  3271. return RetVal;
  3272. };
  3273. uint32_t mysqlDBC::getServerID( CSTR identity ){
  3274. uint32_t RetVal = 0;
  3275. if(m_bIsConnected){
  3276. char tQBuf[CTEXT];
  3277. sprintf(tQBuf,"SELECT id FROM servers WHERE `identity`='%s'", identity );
  3278. #ifdef DEBUG_ALL
  3279. LOG(tQBuf);
  3280. #endif
  3281. AAssoc *result;
  3282. result = m_pDatabase->Query( tQBuf );
  3283. if( result!= NULL ) {
  3284. if( result->size() > 0 ) {
  3285. Assoc * cArr;
  3286. Assoc::iterator it;
  3287. cArr = result->at(0);
  3288. it = cArr->find("id");
  3289. if( it != cArr->end() ){
  3290. RetVal = atoi( it->second.c_str() );
  3291. };
  3292. };
  3293. };
  3294. deleteResult( result );
  3295. };
  3296. return RetVal;
  3297. };
  3298. uint32_t mysqlDBC::getServerNode( uint32_t SID ){
  3299. uint32_t RetVal = 0;
  3300. if(m_bIsConnected){
  3301. char tQBuf[CTEXT];
  3302. sprintf(tQBuf,"SELECT id FROM nodes WHERE `type`=0 AND `aux_id`=%d", SID );
  3303. #ifdef DEBUG_ALL
  3304. LOG(tQBuf);
  3305. #endif
  3306. AAssoc *result;
  3307. result = m_pDatabase->Query( tQBuf );
  3308. if( result!= NULL ) {
  3309. if( result->size() > 0 ) {
  3310. Assoc * cArr;
  3311. Assoc::iterator it;
  3312. cArr = result->at(0);
  3313. it = cArr->find("id");
  3314. if( it != cArr->end() ){
  3315. RetVal = atoi( it->second.c_str() );
  3316. };
  3317. };
  3318. };
  3319. deleteResult( result );
  3320. };
  3321. return RetVal;
  3322. };
  3323. uint32_t mysqlDBC::addLocalMediaSource( uint32_t SiteID, CSTR path, uint32_t width, uint32_t height ){
  3324. uint32_t RetVal = 0;
  3325. if(m_bIsConnected){
  3326. char tQBuf[1024];
  3327. char tM5[33];
  3328. CSTR tMD5 = MD5String( path );
  3329. if( tMD5 != NULL ) {
  3330. memcpy( tM5, tMD5, 33 );
  3331. tM5[32]=(char)0;
  3332. free( tMD5 );
  3333. 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",
  3334. SiteID, tM5, width, height, path );//, width, height );
  3335. #ifdef DEBUG_ALL
  3336. LOG(tQBuf);
  3337. #endif
  3338. RetVal = (uint32_t) m_pDatabase->QueryID( tQBuf );
  3339. };
  3340. };
  3341. return RetVal;
  3342. };
  3343. /*
  3344. uint32_t mysqlDBC::addNodeSocket( uint32_t NodeID, uint32_t auxID, uint8_t SocketType, uint8_t SocketMode, bool multidrop, CSTR path, CSTR name ){
  3345. uint32_t retVal = 0;
  3346. if(m_bIsConnected){
  3347. char tQBuf[2048];
  3348. char tM5[33];
  3349. CSTR tMD5 = MD5String( path );
  3350. if( tMD5 != NULL ) {
  3351. memcpy( tM5, tMD5, 33 );
  3352. free( tMD5 );
  3353. if( multidrop ) {
  3354. 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'",
  3355. NodeID, SocketType, SocketMode, tM5, path, name, auxID, name );
  3356. } else {
  3357. 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'",
  3358. NodeID, SocketType, SocketMode, tM5, path, name, auxID, name );
  3359. };
  3360. #ifdef DEBUG
  3361. LOG(tQBuf);
  3362. #endif
  3363. //m_pDatabase->SilentQuery( tQBuf );
  3364. retVal = (uint32_t) m_pDatabase->QueryID( tQBuf );
  3365. };
  3366. };
  3367. return retVal;
  3368. };
  3369. */
  3370. bool mysqlDBC::addNotification( uint32_t MSG_ID, uint8_t DIS_LVL, uint32_t OBJ_ID ){
  3371. if(m_bIsConnected){
  3372. char tQBuf[2048];
  3373. 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 );
  3374. #ifdef DEBUG_ALL
  3375. LOG(tQBuf);
  3376. #endif
  3377. m_pDatabase->SilentQuery( tQBuf );
  3378. return true;
  3379. };
  3380. return false;
  3381. };
  3382. uint32_t mysqlDBC::addResource( /*uint32_t NodeID,*/ uint8_t type, CSTR devName, uint32_t auxID ){
  3383. uint32_t RetVal = 0;
  3384. if( m_bIsConnected ){
  3385. char tQBuf[2048];
  3386. sprintf( tQBuf, "%d:%d:%s", m_nServerNodeID, type, devName );
  3387. CSTR tMD5 = MD5String( tQBuf );
  3388. if( tMD5 ) {
  3389. 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 );
  3390. //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 );
  3391. free( tMD5 );
  3392. #ifdef DEBUG_ALL
  3393. LOG(tQBuf);
  3394. #endif
  3395. RetVal = (uint32_t) m_pDatabase->QueryID( tQBuf );
  3396. if( RetVal == 0 ) {
  3397. RetVal = getResourceID( m_nServerNodeID, type, auxID );
  3398. };
  3399. };
  3400. };
  3401. return RetVal;
  3402. };
  3403. /*
  3404. uint32_t mysqlDBC::getNodeSocketID( uint32_t NodeID, uint32_t auxID, uint8_t SocketType, CSTR path ){
  3405. uint32_t retVal = 0;
  3406. if(m_bIsConnected){
  3407. char tQBuf[2048];
  3408. char tM5[33];
  3409. CSTR tMD5 = MD5String( path );
  3410. if( tMD5 != NULL ) {
  3411. memcpy( tM5, tMD5, 33 );
  3412. free( tMD5 );
  3413. sprintf( tQBuf,"SELECT id FROM `sockets` WHERE `node_id`=%d AND `type`=%d AND `md5`='%s' AND `aux_id`=%d", NodeID, SocketType, tM5, auxID );
  3414. #ifdef DEBUG
  3415. LOG(tQBuf);
  3416. #endif
  3417. AAssoc *result;
  3418. result = m_pDatabase->Query( tQBuf );
  3419. if( result!= NULL ) {
  3420. if( result->size() > 0 ) {
  3421. Assoc * cArr;
  3422. Assoc::iterator it;
  3423. cArr = result->at(0);
  3424. it = cArr->find("id");
  3425. if( it != cArr->end() ){
  3426. retVal = atoi( it->second.c_str() );
  3427. };
  3428. };
  3429. };
  3430. deleteResult( result );
  3431. };
  3432. };
  3433. return retVal;
  3434. };
  3435. */
  3436. /*
  3437. CSTR mysqlDBC::getSocketName( uint32_t NodeID, uint32_t Type ){
  3438. if(m_bIsConnected){
  3439. char tQBuf[CTEXT];
  3440. sprintf( tQBuf, "SELECT `name` FROM `sockets` WHERE `node_id`=%d AND `type`=%d LIMIT 1",
  3441. NodeID, Type );
  3442. #ifdef DEBUG
  3443. LOG(tQBuf);
  3444. #endif
  3445. AAssoc *result;
  3446. result = m_pDatabase->Query( tQBuf );
  3447. if( result!= NULL ) {
  3448. if( result->size() > 0 ) {
  3449. Assoc * cArr;
  3450. Assoc::iterator it;
  3451. cArr = result->at(0);
  3452. it = cArr->find("name");
  3453. if( it != cArr->end() ){
  3454. strncpy( tQBuf, it->second.c_str(), CTEXT );
  3455. };
  3456. };
  3457. };
  3458. deleteResult( result );
  3459. return strdup(tQBuf);
  3460. };
  3461. return NULL;
  3462. };
  3463. */
  3464. KAFKA_SETTINGS *mysqlDBC::getSettingsKAFKA( uint32_t ModuleID ){
  3465. KAFKA_SETTINGS *tVal = NULL;
  3466. if( m_bIsConnected ) {
  3467. char tQBuf[CTEXT];
  3468. AAssoc *result;
  3469. sprintf( tQBuf, "SELECT * FROM modules_kafka WHERE module_id = %d", ModuleID );
  3470. #ifdef DEBUG_ALL
  3471. LOG(tQBuf);
  3472. #endif
  3473. result = m_pDatabase->Query( tQBuf );
  3474. if( result!= NULL ) {
  3475. if( result->size() > 0 ) {
  3476. Assoc *cArr;
  3477. tVal = (KAFKA_SETTINGS*) malloc(sizeof(KAFKA_SETTINGS));
  3478. if( tVal != NULL ) {
  3479. memset( tVal, 0, sizeof(KAFKA_SETTINGS) );
  3480. Assoc::iterator it;
  3481. cArr = result->at(0);
  3482. it = cArr->find("brocker_address");
  3483. if( it != cArr->end() ){
  3484. strncpy( tVal->brocker_addr, it->second.c_str(), 255 );
  3485. };
  3486. it = cArr->find("brocker_port");
  3487. if( it != cArr->end() ){
  3488. tVal->brocker_port = atoi( it->second.c_str() );
  3489. };
  3490. it = cArr->find("use_ssl");
  3491. if( it != cArr->end() ){
  3492. tVal->use_ssl = (bool)atoi( it->second.c_str() );
  3493. };
  3494. it = cArr->find("auth_cert");
  3495. if( it != cArr->end() ){
  3496. tVal->auth_by_cert = (bool)atoi( it->second.c_str() );
  3497. };
  3498. it = cArr->find("auth_cred");
  3499. if( it != cArr->end() ){
  3500. tVal->auth_by_cred = (bool)atoi( it->second.c_str() );
  3501. };
  3502. it = cArr->find("vault_md5");
  3503. if( it != cArr->end() ){
  3504. strncpy( tVal->vault_md5, it->second.c_str(), 32 );
  3505. };
  3506. it = cArr->find("truststore");
  3507. if( it != cArr->end() ){
  3508. tVal->truststore = (bool)atoi( it->second.c_str() );
  3509. };
  3510. it = cArr->find("certstore");
  3511. if( it != cArr->end() ){
  3512. tVal->certstore = (bool)atoi( it->second.c_str() );
  3513. };
  3514. it = cArr->find("keystore");
  3515. if( it != cArr->end() ){
  3516. tVal->keystore = (bool)atoi( it->second.c_str() );
  3517. };
  3518. it = cArr->find("cred_username");
  3519. if( it != cArr->end() ){
  3520. strncpy( tVal->cred_username, it->second.c_str(), 32 );
  3521. };
  3522. it = cArr->find("cred_password");
  3523. if( it != cArr->end() ){
  3524. strncpy( tVal->cred_password, it->second.c_str(), 32 );
  3525. };
  3526. };
  3527. };
  3528. };
  3529. deleteResult( result );
  3530. };
  3531. return tVal;
  3532. };
  3533. KAFKA_TEMPLATE *mysqlDBC::getKafkaTemplateForEvent( uint32_t ModuleID, uint32_t ClassID, uint32_t EventID ){
  3534. KAFKA_TEMPLATE *tVal = NULL;
  3535. if( m_bIsConnected ) {
  3536. char tQBuf[CTEXT];
  3537. AAssoc *result;
  3538. sprintf( tQBuf, "SELECT topic, template FROM module_kafka_settings WHERE module_id=%d AND class_id=%d AND event_id=%d", ModuleID, ClassID, EventID );
  3539. #ifdef DEBUG_ALL
  3540. LOG(tQBuf);
  3541. #endif
  3542. result = m_pDatabase->Query( tQBuf );
  3543. if( result!= NULL ) {
  3544. if( result->size() > 0 ) {
  3545. Assoc *cArr;
  3546. tVal = (KAFKA_TEMPLATE*) malloc(sizeof(KAFKA_TEMPLATE));
  3547. if( tVal != NULL ) {
  3548. Assoc::iterator it;
  3549. cArr = result->at(0);
  3550. it = cArr->find("topic");
  3551. if( it != cArr->end() ){
  3552. memset( tVal->topic, 0, 128 );
  3553. strncpy( tVal->topic , it->second.c_str(), 127 );
  3554. };
  3555. it = cArr->find("template");
  3556. if( it != cArr->end() ){
  3557. tVal->tpl = (CSTR)malloc( it->second.length() + 1 );
  3558. if( tVal->tpl!= NULL) {
  3559. memset( tVal->tpl, 0, it->second.length() + 1 );
  3560. strncpy( tVal->tpl, it->second.c_str(), it->second.length() );
  3561. };
  3562. };
  3563. };
  3564. };
  3565. };
  3566. deleteResult( result );
  3567. };
  3568. return tVal;
  3569. };
  3570. DBC_UART_DATA *mysqlDBC::getUartData( uint32_t UartID ){
  3571. DBC_UART_DATA *tVal = NULL;
  3572. if( m_bIsConnected ) {
  3573. char tQBuf[MAX_PATH_LEN];
  3574. AAssoc *result;
  3575. sprintf( tQBuf, "SELECT * FROM uart_settings WHERE id = %d", UartID );
  3576. #ifdef DEBUG_ALL
  3577. LOG(tQBuf);
  3578. #endif
  3579. result = m_pDatabase->Query( tQBuf );
  3580. if( result!= NULL ) {
  3581. if( result->size() > 0 ) {
  3582. Assoc *cArr;
  3583. tVal = (DBC_UART_DATA*) malloc(sizeof(DBC_UART_DATA));
  3584. if( tVal != NULL ) {
  3585. Assoc::iterator it;
  3586. cArr = result->at(0);
  3587. it = cArr->find("type");
  3588. if( it != cArr->end() ){
  3589. tVal->type = atoi( it->second.c_str() );
  3590. };
  3591. it = cArr->find("speed");
  3592. if( it != cArr->end() ){
  3593. tVal->speed = atoi( it->second.c_str() );
  3594. };
  3595. it = cArr->find("mode");
  3596. if( it != cArr->end() ){
  3597. tVal->mode = atoi( it->second.c_str() );
  3598. };
  3599. it = cArr->find("port");
  3600. if( it != cArr->end() ){
  3601. tVal->port = atoi( it->second.c_str() );
  3602. };
  3603. it = cArr->find("path");
  3604. if( it != cArr->end() ){
  3605. strncpy( tVal->path, it->second.c_str(), 128 );
  3606. };
  3607. };
  3608. };
  3609. };
  3610. deleteResult( result );
  3611. };
  3612. return tVal;
  3613. };
  3614. uint32_t mysqlDBC::getUartID( uint32_t NodeID, uint8_t Type, CSTR path ){
  3615. uint32_t RetVal = 0;
  3616. if(m_bIsConnected){
  3617. char tQBuf[CTEXT];
  3618. sprintf(tQBuf,"SELECT `id` FROM `uart_settings` WHERE `node_id`=%d AND `type`=%d AND `path`='%s' ", NodeID, Type, path );
  3619. #ifdef DEBUG_ALL
  3620. LOG(tQBuf);
  3621. #endif
  3622. AAssoc *result;
  3623. result = m_pDatabase->Query( tQBuf );
  3624. if( result!= NULL ) {
  3625. if( result->size() > 0 ) {
  3626. Assoc * cArr;
  3627. Assoc::iterator it;
  3628. cArr = result->at(0);
  3629. it = cArr->find("id");
  3630. if( it != cArr->end() ){
  3631. RetVal = atoi( it->second.c_str() );
  3632. };
  3633. };
  3634. };
  3635. deleteResult( result );
  3636. };
  3637. return RetVal;
  3638. };
  3639. bool mysqlDBC::updateMediaServerStream( uint32_t id, CSTR mrl, CSTR key ){
  3640. if( m_bIsConnected ) {
  3641. char tQBuf[MAX_PATH_LEN];
  3642. if( key == NULL ) {
  3643. if( mrl == NULL ) {
  3644. sprintf( tQBuf,"UPDATE media_server_streams SET `online`=0, `key`='', mrl='', `valid`=0 WHERE `id`=%d", id );
  3645. } else {
  3646. sprintf( tQBuf,"UPDATE media_server_streams SET `online`=0, `key`='', `mrl`='%s', `valid`=1 WHERE `id`=%d", mrl, id );
  3647. };
  3648. } else {
  3649. sprintf( tQBuf,"UPDATE media_server_streams SET `online`=1, `key`='%s', `mrl`='%s', `valid`=1 WHERE `id`=%d",
  3650. key,
  3651. mrl,
  3652. id
  3653. );
  3654. };
  3655. #ifdef DEBUG_ALL
  3656. LOG(tQBuf);
  3657. #endif
  3658. m_pDatabase->SilentQuery( tQBuf );
  3659. return true;
  3660. };
  3661. return false;
  3662. };
  3663. bool mysqlDBC::updateResourceAUX( uint32_t ResID, uint32_t AUX ){
  3664. if( m_bIsConnected ) {
  3665. char tQBuf[MAX_PATH_LEN];
  3666. sprintf( tQBuf, "UPDATE `resources` SET `aux_id`=%d WHERE `id`=%d", AUX, ResID );
  3667. #ifdef DEBUG
  3668. LOG(tQBuf);
  3669. #endif
  3670. m_pDatabase->SilentQuery( tQBuf );
  3671. return true;
  3672. };
  3673. return false;
  3674. };
  3675. //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 ){
  3676. bool mysqlDBC::updateServerUtilisation( DBC_SYS_LOAD_INFO *ptr ){
  3677. if( m_bIsConnected ) {
  3678. char tQBuf[MAX_PATH_LEN];
  3679. 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",
  3680. ptr->CPU_CORES,
  3681. ptr->cpu1,
  3682. ptr->cpu5,
  3683. ptr->cpu15,
  3684. ptr->mem,
  3685. ptr->disk,
  3686. ptr->temperature,
  3687. ptr->T_DISK,
  3688. ptr->C_DISK,
  3689. ptr->T_MEM,
  3690. ptr->C_MEM,
  3691. m_nServerID
  3692. );
  3693. #ifdef DEBUG_ALL
  3694. LOG(tQBuf);
  3695. #endif
  3696. m_pDatabase->SilentQuery( tQBuf );
  3697. return true;
  3698. };
  3699. return false;
  3700. };
  3701. uint32_t mysqlDBC::addLocalDCB( uint32_t SiteID, CSTR PATH, CSTR SERIAL, uint8_t CNT, uint32_t status ){
  3702. uint32_t RetVal = 0;
  3703. if( m_bIsConnected ) {
  3704. char tQBuf[MAX_PATH_LEN];
  3705. 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",
  3706. SiteID,
  3707. status,
  3708. CNT,
  3709. SERIAL,
  3710. status,
  3711. CNT
  3712. );
  3713. #ifdef DEBUG_ALL
  3714. LOG(tQBuf);
  3715. #endif
  3716. uint64_t cid = m_pDatabase->QueryID( tQBuf );
  3717. if( cid == 0 ) {
  3718. AAssoc *result;
  3719. sprintf( tQBuf, "SELECT id FROM modules_dcr WHERE site_id=%d AND serial_id='%s'",
  3720. SiteID,
  3721. SERIAL
  3722. );
  3723. #ifdef DEBUG_ALL
  3724. LOG(tQBuf);
  3725. #endif
  3726. result = m_pDatabase->Query( tQBuf );
  3727. if( result!= NULL ) {
  3728. if( result->size() > 0 ) {
  3729. Assoc * cArr;
  3730. Assoc::iterator it;
  3731. cArr = result->at(0);
  3732. it = cArr->find("id");
  3733. if( it != cArr->end() ){
  3734. cid = atoi( it->second.c_str() );
  3735. };
  3736. };
  3737. deleteResult( result );
  3738. };
  3739. };
  3740. if( cid!= 0 ) {
  3741. for( uint8_t idx = 0; idx < CNT; idx++ ) {
  3742. if( status & ( 1 << idx ) ){
  3743. sprintf( tQBuf, "INSERT INTO module_dcr_chanels SET dcr_id=%d, channel_id=%d, mode='O', status='C' ON DUPLICATE KEY UPDATE status='C'",
  3744. (uint32_t) cid,
  3745. idx
  3746. );
  3747. } else {
  3748. sprintf( tQBuf, "INSERT INTO module_dcr_chanels SET dcr_id=%d, channel_id=%d, mode='O', status='O' ON DUPLICATE KEY UPDATE status='O'",
  3749. (uint32_t) cid,
  3750. idx
  3751. );
  3752. }
  3753. #ifdef DEBUG_ALL
  3754. LOG(tQBuf);
  3755. #endif
  3756. m_pDatabase->SilentQuery( tQBuf );
  3757. };
  3758. };
  3759. };
  3760. return RetVal;
  3761. };
  3762. 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 ){
  3763. uint32_t RetVal = 0;
  3764. if( m_bIsConnected ) {
  3765. char tQBuf[MAX_PATH_LEN];
  3766. 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`",
  3767. m_nServerNodeID,
  3768. utype,
  3769. speed,
  3770. bit,
  3771. parity,
  3772. stop_bit,
  3773. mode,
  3774. port,
  3775. PATH
  3776. );
  3777. #ifdef DEBUG_ALL
  3778. LOG(tQBuf);
  3779. #endif
  3780. RetVal = m_pDatabase->QueryID( tQBuf );
  3781. if( RetVal == 0 ) {
  3782. RetVal = getUartID( m_nServerNodeID, utype, PATH );
  3783. };
  3784. };
  3785. return RetVal;
  3786. };
  3787. uint32_t mysqlDBC::addLocalNIF( CSTR device, CSTR mac, NIF_TYPE dtype, NIF_MODE dmode, uint32_t aux_id ){
  3788. uint32_t RetVal = 0;
  3789. if( m_bIsConnected ) {
  3790. char tQBuf[MAX_PATH_LEN];
  3791. char * tKey = MD5String( device );
  3792. if( tKey != NULL ) {
  3793. 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'",
  3794. dtype,
  3795. tKey,
  3796. device,
  3797. mac,
  3798. dmode,
  3799. aux_id,
  3800. dmode,
  3801. aux_id,
  3802. mac
  3803. );
  3804. #ifdef DEBUG
  3805. LOG(tQBuf);
  3806. #endif
  3807. RetVal = m_pDatabase->QueryID( tQBuf );
  3808. if( RetVal == 0 ) {
  3809. RetVal = getNIF_ID( tKey );
  3810. };
  3811. free( tKey );
  3812. };
  3813. };
  3814. return RetVal;
  3815. };
  3816. uint32_t mysqlDBC::addLocalWiFi( uint32_t NIF_ID, WIFI_MODE mode, CSTR SSID, CSTR password, WIFI_ENCRIPTION encryption, uint32_t router_id ){
  3817. uint32_t RetVal = 0;
  3818. if( m_bIsConnected ) {
  3819. char tQBuf[MAX_PATH_LEN];
  3820. 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",
  3821. NIF_ID,
  3822. mode,
  3823. router_id,
  3824. SSID,
  3825. password,
  3826. encryption,
  3827. mode,
  3828. router_id,
  3829. SSID,
  3830. password,
  3831. encryption
  3832. );
  3833. #ifdef DEBUG
  3834. LOG(tQBuf);
  3835. #endif
  3836. RetVal = m_pDatabase->QueryID( tQBuf );
  3837. if( RetVal == 0 ) {
  3838. RetVal = getWiFi_ID( NIF_ID );
  3839. };
  3840. };
  3841. return RetVal;
  3842. };
  3843. uint32_t mysqlDBC::addLRFMask( uint32_t devID, uint8_t lrfID, uint8_t layerID ){
  3844. uint32_t RetVal = 0;
  3845. if( m_bIsConnected ) {
  3846. char tQBuf[MAX_PATH_LEN];
  3847. sprintf( tQBuf, "INSERT INTO `lrf_masks` SET `sensor_id`=%d, `lrf_id`=%d, `layer`=%d ON DUPLICATE KEY UPDATE `id`=`id`",
  3848. devID,
  3849. lrfID,
  3850. layerID
  3851. );
  3852. #ifdef DEBUG
  3853. LOG(tQBuf);
  3854. #endif
  3855. RetVal = m_pDatabase->QueryID( tQBuf );
  3856. if( RetVal == 0 ) {
  3857. RetVal = getLRFMaskID( devID, lrfID, layerID );
  3858. };
  3859. };
  3860. return RetVal;
  3861. };
  3862. uint32_t mysqlDBC::addLRFMaskPolygone( uint32_t maskID, uint8_t r, uint8_t g, uint8_t b ){
  3863. uint32_t RetVal = 0;
  3864. if( m_bIsConnected ) {
  3865. char tQBuf[MAX_PATH_LEN];
  3866. sprintf( tQBuf, "INSERT INTO `lrf_mask_vertexes` SET `mask_id`=%d, `r`=%d, `g`=%d, `b`=%d",
  3867. maskID,
  3868. r,
  3869. g,
  3870. b
  3871. );
  3872. #ifdef DEBUG
  3873. LOG(tQBuf);
  3874. #endif
  3875. RetVal = m_pDatabase->QueryID( tQBuf );
  3876. };
  3877. return RetVal;
  3878. };
  3879. bool mysqlDBC::addLRFMaskPolygonePoint( uint32_t polyID, int16_t x, int16_t y ){
  3880. if( m_bIsConnected ) {
  3881. char tQBuf[MAX_PATH_LEN];
  3882. sprintf( tQBuf, "INSERT INTO `lrf_mask_vertex_points` SET `vertex_id`=%d, `x`=%d, `y`=%d",
  3883. polyID,
  3884. x,
  3885. y
  3886. );
  3887. #ifdef DEBUG
  3888. LOG(tQBuf);
  3889. #endif
  3890. m_pDatabase->SilentQuery( tQBuf );
  3891. return true;
  3892. };
  3893. return false;
  3894. };
  3895. uint32_t mysqlDBC::addLocalNetwork( uint32_t NIF_ID, NETWORK_TYPE net_type, CSTR address, CSTR mask, CSTR gateway, CSTR broadcast ){
  3896. uint32_t RetVal = 0;
  3897. if( m_bIsConnected ) {
  3898. char tQBuf[MAX_PATH_LEN];
  3899. 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'",
  3900. NIF_ID,
  3901. net_type,
  3902. address,
  3903. gateway,
  3904. mask,
  3905. broadcast,
  3906. address,
  3907. gateway,
  3908. mask,
  3909. broadcast
  3910. );
  3911. #ifdef DEBUG
  3912. LOG(tQBuf);
  3913. #endif
  3914. RetVal = m_pDatabase->QueryID( tQBuf );
  3915. // On Update IF data no need to return ID
  3916. //if( RetVal == 0 ) {
  3917. // RetVal = getNetworkInterfaceID( tKey );
  3918. //};
  3919. };
  3920. return RetVal;
  3921. };
  3922. uint32_t mysqlDBC::addLocalNetworkInfrastructure( uint32_t NIF_ID, uint32_t OUTBOUND_NIF, bool ena_dhcp, CSTR BRANG, CSTR ERANG, CSTR MASK, CSTR LEASE_TIME ){
  3923. uint32_t RetVal = 0;
  3924. if( m_bIsConnected ) {
  3925. char tQBuf[MAX_PATH_LEN];
  3926. bool ena_routing = true;
  3927. if( OUTBOUND_NIF == 0 ){
  3928. ena_routing = false;
  3929. };
  3930. if( ena_dhcp ){
  3931. if ( BRANG == NULL || ERANG == NULL || MASK == NULL || LEASE_TIME == NULL ) {
  3932. LOG_ERROR("Wrong DHCP parameters to create Network Infrastructure!");
  3933. return 0;
  3934. };
  3935. 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'",
  3936. NIF_ID,
  3937. ena_routing,
  3938. OUTBOUND_NIF,
  3939. BRANG,
  3940. ERANG,
  3941. MASK,
  3942. LEASE_TIME,
  3943. ena_routing,
  3944. OUTBOUND_NIF,
  3945. BRANG,
  3946. ERANG,
  3947. MASK,
  3948. LEASE_TIME
  3949. );
  3950. } else {
  3951. if( ena_routing ){
  3952. 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",
  3953. NIF_ID,
  3954. OUTBOUND_NIF,
  3955. OUTBOUND_NIF
  3956. );
  3957. } else {
  3958. LOG_ERROR("No Special Service Defined To Network Infrastructure!");
  3959. return 0;
  3960. };
  3961. };
  3962. #ifdef DEBUG_ALL
  3963. LOG(tQBuf);
  3964. #endif
  3965. RetVal = m_pDatabase->QueryID( tQBuf );
  3966. // On Update IF data no need to return ID
  3967. if( RetVal == 0 ) {
  3968. RetVal = getNetworkInfrastructureID( NIF_ID );
  3969. };
  3970. };
  3971. return RetVal;
  3972. };
  3973. /*
  3974. bool mysqlDBC::addLRFDraw( uint32_t DBID, uint32_t SIZE, CSTR ID, uint8_t kID, uint8_t type, bool rendered ){
  3975. if( m_bIsConnected ) {
  3976. char tQBuf[MAX_PATH_LEN];
  3977. if ( rendered ) {
  3978. 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'",
  3979. DBID,
  3980. ID,
  3981. SIZE,
  3982. kID,
  3983. type,
  3984. ID,
  3985. SIZE
  3986. );
  3987. } else {
  3988. 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'",
  3989. DBID,
  3990. ID,
  3991. SIZE,
  3992. kID,
  3993. type,
  3994. ID,
  3995. SIZE
  3996. );
  3997. };
  3998. #ifdef DEBUG
  3999. LOG(tQBuf);
  4000. #endif
  4001. m_pDatabase->SilentQuery( tQBuf );
  4002. return true;
  4003. };
  4004. return false;
  4005. };
  4006. */
  4007. 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 ){
  4008. uint32_t RetVal = 0;
  4009. if( m_bIsConnected ) {
  4010. char tQBuf[MAX_PATH_LEN];
  4011. if( RefUUID == NULL ) {
  4012. 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",
  4013. SRC,
  4014. UUID,
  4015. tss,
  4016. tsms,
  4017. evt_type,
  4018. k_id,
  4019. dig_r,
  4020. AZ,
  4021. EL,
  4022. RANGE,
  4023. AREA,
  4024. lat,
  4025. lon,
  4026. alt
  4027. );
  4028. } else {
  4029. 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'",
  4030. SRC,
  4031. UUID,
  4032. tss,
  4033. tsms,
  4034. evt_type,
  4035. k_id,
  4036. dig_r,
  4037. AZ,
  4038. EL,
  4039. RANGE,
  4040. AREA,
  4041. lat,
  4042. lon,
  4043. alt,
  4044. RefUUID
  4045. );
  4046. };
  4047. #ifdef DEBUG_ALL
  4048. LOG(tQBuf);
  4049. #endif
  4050. RetVal = (uint32_t) m_pDatabase->QueryID( tQBuf );
  4051. if( RetVal ) {
  4052. if (RefUUID == NULL) {
  4053. 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",
  4054. RetVal,
  4055. SRC,
  4056. UUID,
  4057. tss,
  4058. tsms,
  4059. evt_type,
  4060. k_id,
  4061. dig_r,
  4062. AZ,
  4063. EL,
  4064. RANGE,
  4065. AREA,
  4066. lat,
  4067. lon,
  4068. alt
  4069. );
  4070. } else {
  4071. 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'",
  4072. RetVal,
  4073. SRC,
  4074. UUID,
  4075. tss,
  4076. tsms,
  4077. evt_type,
  4078. k_id,
  4079. dig_r,
  4080. AZ,
  4081. EL,
  4082. RANGE,
  4083. AREA,
  4084. lat,
  4085. lon,
  4086. alt,
  4087. RefUUID
  4088. );
  4089. };
  4090. m_pDatabase->SilentQuery( tQBuf );
  4091. };
  4092. // Cleanup Mem Targets Older then 1 Hour
  4093. sprintf( tQBuf, "DELETE FROM events_cloud WHERE ts < ( UNIX_TIMESTAMP(NOW()) - 3600 )" );
  4094. m_pDatabase->SilentQuery( tQBuf );
  4095. };
  4096. return RetVal;
  4097. };
  4098. bool mysqlDBC::addDeviceDraw( uint32_t DBID, uint8_t type, uint8_t lrf, void *th_data, uint32_t th_size ){
  4099. bool rVal = false;
  4100. if( th_data != NULL && th_size ){
  4101. if( m_bIsConnected ){
  4102. CSTR tPData = m_pDatabase->escapeBinary( (uint8_t *) th_data, th_size );
  4103. if ( tPData ) {
  4104. CSTR tQBuf = (CSTR)malloc(BUF_4MB);
  4105. if( tQBuf ) {
  4106. sprintf( tQBuf, "DELETE FROM `lrf_draw` WHERE `node_id`=%d AND `lrf_id`=%d AND `type`=%d", DBID, lrf, type );
  4107. LOG( tQBuf );
  4108. m_pDatabase->SilentQuery( tQBuf );
  4109. 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 );
  4110. m_pDatabase->SilentQuery( tQBuf );
  4111. LOG( "Inserted Draw OK!" );
  4112. free( tQBuf );
  4113. rVal = true;
  4114. } else {
  4115. LOG_ERROR("Error Allocating Query Buffer!");
  4116. };
  4117. free( tPData );
  4118. } else {
  4119. LOG_ERROR( "Error escaping Pic Data!");
  4120. };
  4121. };
  4122. };
  4123. return rVal;
  4124. };
  4125. bool mysqlDBC::addVideoEvent( uint32_t evtID, uint32_t videoID, uint32_t clen ){
  4126. if( m_bIsConnected ) {
  4127. char tQBuf[MAX_PATH_LEN];
  4128. sprintf( tQBuf, "INSERT INTO `events_2_videos` SET `evt_id`=%d, `video_id`=%d, `frame`=%d", evtID, videoID, clen );
  4129. #ifdef DEBUG_ALL
  4130. LOG(tQBuf);
  4131. #endif
  4132. m_pDatabase->SilentQuery( tQBuf );
  4133. return true;
  4134. };
  4135. return true;
  4136. };
  4137. /*
  4138. bool mysqlDBC::addPictureEvent( uint32_t evtID, uint32_t pictureoID ){
  4139. if( m_bIsConnected ) {
  4140. char tQBuf[MAX_PATH_LEN];
  4141. sprintf( tQBuf, "INSERT INTO `events_2_pictures` SET `evt_id`=%d, `picture_id`=%d", evtID, pictureoID );
  4142. #ifdef DEBUG_ALL
  4143. LOG(tQBuf);
  4144. #endif
  4145. m_pDatabase->SilentQuery( tQBuf );
  4146. return true;
  4147. };
  4148. return true;
  4149. };
  4150. */
  4151. uint32_t mysqlDBC::addVideoRecord( uint32_t streamID, CSTR md5, CSTR ext, uint32_t ts, uint32_t tsms, uint32_t fps ){
  4152. uint32_t tID = 0;
  4153. if( m_bIsConnected ) {
  4154. char tQBuf[MAX_PATH_LEN];
  4155. 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 );
  4156. #ifdef DEBUG_ALL
  4157. LOG(tQBuf);
  4158. #endif
  4159. tID = (uint32_t) m_pDatabase->QueryID( tQBuf );
  4160. }
  4161. return tID;
  4162. };
  4163. bool mysqlDBC::addPicture( DBC_SNAPSHOT_DATA *ptr, CSTR ext ){
  4164. bool rVal = false;
  4165. if( ptr != NULL ){
  4166. if( m_bIsConnected ){
  4167. CSTR tPData = m_pDatabase->escapeBinary( ptr->data, ptr->data_size );
  4168. if ( tPData ) {
  4169. uint32_t pic_id;
  4170. CSTR tQBuf = (CSTR)malloc(BUF_4MB);
  4171. if( tQBuf ) {
  4172. //sprintf( tQBuf, "INSERT INTO `pictures` SET `media_stream_id`=%d, `ts`=NOW(), `md5`='%s', `ext`='%s'",
  4173. sprintf( tQBuf, "INSERT INTO pictures(media_stream_id,ts,md5,ext,data) VALUES(%d,NOW(),'%s','%s','%s')",
  4174. ptr->stream_id, ptr->md5, ext, tPData );
  4175. pic_id = (uint32_t) m_pDatabase->QueryID( tQBuf );
  4176. if ( pic_id ) {
  4177. for( DBC_INT_LIST::iterator idx = ptr->assoc_event_ids.begin(); idx < ptr->assoc_event_ids.end(); idx++ ) {
  4178. sprintf( tQBuf, "INSERT INTO `events_2_pictures` SET `evt_id`=%d, `picture_id`=%d", (*idx), pic_id );
  4179. m_pDatabase->SilentQuery( tQBuf );
  4180. };
  4181. rVal = true;
  4182. };
  4183. free( tQBuf );
  4184. } else {
  4185. LOG_ERROR("Error Allocating Query Buffer!");
  4186. };
  4187. free( tPData );
  4188. } else {
  4189. LOG_ERROR( "Error escaping Pic Data!");
  4190. };
  4191. };
  4192. };
  4193. return rVal;
  4194. };
  4195. 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 ){
  4196. if( m_bIsConnected ) {
  4197. char tQBuf[MAX_PATH_LEN];
  4198. if( master ) {
  4199. 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",
  4200. lrfID,
  4201. profileID,
  4202. nOrder,
  4203. nOffset,
  4204. nDelta,
  4205. nFlip,
  4206. nWidth,
  4207. bSST,
  4208. nSun,
  4209. GP,
  4210. spikes,
  4211. nOrder,
  4212. nOffset,
  4213. nDelta,
  4214. nFlip,
  4215. nWidth,
  4216. bSST,
  4217. nSun,
  4218. GP,
  4219. spikes );
  4220. } else {
  4221. 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",
  4222. lrfID,
  4223. profileID,
  4224. nOrder,
  4225. nOffset,
  4226. nDelta,
  4227. nFlip,
  4228. nWidth,
  4229. bSST,
  4230. nSun,
  4231. GP,
  4232. spikes,
  4233. nOrder,
  4234. nOffset,
  4235. nDelta,
  4236. nFlip,
  4237. nWidth,
  4238. bSST,
  4239. nSun,
  4240. GP,
  4241. spikes );
  4242. };
  4243. #ifdef DEBUG_ALL
  4244. LOG(tQBuf);
  4245. #endif
  4246. m_pDatabase->SilentQuery( tQBuf );
  4247. return true;
  4248. };
  4249. return false;
  4250. };
  4251. bool mysqlDBC::updateLRFSerial( uint32_t lrfID, CSTR Serial ){
  4252. if( m_bIsConnected ) {
  4253. char tQBuf[MAX_PATH_LEN];
  4254. CSTR tES = m_pDatabase->escapeString( Serial );
  4255. if( tES ) {
  4256. sprintf( tQBuf, "UPDATE `lrf_sensors` SET `serial`='%s' WHERE `id`=%d", tES, lrfID );
  4257. free( tES );
  4258. #ifdef DEBUG_ALL
  4259. LOG(tQBuf);
  4260. #endif
  4261. m_pDatabase->SilentQuery( tQBuf );
  4262. return true;
  4263. };
  4264. };
  4265. return false;
  4266. };
  4267. bool mysqlDBC::updateLRFVerison( uint32_t lrfID, CSTR version ){
  4268. if( m_bIsConnected ) {
  4269. char tQBuf[MAX_PATH_LEN];
  4270. CSTR tES = m_pDatabase->escapeString( version );
  4271. if( tES ) {
  4272. sprintf( tQBuf, "UPDATE `lrf_sensors` SET `version`='%s' WHERE `id`=%d", tES, lrfID );
  4273. free( tES );
  4274. #ifdef DEBUG_ALL
  4275. LOG(tQBuf);
  4276. #endif
  4277. m_pDatabase->SilentQuery( tQBuf );
  4278. return true;
  4279. };
  4280. };
  4281. return false;
  4282. };
  4283. bool mysqlDBC::update3DRuntimeStatus( uint32_t lrfID, ALG_RUN_STATUS *ptr ){
  4284. if( m_bIsConnected ) {
  4285. char tQBuf[MAX_PATH_LEN];
  4286. sprintf( tQBuf, "INSERT INTO `lrf_runtime_status` SET `lrf_id`=%d ON DUPLICATE KEY UPDATE `lrf_id`=`lrf_id`", lrfID );
  4287. #ifdef DEBUG_ALL
  4288. LOG(tQBuf);
  4289. #endif
  4290. m_pDatabase->SilentQuery( tQBuf );
  4291. sprintf( tQBuf,
  4292. "UPDATE `lrf_runtime_status` SET "
  4293. "`hw_status`=%d,"
  4294. "`detecting_kernels`=%d,"
  4295. "`th_ready`=%d,"
  4296. "`master_flips`=%d,"
  4297. "`slave_flips`=%d,"
  4298. "`twinc`=%d,"
  4299. "`master_mp_0`=%d,"
  4300. "`master_mp_1`=%d,"
  4301. "`master_mp_2`=%d,"
  4302. "`master_mp_3`=%d,"
  4303. "`master_mp_4`=%d,"
  4304. "`master_mp_5`=%d,"
  4305. "`master_mp_6`=%d,"
  4306. "`master_mp_7`=%d,"
  4307. "`master_gp_0`=%d,"
  4308. "`master_gp_1`=%d,"
  4309. "`master_gp_2`=%d,"
  4310. "`master_gp_3`=%d,"
  4311. "`master_gp_4`=%d,"
  4312. "`master_gp_5`=%d,"
  4313. "`master_gp_6`=%d,"
  4314. "`master_gp_7`=%d,"
  4315. "`master_wp_0`=%d,"
  4316. "`master_wp_1`=%d,"
  4317. "`master_wp_2`=%d,"
  4318. "`master_wp_3`=%d,"
  4319. "`master_wp_4`=%d,"
  4320. "`master_wp_5`=%d,"
  4321. "`master_wp_6`=%d,"
  4322. "`master_wp_7`=%d,"
  4323. "`slave_mp_0`=%d,"
  4324. "`slave_mp_1`=%d,"
  4325. "`slave_mp_2`=%d,"
  4326. "`slave_mp_3`=%d,"
  4327. "`slave_mp_4`=%d,"
  4328. "`slave_mp_5`=%d,"
  4329. "`slave_mp_6`=%d,"
  4330. "`slave_mp_7`=%d,"
  4331. "`slave_gp_0`=%d,"
  4332. "`slave_gp_1`=%d,"
  4333. "`slave_gp_2`=%d,"
  4334. "`slave_gp_3`=%d,"
  4335. "`slave_gp_4`=%d,"
  4336. "`slave_gp_5`=%d,"
  4337. "`slave_gp_6`=%d,"
  4338. "`slave_gp_7`=%d,"
  4339. "`slave_wp_0`=%d,"
  4340. "`slave_wp_1`=%d,"
  4341. "`slave_wp_2`=%d,"
  4342. "`slave_wp_3`=%d,"
  4343. "`slave_wp_4`=%d,"
  4344. "`slave_wp_5`=%d,"
  4345. "`slave_wp_6`=%d,"
  4346. "`slave_wp_7`=%d"
  4347. " WHERE `lrf_id`=%d",
  4348. ptr->HW_STATUS,
  4349. ptr->DETECTING_LRF,
  4350. ptr->TH_READY,
  4351. ptr->MASTER_FLIP_CNT,
  4352. ptr->SLAVE_FLIP_CNT,
  4353. ptr->TWINC_STATUS,
  4354. ptr->MASTER_MP[0],
  4355. ptr->MASTER_MP[1],
  4356. ptr->MASTER_MP[2],
  4357. ptr->MASTER_MP[3],
  4358. ptr->MASTER_MP[4],
  4359. ptr->MASTER_MP[5],
  4360. ptr->MASTER_MP[6],
  4361. ptr->MASTER_MP[7],
  4362. ptr->MASTER_GP[0],
  4363. ptr->MASTER_GP[1],
  4364. ptr->MASTER_GP[2],
  4365. ptr->MASTER_GP[3],
  4366. ptr->MASTER_GP[4],
  4367. ptr->MASTER_GP[5],
  4368. ptr->MASTER_GP[6],
  4369. ptr->MASTER_GP[7],
  4370. ptr->MASTER_WP[0],
  4371. ptr->MASTER_WP[1],
  4372. ptr->MASTER_WP[2],
  4373. ptr->MASTER_WP[3],
  4374. ptr->MASTER_WP[4],
  4375. ptr->MASTER_WP[5],
  4376. ptr->MASTER_WP[6],
  4377. ptr->MASTER_WP[7],
  4378. ptr->SLAVE_MP[0],
  4379. ptr->SLAVE_MP[1],
  4380. ptr->SLAVE_MP[2],
  4381. ptr->SLAVE_MP[3],
  4382. ptr->SLAVE_MP[4],
  4383. ptr->SLAVE_MP[5],
  4384. ptr->SLAVE_MP[6],
  4385. ptr->SLAVE_MP[7],
  4386. ptr->SLAVE_GP[0],
  4387. ptr->SLAVE_GP[1],
  4388. ptr->SLAVE_GP[2],
  4389. ptr->SLAVE_GP[3],
  4390. ptr->SLAVE_GP[4],
  4391. ptr->SLAVE_GP[5],
  4392. ptr->SLAVE_GP[6],
  4393. ptr->SLAVE_GP[7],
  4394. ptr->SLAVE_WP[0],
  4395. ptr->SLAVE_WP[1],
  4396. ptr->SLAVE_WP[2],
  4397. ptr->SLAVE_WP[3],
  4398. ptr->SLAVE_WP[4],
  4399. ptr->SLAVE_WP[5],
  4400. ptr->SLAVE_WP[6],
  4401. ptr->SLAVE_WP[7],
  4402. lrfID
  4403. );
  4404. #ifdef DEBUG_ALL
  4405. LOG(tQBuf);
  4406. #endif
  4407. m_pDatabase->SilentQuery( tQBuf );
  4408. return true;
  4409. };
  4410. return false;
  4411. };
  4412. bool mysqlDBC::setLRFDataStatus( uint32_t lrfID, uint8_t ST ){
  4413. if( m_bIsConnected ) {
  4414. char tQBuf[MAX_PATH_LEN];
  4415. sprintf( tQBuf, "UPDATE `lrf_sensors` SET `data_status`=%d WHERE `id`=%d", ST, lrfID );
  4416. #ifdef DEBUG_ALL
  4417. LOG(tQBuf);
  4418. #endif
  4419. m_pDatabase->SilentQuery( tQBuf );
  4420. return true;
  4421. };
  4422. return false;
  4423. };
  4424. bool mysqlDBC::setLRFDetectionProfile( uint32_t lrfID, uint8_t profileID ){
  4425. if( m_bIsConnected ) {
  4426. char tQBuf[MAX_PATH_LEN];
  4427. sprintf( tQBuf, "UPDATE `lrf_sensors` SET `detection_profile_id`=%d WHERE `id`=%d", profileID, lrfID );
  4428. #ifdef DEBUG_ALL
  4429. LOG(tQBuf);
  4430. #endif
  4431. m_pDatabase->SilentQuery( tQBuf );
  4432. return true;
  4433. };
  4434. return false;
  4435. };
  4436. bool mysqlDBC::setLRFMaskStatus( uint32_t maskID, bool status ){
  4437. if( m_bIsConnected ) {
  4438. char tQBuf[MAX_PATH_LEN];
  4439. char S[2];
  4440. if (status ) {
  4441. S[0] = 'E';
  4442. S[1] = (char)0;
  4443. } else {
  4444. S[0] = 'D';
  4445. S[1] = (char)0;
  4446. };
  4447. sprintf( tQBuf, "UPDATE `lrf_masks` SET `status`='%s' WHERE `id`=%d", S, maskID );
  4448. #ifdef DEBUG_ALL
  4449. LOG(tQBuf);
  4450. #endif
  4451. m_pDatabase->SilentQuery( tQBuf );
  4452. return true;
  4453. };
  4454. return false;
  4455. };
  4456. bool mysqlDBC::setLRFAltSerial( uint32_t lrfID, CSTR Serial ){
  4457. if( m_bIsConnected ) {
  4458. char tQBuf[MAX_PATH_LEN];
  4459. sprintf( tQBuf, "UPDATE `lrf_sensors` SET `alt_serial`='%s' WHERE `id`=%d", Serial, lrfID );
  4460. #ifdef DEBUG_ALL
  4461. LOG(tQBuf);
  4462. #endif
  4463. m_pDatabase->SilentQuery( tQBuf );
  4464. return true;
  4465. };
  4466. return false;
  4467. };
  4468. bool mysqlDBC::setLRFAltVerison( uint32_t lrfID, CSTR version ){
  4469. if( m_bIsConnected ) {
  4470. char tQBuf[MAX_PATH_LEN];
  4471. sprintf( tQBuf, "UPDATE `lrf_sensors` SET `alt_version`='%s' WHERE `id`=%d", version, lrfID );
  4472. #ifdef DEBUG_ALL
  4473. LOG(tQBuf);
  4474. #endif
  4475. m_pDatabase->SilentQuery( tQBuf );
  4476. return true;
  4477. };
  4478. return false;
  4479. };
  4480. bool mysqlDBC::setStreamValid( uint32_t streamID, bool status ){
  4481. if( m_bIsConnected ) {
  4482. char tQBuf[MAX_PATH_LEN];
  4483. if ( status ) {
  4484. sprintf(tQBuf, "UPDATE `media_streams` SET `valid`=1 WHERE `id`=%d", streamID);
  4485. } else {
  4486. sprintf(tQBuf, "UPDATE `media_streams` SET `valid`=0 WHERE `id`=%d", streamID);
  4487. };
  4488. #ifdef DEBUG_ALL
  4489. LOG(tQBuf);
  4490. #endif
  4491. m_pDatabase->SilentQuery( tQBuf );
  4492. return true;
  4493. };
  4494. return false;
  4495. };
  4496. bool mysqlDBC::updateAFPBox( uint32_t filterID, CSTR Tag, float x, float y, float z ){
  4497. if( m_bIsConnected ) {
  4498. char tQBuf[MAX_PATH_LEN];
  4499. 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",
  4500. filterID,
  4501. Tag,
  4502. x,y,z,
  4503. x,y,z
  4504. );
  4505. #ifdef DEBUG_ALL
  4506. LOG(tQBuf);
  4507. #endif
  4508. m_pDatabase->SilentQuery( tQBuf );
  4509. return true;
  4510. };
  4511. return false;
  4512. };
  4513. DBC_MODULE_EMBED_VIDEO_DATA *mysqlDBC::getEmbedVideoData( uint32_t ID ){
  4514. DBC_MODULE_EMBED_VIDEO_DATA *tPtr = NULL;
  4515. if( m_bIsConnected ) {
  4516. char tQBuf[MAX_PATH_LEN];
  4517. AAssoc *result;
  4518. sprintf( tQBuf, "SELECT * FROM `module_eve` WHERE `id`=%d", ID );
  4519. #ifdef DEBUG_ALL
  4520. LOG(tQBuf);
  4521. #endif
  4522. result = m_pDatabase->Query( tQBuf );
  4523. if( result!= NULL ) {
  4524. if( result->size() > 0 ) {
  4525. Assoc *cArr;
  4526. tPtr = (DBC_MODULE_EMBED_VIDEO_DATA*)malloc(sizeof(DBC_MODULE_EMBED_VIDEO_DATA));
  4527. if( tPtr!= NULL ) {
  4528. Assoc::iterator it;
  4529. memset(tPtr,0,sizeof(DBC_MODULE_EMBED_VIDEO_DATA));
  4530. cArr = result->at(0);
  4531. it = cArr->find("output_mode");
  4532. if( it != cArr->end() ){
  4533. tPtr->output_mode = atoi( it->second.c_str() );
  4534. };
  4535. it = cArr->find("web_port");
  4536. if( it != cArr->end() ){
  4537. tPtr->port = atoi( it->second.c_str() );
  4538. };
  4539. it = cArr->find("width");
  4540. if( it != cArr->end() ){
  4541. tPtr->width = atoi( it->second.c_str() );
  4542. };
  4543. it = cArr->find("height");
  4544. if( it != cArr->end() ){
  4545. tPtr->height = atoi( it->second.c_str() );
  4546. };
  4547. it = cArr->find("compression_quality");
  4548. if( it != cArr->end() ){
  4549. tPtr->compression_quality = atoi( it->second.c_str() );
  4550. };
  4551. it = cArr->find("show_ts");
  4552. if( it != cArr->end() ){
  4553. tPtr->show_ts = (bool)atoi( it->second.c_str() );
  4554. };
  4555. it = cArr->find("ts_x");
  4556. if( it != cArr->end() ){
  4557. tPtr->ts_x = atoi( it->second.c_str() );
  4558. };
  4559. it = cArr->find("ts_y");
  4560. if( it != cArr->end() ){
  4561. tPtr->ts_y = atoi( it->second.c_str() );
  4562. };
  4563. it = cArr->find("ts_font_face");
  4564. if( it != cArr->end() ){
  4565. tPtr->ts_font_face = atoi( it->second.c_str() );
  4566. };
  4567. it = cArr->find("ts_font_scale");
  4568. if( it != cArr->end() ){
  4569. tPtr->ts_font_scale = atof( it->second.c_str() );
  4570. };
  4571. it = cArr->find("ts_font_thickness");
  4572. if( it != cArr->end() ){
  4573. tPtr->ts_font_thickness = atoi( it->second.c_str() );
  4574. };
  4575. it = cArr->find("ts_line_type");
  4576. if( it != cArr->end() ){
  4577. tPtr->ts_line_type = atoi( it->second.c_str() );
  4578. };
  4579. it = cArr->find("ts_transperant");
  4580. if( it != cArr->end() ){
  4581. tPtr->ts_transperant = (bool)atoi( it->second.c_str() );
  4582. };
  4583. it = cArr->find("show_label");
  4584. if( it != cArr->end() ){
  4585. tPtr->show_label = (bool)atoi( it->second.c_str() );
  4586. };
  4587. it = cArr->find("label_x");
  4588. if( it != cArr->end() ){
  4589. tPtr->label_x = atoi( it->second.c_str() );
  4590. };
  4591. it = cArr->find("label_y");
  4592. if( it != cArr->end() ){
  4593. tPtr->label_y = atoi( it->second.c_str() );
  4594. };
  4595. it = cArr->find("label_font_face");
  4596. if( it != cArr->end() ){
  4597. tPtr->label_font_face = atoi( it->second.c_str() );
  4598. };
  4599. it = cArr->find("label_font_scale");
  4600. if( it != cArr->end() ){
  4601. tPtr->label_font_scale = atof( it->second.c_str() );
  4602. };
  4603. it = cArr->find("label_font_thickness");
  4604. if( it != cArr->end() ){
  4605. tPtr->label_font_thickness = atoi( it->second.c_str() );
  4606. };
  4607. it = cArr->find("label_line_type");
  4608. if( it != cArr->end() ){
  4609. tPtr->label_line_type = atoi( it->second.c_str() );
  4610. };
  4611. it = cArr->find("label_transperant");
  4612. if( it != cArr->end() ){
  4613. tPtr->label_transperant = (bool) atoi( it->second.c_str() );
  4614. };
  4615. it = cArr->find("show_logo");
  4616. if( it != cArr->end() ){
  4617. tPtr->show_logo = (bool) atoi( it->second.c_str() );
  4618. };
  4619. it = cArr->find("logo_w");
  4620. if( it != cArr->end() ){
  4621. tPtr->logo_w = atoi( it->second.c_str() );
  4622. };
  4623. it = cArr->find("logo_h");
  4624. if( it != cArr->end() ){
  4625. tPtr->logo_h = atoi( it->second.c_str() );
  4626. };
  4627. it = cArr->find("logo_x");
  4628. if( it != cArr->end() ){
  4629. tPtr->logo_x = atoi( it->second.c_str() );
  4630. };
  4631. it = cArr->find("logo_y");
  4632. if( it != cArr->end() ){
  4633. tPtr->logo_y = atoi( it->second.c_str() );
  4634. };
  4635. it = cArr->find("logo_md5");
  4636. if( it != cArr->end() ){
  4637. strncpy( tPtr->logo_md5, it->second.c_str(),32);
  4638. tPtr->logo_md5[32]=(char)0;
  4639. };
  4640. };
  4641. };
  4642. };
  4643. deleteResult( result );
  4644. };
  4645. return tPtr;
  4646. };
  4647. DBC_EVT_RECORD *mysqlDBC::getEventByUUID( CSTR UUID ){
  4648. DBC_EVT_RECORD *tPtr = NULL;
  4649. if( m_bIsConnected ) {
  4650. char tQBuf[MAX_PATH_LEN];
  4651. AAssoc *result;
  4652. sprintf( tQBuf, "SELECT * FROM events_cloud WHERE uuid = '%s'", UUID );
  4653. #ifdef DEBUG_ALL
  4654. LOG(tQBuf);
  4655. #endif
  4656. result = m_pDatabase->Query( tQBuf );
  4657. if( result!= NULL ) {
  4658. if( result->size() > 0 ) {
  4659. Assoc *cArr;
  4660. tPtr = (DBC_EVT_RECORD*)malloc(sizeof(DBC_EVT_RECORD));
  4661. if( tPtr!= NULL ) {
  4662. Assoc::iterator it;
  4663. memset(tPtr,0,sizeof(DBC_EVT_RECORD));
  4664. cArr = result->at(0);
  4665. it = cArr->find("id");
  4666. if( it != cArr->end() ){
  4667. tPtr->id = atoi( it->second.c_str() );
  4668. };
  4669. it = cArr->find("node_id");
  4670. if( it != cArr->end() ){
  4671. tPtr->node_id = atoi( it->second.c_str() );
  4672. };
  4673. it = cArr->find("uuid");
  4674. if( it != cArr->end() ){
  4675. strncpy( tPtr->uuid, it->second.c_str(),64 );
  4676. };
  4677. it = cArr->find("ts");
  4678. if( it != cArr->end() ){
  4679. tPtr->ts_s = atoi( it->second.c_str() );
  4680. };
  4681. it = cArr->find("ts_ms");
  4682. if( it != cArr->end() ){
  4683. tPtr->ts_ms = atoi( it->second.c_str() );
  4684. };
  4685. it = cArr->find("evt_type");
  4686. if( it != cArr->end() ){
  4687. tPtr->type = atoi( it->second.c_str() );
  4688. };
  4689. it = cArr->find("range_digital");
  4690. if( it != cArr->end() ){
  4691. tPtr->range_digital = atoi( it->second.c_str() );
  4692. };
  4693. it = cArr->find("azimuth");
  4694. if( it != cArr->end() ){
  4695. tPtr->az = atof( it->second.c_str() );
  4696. };
  4697. it = cArr->find("elevation");
  4698. if( it != cArr->end() ){
  4699. tPtr->el = atof( it->second.c_str() );
  4700. };
  4701. it = cArr->find("range");
  4702. if( it != cArr->end() ){
  4703. tPtr->ra = atof( it->second.c_str() );
  4704. };
  4705. it = cArr->find("area");
  4706. if( it != cArr->end() ){
  4707. tPtr->area = atof( it->second.c_str() );
  4708. };
  4709. it = cArr->find("lat");
  4710. if( it != cArr->end() ){
  4711. tPtr->lat = atof( it->second.c_str() );
  4712. };
  4713. it = cArr->find("lon");
  4714. if( it != cArr->end() ){
  4715. tPtr->lon = atof( it->second.c_str() );
  4716. };
  4717. it = cArr->find("alt");
  4718. if( it != cArr->end() ){
  4719. tPtr->alt = atof( it->second.c_str() );
  4720. };
  4721. it = cArr->find("ref_id");
  4722. if( it != cArr->end() ){
  4723. tPtr->ref_id = atoi( it->second.c_str() );
  4724. };
  4725. it = cArr->find("ref_uuid");
  4726. if( it != cArr->end() ){
  4727. strncpy( tPtr->ref_uuid, it->second.c_str(),64 );
  4728. };
  4729. };
  4730. };
  4731. };
  4732. deleteResult( result );
  4733. };
  4734. return tPtr;
  4735. };
  4736. #undef LOG
  4737. #undef LOG_ERROR