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.

5514 lines
132 KiB

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