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.

4755 lines
172 KiB

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