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.

4661 lines
176 KiB

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