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.

4818 lines
179 KiB

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