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.

2510 lines
61 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
7 months ago
​
​
​
​
​
​
7 months ago
​
​
​
​
​
7 months ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
7 months ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
7 months ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
la_serva: fix memory/descriptor leaks, crashes and a DB-log deadlock Leaks that grew without bound: - Dead module connections were never removed (half-open TCP after a module power loss / network drop): every one kept 3 threads, 8 MB of socket buffers, a descriptor and a 10 ms DB poll. servaRPCHadnler now drops a connection that sends nothing for RPC_IDLE_TIMEOUT_S (60 s; la_mojo sends a status about every second), and accepted sockets get TCP keepalive (30 s idle, 3 probes of 10 s). - The client socket was only closed on an I/O error: a handler removed for any other reason (module disabled / not registered, idle) leaked its descriptor until accept() failed with EMFILE - which ended the accept thread for good. ~serverPort now shuts down and closes it; transient accept() errors (EMFILE, ENFILE, ENOMEM, ECONNABORTED, EINTR, ...) no longer stop the server. recv() == 0 (peer closed) is always a disconnect, whatever errno holds. - servaSessionManager::reopenSession stored the reopened (expired) session in the per-track map, overwriting the track's ACTIVE session: its data and open report.db leaked and it was never closed in MySQL. Reopened sessions are now kept outside the map and released by the caller (addVideo, getSessionBase). - servaVideoComposer leaked its session data, an open SQLite connection and both video queues on every composition; servaKernel leaked a composer whose compose() failed, never initialised / released the automatic composer (it ran at most once) and leaked the media info of every encoded video (processVideoFile success path). Crashes / corruption: - vector erase() with the old iterator reused (netServer client cleanup, encoder / composer pools, 4 ModBus action loops). - transportSocket::_close wrote the stop byte into the read end of the pipe (threads only stopped at the 5 s select timeout, blocking the accept thread on every disconnect) and left closed pipe numbers set (a second _close could write into another connection's socket). - Session map used without the lock from RPC, kernel and ModBus threads: now a recursive mutex held for each public operation. - Freeze on the first MySQL error with DB logging enabled: Query() logs while holding the non-recursive DB mutex and the log service wrote synchronously into the DB (same-thread and two-thread deadlock). The DB log service now queues lines (max 1000) and writes them with MySQL_Connector::TrySilentQuery (never blocks, never logs); reconnect retries per query are bounded (3) instead of looping forever while holding the mutex. The log line parser also skips the UTC offset. - basicMutex::try_lock returned true when the lock was NOT taken: an uncontended try_lock took the mutex and the caller never released it (basicEngine, serial transport, ...). - Kernel restart (web commands): the ModBus singleton was deleted but not reset (next getInstance returned freed memory), the remote client kept the deleted kernel and refused to start again, and EXIT_CODE_RELOAD_SERVICES deleted the DB object every surviving component still used. Now fixed / the DB object is kept. - Life monitoring overflowed module_id[4] for platforms with > 4 modules; registerServA overflowed a 120-byte stack buffer, closed a popen() stream with fclose and leaked the config; 9 config strings in servaBackend were allocated one byte short; video chunk length is now checked against the packet; "eased" events copied every field from itself (all 0); networkServer freed libconfig's host string. Minor: ModBus action list / sessions freed at shutdown, session-start event payload freed if the event cannot be created, the per-second "No History Auto Delete!" log line moved to DEBUG_EXTRA. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0139veDo3XyavMuVhdnHcN16
44 minutes ago
​
​
la_serva: fix memory/descriptor leaks, crashes and a DB-log deadlock Leaks that grew without bound: - Dead module connections were never removed (half-open TCP after a module power loss / network drop): every one kept 3 threads, 8 MB of socket buffers, a descriptor and a 10 ms DB poll. servaRPCHadnler now drops a connection that sends nothing for RPC_IDLE_TIMEOUT_S (60 s; la_mojo sends a status about every second), and accepted sockets get TCP keepalive (30 s idle, 3 probes of 10 s). - The client socket was only closed on an I/O error: a handler removed for any other reason (module disabled / not registered, idle) leaked its descriptor until accept() failed with EMFILE - which ended the accept thread for good. ~serverPort now shuts down and closes it; transient accept() errors (EMFILE, ENFILE, ENOMEM, ECONNABORTED, EINTR, ...) no longer stop the server. recv() == 0 (peer closed) is always a disconnect, whatever errno holds. - servaSessionManager::reopenSession stored the reopened (expired) session in the per-track map, overwriting the track's ACTIVE session: its data and open report.db leaked and it was never closed in MySQL. Reopened sessions are now kept outside the map and released by the caller (addVideo, getSessionBase). - servaVideoComposer leaked its session data, an open SQLite connection and both video queues on every composition; servaKernel leaked a composer whose compose() failed, never initialised / released the automatic composer (it ran at most once) and leaked the media info of every encoded video (processVideoFile success path). Crashes / corruption: - vector erase() with the old iterator reused (netServer client cleanup, encoder / composer pools, 4 ModBus action loops). - transportSocket::_close wrote the stop byte into the read end of the pipe (threads only stopped at the 5 s select timeout, blocking the accept thread on every disconnect) and left closed pipe numbers set (a second _close could write into another connection's socket). - Session map used without the lock from RPC, kernel and ModBus threads: now a recursive mutex held for each public operation. - Freeze on the first MySQL error with DB logging enabled: Query() logs while holding the non-recursive DB mutex and the log service wrote synchronously into the DB (same-thread and two-thread deadlock). The DB log service now queues lines (max 1000) and writes them with MySQL_Connector::TrySilentQuery (never blocks, never logs); reconnect retries per query are bounded (3) instead of looping forever while holding the mutex. The log line parser also skips the UTC offset. - basicMutex::try_lock returned true when the lock was NOT taken: an uncontended try_lock took the mutex and the caller never released it (basicEngine, serial transport, ...). - Kernel restart (web commands): the ModBus singleton was deleted but not reset (next getInstance returned freed memory), the remote client kept the deleted kernel and refused to start again, and EXIT_CODE_RELOAD_SERVICES deleted the DB object every surviving component still used. Now fixed / the DB object is kept. - Life monitoring overflowed module_id[4] for platforms with > 4 modules; registerServA overflowed a 120-byte stack buffer, closed a popen() stream with fclose and leaked the config; 9 config strings in servaBackend were allocated one byte short; video chunk length is now checked against the packet; "eased" events copied every field from itself (all 0); networkServer freed libconfig's host string. Minor: ModBus action list / sessions freed at shutdown, session-start event payload freed if the event cannot be created, the per-second "No History Auto Delete!" log line moved to DEBUG_EXTRA. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0139veDo3XyavMuVhdnHcN16
44 minutes ago
​
la_serva: fix memory/descriptor leaks, crashes and a DB-log deadlock Leaks that grew without bound: - Dead module connections were never removed (half-open TCP after a module power loss / network drop): every one kept 3 threads, 8 MB of socket buffers, a descriptor and a 10 ms DB poll. servaRPCHadnler now drops a connection that sends nothing for RPC_IDLE_TIMEOUT_S (60 s; la_mojo sends a status about every second), and accepted sockets get TCP keepalive (30 s idle, 3 probes of 10 s). - The client socket was only closed on an I/O error: a handler removed for any other reason (module disabled / not registered, idle) leaked its descriptor until accept() failed with EMFILE - which ended the accept thread for good. ~serverPort now shuts down and closes it; transient accept() errors (EMFILE, ENFILE, ENOMEM, ECONNABORTED, EINTR, ...) no longer stop the server. recv() == 0 (peer closed) is always a disconnect, whatever errno holds. - servaSessionManager::reopenSession stored the reopened (expired) session in the per-track map, overwriting the track's ACTIVE session: its data and open report.db leaked and it was never closed in MySQL. Reopened sessions are now kept outside the map and released by the caller (addVideo, getSessionBase). - servaVideoComposer leaked its session data, an open SQLite connection and both video queues on every composition; servaKernel leaked a composer whose compose() failed, never initialised / released the automatic composer (it ran at most once) and leaked the media info of every encoded video (processVideoFile success path). Crashes / corruption: - vector erase() with the old iterator reused (netServer client cleanup, encoder / composer pools, 4 ModBus action loops). - transportSocket::_close wrote the stop byte into the read end of the pipe (threads only stopped at the 5 s select timeout, blocking the accept thread on every disconnect) and left closed pipe numbers set (a second _close could write into another connection's socket). - Session map used without the lock from RPC, kernel and ModBus threads: now a recursive mutex held for each public operation. - Freeze on the first MySQL error with DB logging enabled: Query() logs while holding the non-recursive DB mutex and the log service wrote synchronously into the DB (same-thread and two-thread deadlock). The DB log service now queues lines (max 1000) and writes them with MySQL_Connector::TrySilentQuery (never blocks, never logs); reconnect retries per query are bounded (3) instead of looping forever while holding the mutex. The log line parser also skips the UTC offset. - basicMutex::try_lock returned true when the lock was NOT taken: an uncontended try_lock took the mutex and the caller never released it (basicEngine, serial transport, ...). - Kernel restart (web commands): the ModBus singleton was deleted but not reset (next getInstance returned freed memory), the remote client kept the deleted kernel and refused to start again, and EXIT_CODE_RELOAD_SERVICES deleted the DB object every surviving component still used. Now fixed / the DB object is kept. - Life monitoring overflowed module_id[4] for platforms with > 4 modules; registerServA overflowed a 120-byte stack buffer, closed a popen() stream with fclose and leaked the config; 9 config strings in servaBackend were allocated one byte short; video chunk length is now checked against the packet; "eased" events copied every field from itself (all 0); networkServer freed libconfig's host string. Minor: ModBus action list / sessions freed at shutdown, session-start event payload freed if the event cannot be created, the per-second "No History Auto Delete!" log line moved to DEBUG_EXTRA. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0139veDo3XyavMuVhdnHcN16
44 minutes ago
​
la_serva: fix memory/descriptor leaks, crashes and a DB-log deadlock Leaks that grew without bound: - Dead module connections were never removed (half-open TCP after a module power loss / network drop): every one kept 3 threads, 8 MB of socket buffers, a descriptor and a 10 ms DB poll. servaRPCHadnler now drops a connection that sends nothing for RPC_IDLE_TIMEOUT_S (60 s; la_mojo sends a status about every second), and accepted sockets get TCP keepalive (30 s idle, 3 probes of 10 s). - The client socket was only closed on an I/O error: a handler removed for any other reason (module disabled / not registered, idle) leaked its descriptor until accept() failed with EMFILE - which ended the accept thread for good. ~serverPort now shuts down and closes it; transient accept() errors (EMFILE, ENFILE, ENOMEM, ECONNABORTED, EINTR, ...) no longer stop the server. recv() == 0 (peer closed) is always a disconnect, whatever errno holds. - servaSessionManager::reopenSession stored the reopened (expired) session in the per-track map, overwriting the track's ACTIVE session: its data and open report.db leaked and it was never closed in MySQL. Reopened sessions are now kept outside the map and released by the caller (addVideo, getSessionBase). - servaVideoComposer leaked its session data, an open SQLite connection and both video queues on every composition; servaKernel leaked a composer whose compose() failed, never initialised / released the automatic composer (it ran at most once) and leaked the media info of every encoded video (processVideoFile success path). Crashes / corruption: - vector erase() with the old iterator reused (netServer client cleanup, encoder / composer pools, 4 ModBus action loops). - transportSocket::_close wrote the stop byte into the read end of the pipe (threads only stopped at the 5 s select timeout, blocking the accept thread on every disconnect) and left closed pipe numbers set (a second _close could write into another connection's socket). - Session map used without the lock from RPC, kernel and ModBus threads: now a recursive mutex held for each public operation. - Freeze on the first MySQL error with DB logging enabled: Query() logs while holding the non-recursive DB mutex and the log service wrote synchronously into the DB (same-thread and two-thread deadlock). The DB log service now queues lines (max 1000) and writes them with MySQL_Connector::TrySilentQuery (never blocks, never logs); reconnect retries per query are bounded (3) instead of looping forever while holding the mutex. The log line parser also skips the UTC offset. - basicMutex::try_lock returned true when the lock was NOT taken: an uncontended try_lock took the mutex and the caller never released it (basicEngine, serial transport, ...). - Kernel restart (web commands): the ModBus singleton was deleted but not reset (next getInstance returned freed memory), the remote client kept the deleted kernel and refused to start again, and EXIT_CODE_RELOAD_SERVICES deleted the DB object every surviving component still used. Now fixed / the DB object is kept. - Life monitoring overflowed module_id[4] for platforms with > 4 modules; registerServA overflowed a 120-byte stack buffer, closed a popen() stream with fclose and leaked the config; 9 config strings in servaBackend were allocated one byte short; video chunk length is now checked against the packet; "eased" events copied every field from itself (all 0); networkServer freed libconfig's host string. Minor: ModBus action list / sessions freed at shutdown, session-start event payload freed if the event cannot be created, the per-second "No History Auto Delete!" log line moved to DEBUG_EXTRA. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0139veDo3XyavMuVhdnHcN16
44 minutes ago
​
​
​
​
​
​
la_serva: fix memory/descriptor leaks, crashes and a DB-log deadlock Leaks that grew without bound: - Dead module connections were never removed (half-open TCP after a module power loss / network drop): every one kept 3 threads, 8 MB of socket buffers, a descriptor and a 10 ms DB poll. servaRPCHadnler now drops a connection that sends nothing for RPC_IDLE_TIMEOUT_S (60 s; la_mojo sends a status about every second), and accepted sockets get TCP keepalive (30 s idle, 3 probes of 10 s). - The client socket was only closed on an I/O error: a handler removed for any other reason (module disabled / not registered, idle) leaked its descriptor until accept() failed with EMFILE - which ended the accept thread for good. ~serverPort now shuts down and closes it; transient accept() errors (EMFILE, ENFILE, ENOMEM, ECONNABORTED, EINTR, ...) no longer stop the server. recv() == 0 (peer closed) is always a disconnect, whatever errno holds. - servaSessionManager::reopenSession stored the reopened (expired) session in the per-track map, overwriting the track's ACTIVE session: its data and open report.db leaked and it was never closed in MySQL. Reopened sessions are now kept outside the map and released by the caller (addVideo, getSessionBase). - servaVideoComposer leaked its session data, an open SQLite connection and both video queues on every composition; servaKernel leaked a composer whose compose() failed, never initialised / released the automatic composer (it ran at most once) and leaked the media info of every encoded video (processVideoFile success path). Crashes / corruption: - vector erase() with the old iterator reused (netServer client cleanup, encoder / composer pools, 4 ModBus action loops). - transportSocket::_close wrote the stop byte into the read end of the pipe (threads only stopped at the 5 s select timeout, blocking the accept thread on every disconnect) and left closed pipe numbers set (a second _close could write into another connection's socket). - Session map used without the lock from RPC, kernel and ModBus threads: now a recursive mutex held for each public operation. - Freeze on the first MySQL error with DB logging enabled: Query() logs while holding the non-recursive DB mutex and the log service wrote synchronously into the DB (same-thread and two-thread deadlock). The DB log service now queues lines (max 1000) and writes them with MySQL_Connector::TrySilentQuery (never blocks, never logs); reconnect retries per query are bounded (3) instead of looping forever while holding the mutex. The log line parser also skips the UTC offset. - basicMutex::try_lock returned true when the lock was NOT taken: an uncontended try_lock took the mutex and the caller never released it (basicEngine, serial transport, ...). - Kernel restart (web commands): the ModBus singleton was deleted but not reset (next getInstance returned freed memory), the remote client kept the deleted kernel and refused to start again, and EXIT_CODE_RELOAD_SERVICES deleted the DB object every surviving component still used. Now fixed / the DB object is kept. - Life monitoring overflowed module_id[4] for platforms with > 4 modules; registerServA overflowed a 120-byte stack buffer, closed a popen() stream with fclose and leaked the config; 9 config strings in servaBackend were allocated one byte short; video chunk length is now checked against the packet; "eased" events copied every field from itself (all 0); networkServer freed libconfig's host string. Minor: ModBus action list / sessions freed at shutdown, session-start event payload freed if the event cannot be created, the per-second "No History Auto Delete!" log line moved to DEBUG_EXTRA. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0139veDo3XyavMuVhdnHcN16
44 minutes ago
​
​
​
​
​
​
​
​
la_serva: fix memory/descriptor leaks, crashes and a DB-log deadlock Leaks that grew without bound: - Dead module connections were never removed (half-open TCP after a module power loss / network drop): every one kept 3 threads, 8 MB of socket buffers, a descriptor and a 10 ms DB poll. servaRPCHadnler now drops a connection that sends nothing for RPC_IDLE_TIMEOUT_S (60 s; la_mojo sends a status about every second), and accepted sockets get TCP keepalive (30 s idle, 3 probes of 10 s). - The client socket was only closed on an I/O error: a handler removed for any other reason (module disabled / not registered, idle) leaked its descriptor until accept() failed with EMFILE - which ended the accept thread for good. ~serverPort now shuts down and closes it; transient accept() errors (EMFILE, ENFILE, ENOMEM, ECONNABORTED, EINTR, ...) no longer stop the server. recv() == 0 (peer closed) is always a disconnect, whatever errno holds. - servaSessionManager::reopenSession stored the reopened (expired) session in the per-track map, overwriting the track's ACTIVE session: its data and open report.db leaked and it was never closed in MySQL. Reopened sessions are now kept outside the map and released by the caller (addVideo, getSessionBase). - servaVideoComposer leaked its session data, an open SQLite connection and both video queues on every composition; servaKernel leaked a composer whose compose() failed, never initialised / released the automatic composer (it ran at most once) and leaked the media info of every encoded video (processVideoFile success path). Crashes / corruption: - vector erase() with the old iterator reused (netServer client cleanup, encoder / composer pools, 4 ModBus action loops). - transportSocket::_close wrote the stop byte into the read end of the pipe (threads only stopped at the 5 s select timeout, blocking the accept thread on every disconnect) and left closed pipe numbers set (a second _close could write into another connection's socket). - Session map used without the lock from RPC, kernel and ModBus threads: now a recursive mutex held for each public operation. - Freeze on the first MySQL error with DB logging enabled: Query() logs while holding the non-recursive DB mutex and the log service wrote synchronously into the DB (same-thread and two-thread deadlock). The DB log service now queues lines (max 1000) and writes them with MySQL_Connector::TrySilentQuery (never blocks, never logs); reconnect retries per query are bounded (3) instead of looping forever while holding the mutex. The log line parser also skips the UTC offset. - basicMutex::try_lock returned true when the lock was NOT taken: an uncontended try_lock took the mutex and the caller never released it (basicEngine, serial transport, ...). - Kernel restart (web commands): the ModBus singleton was deleted but not reset (next getInstance returned freed memory), the remote client kept the deleted kernel and refused to start again, and EXIT_CODE_RELOAD_SERVICES deleted the DB object every surviving component still used. Now fixed / the DB object is kept. - Life monitoring overflowed module_id[4] for platforms with > 4 modules; registerServA overflowed a 120-byte stack buffer, closed a popen() stream with fclose and leaked the config; 9 config strings in servaBackend were allocated one byte short; video chunk length is now checked against the packet; "eased" events copied every field from itself (all 0); networkServer freed libconfig's host string. Minor: ModBus action list / sessions freed at shutdown, session-start event payload freed if the event cannot be created, the per-second "No History Auto Delete!" log line moved to DEBUG_EXTRA. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0139veDo3XyavMuVhdnHcN16
44 minutes ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. #include "serverMySQL_dataBinder.h"
  2. #define LOG(X) m_pLog->Log("MDBC", this, X)
  3. #ifdef DEBUG
  4. #define LOG_ERROR(X) \
  5. { \
  6. char _tBfrErrMSG2w34[256]; \
  7. sprintf(_tBfrErrMSG2w34, "In file %s[%d] in func:%s %s", __FILE__, __LINE__, __func__, X); \
  8. m_pLog->Log("MDBC", this, _LOG_ERROR, _tBfrErrMSG2w34); \
  9. }
  10. #else
  11. #define LOG_ERROR(X) m_pLog->Log("MDBC", this, _LOG_ERROR, X);
  12. #endif
  13. servaMySQLDBC * servaMySQLDBC::_instance = NULL;
  14. /**
  15. * Returns the single instance of the object.
  16. */
  17. servaMySQLDBC * servaMySQLDBC::getInstance(config_setting_t * Settings)
  18. {
  19. // check if the instance has been created yet
  20. if (0 == _instance)
  21. {
  22. // if not, then create it
  23. _instance = new servaMySQLDBC(Settings);
  24. };
  25. // return the single instance
  26. return _instance;
  27. }
  28. servaMySQLDBC::servaMySQLDBC(config_setting_t * Settings) :
  29. serverDataBinder()
  30. {
  31. m_pLog = basicLogCollection::getInstance();
  32. m_pSettings = basicSettingsProvider::getInstance()->getSubNode(Settings, "DBC");
  33. m_bIsConnected = false;
  34. m_pDatabase = NULL;
  35. }
  36. servaMySQLDBC::~servaMySQLDBC()
  37. {
  38. m_bIsConnected = false;
  39. if (m_pDatabase != NULL)
  40. {
  41. delete(m_pDatabase);
  42. }
  43. m_pDatabase = NULL;
  44. _instance = NULL;
  45. }
  46. uint64_t servaMySQLDBC::addMediaComposerItem( uint64_t session_id, CSTR uuid ){
  47. uint64_t RetVal = 0;
  48. if (m_bIsConnected)
  49. {
  50. char tQBuf[4096];
  51. sprintf(tQBuf, "INSERT INTO `media_composer_queue` SET `session_id`=%" PRIu64 ", `ts`=UNIX_TIMESTAMP(NOW()), `uuid`='%s', `status`='L', `process`=0", session_id, uuid );
  52. #ifdef DEBUG
  53. LOG(tQBuf);
  54. #endif
  55. RetVal = m_pDatabase->QueryID(tQBuf);
  56. };
  57. return RetVal;
  58. }
  59. uint64_t servaMySQLDBC::addMediaQueueRecord(CSTR uuid, uint64_t module_id, uint64_t session_id, uint32_t ts, uint16_t tsms, uint16_t width, uint16_t height, uint8_t fps, CSTR fmt)
  60. {
  61. uint64_t RetVal = 0;
  62. if (m_bIsConnected)
  63. {
  64. char tQBuf[4096];
  65. sprintf(tQBuf, "INSERT INTO `media_encoder_queue` SET `module_id`=%" PRIu64 ", `session_id`=%" PRIu64 ", `ts`=%d, `tsms`=%d, `uuid`='%s', `width`=%d, `height`=%d, `fps`=%d, `fmt`='%s', `status`=0, `process`=0", module_id, session_id, ts, tsms, uuid,
  66. width, height, fps, fmt);
  67. #ifdef DEBUG_ALL
  68. LOG(tQBuf);
  69. #endif
  70. RetVal = m_pDatabase->QueryID(tQBuf);
  71. };
  72. return RetVal;
  73. }
  74. bool servaMySQLDBC::addScadaPost( uint64_t platform_id, SERVER_SCADA_POST_TYPE mtyp, uint64_t src, uint8_t status ){
  75. if (m_bIsConnected){
  76. char tQBuf[4096];
  77. sprintf( tQBuf, "INSERT INTO `metro_platforms_mboxes` SET `platform_id`=%" PRIu64 ", `src`=%" PRIu64 ", `type`=%d, `ts`=UNIX_TIMESTAMP(), `status`=%d ON DUPLICATE KEY UPDATE id=id",
  78. platform_id, src, mtyp, status );
  79. #ifdef DEBUG_ALL
  80. LOG(tQBuf);
  81. #endif
  82. m_pDatabase->SilentQuery(tQBuf);
  83. return true;
  84. };
  85. return false;
  86. }
  87. bool servaMySQLDBC::connect(void)
  88. {
  89. config_setting_t * tSetting;
  90. m_bIsConnected = false;
  91. if (m_pSettings != NULL)
  92. {
  93. tSetting = config_setting_get_member(m_pSettings, "DATABASE_HOST");
  94. if (tSetting == NULL)
  95. {
  96. tSetting = config_setting_add(m_pSettings, "DATABASE_HOST", CONFIG_TYPE_STRING);
  97. config_setting_set_string(tSetting, "localhost");
  98. basicSettingsProvider::getInstance()->compromise();
  99. LOG("No DB Host Setting! Using default!");
  100. };
  101. sprintf(m_pDbHost, "%s", config_setting_get_string(tSetting));
  102. tSetting = config_setting_get_member(m_pSettings, "DATABASE_NAME");
  103. if (tSetting == NULL)
  104. {
  105. tSetting = config_setting_add(m_pSettings, "DATABASE_NAME", CONFIG_TYPE_STRING);
  106. config_setting_set_string(tSetting, "dfsl_gunter");
  107. basicSettingsProvider::getInstance()->compromise();
  108. LOG("No DB Database Setting! Using default!");
  109. };
  110. sprintf(m_pDbDatabase, "%s", config_setting_get_string(tSetting));
  111. tSetting = config_setting_get_member(m_pSettings, "DATABASE_USER");
  112. if (tSetting == NULL)
  113. {
  114. tSetting = config_setting_add(m_pSettings, "DATABASE_USER", CONFIG_TYPE_STRING);
  115. config_setting_set_string(tSetting, "dbroot");
  116. basicSettingsProvider::getInstance()->compromise();
  117. LOG("No DB User Setting! Using default!");
  118. };
  119. sprintf(m_pDbUsername, "%s", config_setting_get_string(tSetting));
  120. tSetting = config_setting_get_member(m_pSettings, "DATABASE_PASSWORD");
  121. if (tSetting == NULL)
  122. {
  123. tSetting = config_setting_add(m_pSettings, "DATABASE_PASSWORD", CONFIG_TYPE_STRING);
  124. config_setting_set_string(tSetting, "123567");
  125. basicSettingsProvider::getInstance()->compromise();
  126. LOG("No DB Password Setting! Using default!");
  127. };
  128. sprintf(m_pDbPassword, "%s", config_setting_get_string(tSetting));
  129. basicSettingsProvider::getInstance()->validate();
  130. m_pDatabase = new MySQL_Connector();
  131. if (m_pDatabase == NULL)
  132. {
  133. return false;
  134. }
  135. m_bIsConnected = m_pDatabase->Connect(m_pDbDatabase, m_pDbHost, m_pDbUsername, m_pDbPassword);
  136. }
  137. else
  138. {
  139. LOG_ERROR("No Settings Provided!");
  140. };
  141. return m_bIsConnected;
  142. }
  143. bool servaMySQLDBC::checkMediaComposerItem( uint64_t session_id ){
  144. bool retVal = false;
  145. if (m_bIsConnected)
  146. {
  147. char tQBuf[MAX_PATH_LEN];
  148. AAssoc * result;
  149. sprintf(tQBuf, "SELECT `id` FROM `media_composer_queue` WHERE `session_id`=%" PRIu64, session_id );
  150. #ifdef DEBUG_ALL
  151. LOG(tQBuf);
  152. #endif
  153. result = m_pDatabase->Query(tQBuf);
  154. if (result != NULL)
  155. {
  156. if (result->size() > 0) retVal = true;
  157. };
  158. deleteResult(result);
  159. };
  160. return retVal;
  161. }
  162. bool servaMySQLDBC::closeAllOnGoingSessions()
  163. {
  164. if (m_bIsConnected)
  165. {
  166. char tQBuf[MAX_PATH_LEN];
  167. sprintf(tQBuf, "UPDATE `sessions` SET `final`='Y' WHERE `final`='N'");
  168. #ifdef DEBUG_ALL
  169. LOG(tQBuf);
  170. #endif
  171. m_pDatabase->SilentQuery(tQBuf);
  172. return true;
  173. };
  174. return false;
  175. }
  176. bool servaMySQLDBC::cleanWebCmd()
  177. {
  178. if (m_bIsConnected)
  179. {
  180. char tQBuf[MAX_PATH_LEN];
  181. sprintf(tQBuf, "DELETE FROM `mem_web_queue` WHERE `status`>100");
  182. #ifdef DEBUG_ALL
  183. LOG(tQBuf);
  184. #endif
  185. m_pDatabase->SilentQuery(tQBuf);
  186. };
  187. return true;
  188. }
  189. bool servaMySQLDBC::deleteScadaPost( uint64_t post_id ){
  190. if (m_bIsConnected){
  191. char tQBuf[MAX_PATH_LEN];
  192. sprintf(tQBuf, "DELETE FROM `metro_platforms_mboxes` WHERE `id`=%" PRIu64, post_id );
  193. #ifdef DEBUG_ALL
  194. LOG(tQBuf);
  195. #endif
  196. m_pDatabase->SilentQuery(tQBuf);
  197. };
  198. }
  199. bool servaMySQLDBC::deleteScadaPost( uint64_t platform_id, SERVER_SCADA_POST_TYPE mtyp, uint64_t src ){
  200. if (m_bIsConnected){
  201. char tQBuf[MAX_PATH_LEN];
  202. sprintf(tQBuf, "DELETE FROM `metro_platforms_mboxes` WHERE `platform_id`=%" PRIu64 " AND `src`=%" PRIu64 " AND `type`=%d", platform_id, src, mtyp );
  203. #ifdef DEBUG_ALL
  204. LOG(tQBuf);
  205. #endif
  206. m_pDatabase->SilentQuery(tQBuf);
  207. };
  208. return true;
  209. }
  210. bool servaMySQLDBC::deleteScadaPostsAbowe( uint64_t platform_id, SERVER_SCADA_POST_TYPE mtyp, uint64_t src ){
  211. if (m_bIsConnected){
  212. char tQBuf[MAX_PATH_LEN];
  213. // type < 6 - to delete only Health statuses - not the TCC one
  214. if ( src ) {
  215. sprintf(tQBuf, "DELETE FROM `metro_platforms_mboxes` WHERE `platform_id`=%" PRIu64 " AND `type`>%d AND `type`<6 AND `src`=%" PRIu64, platform_id, mtyp, src );
  216. } else {
  217. sprintf(tQBuf, "DELETE FROM `metro_platforms_mboxes` WHERE `platform_id`=%" PRIu64 " AND `type`>%d AND `type`<6", platform_id, mtyp );
  218. };
  219. #ifdef DEBUG
  220. LOG(tQBuf);
  221. #endif
  222. m_pDatabase->SilentQuery(tQBuf);
  223. };
  224. return true;
  225. }
  226. bool servaMySQLDBC::deleteSession(uint64_t id){
  227. if (m_bIsConnected){
  228. char tQBuf[MAX_PATH_LEN];
  229. sprintf(tQBuf, "DELETE FROM `sessions` WHERE `id`=%" PRIu64, id);
  230. #ifdef DEBUG_ALL
  231. LOG(tQBuf);
  232. #endif
  233. m_pDatabase->SilentQuery(tQBuf);
  234. };
  235. return true;
  236. }
  237. DBC_SERVA_MEDIA_ENCODER_SETTINGS * servaMySQLDBC::getMediaEncoderSettings()
  238. {
  239. DBC_SERVA_MEDIA_ENCODER_SETTINGS * RetVal = NULL;
  240. if (m_bIsConnected)
  241. {
  242. char tQBuf[MAX_PATH_LEN];
  243. AAssoc * result;
  244. sprintf(tQBuf, "SELECT * FROM `system_props` WHERE `id`=1");
  245. #ifdef DEBUG_ALL
  246. LOG(tQBuf);
  247. #endif
  248. result = m_pDatabase->Query(tQBuf);
  249. if (result != NULL)
  250. {
  251. if (result->size() > 0)
  252. {
  253. Assoc * cArr;
  254. Assoc::iterator it;
  255. RetVal = (DBC_SERVA_MEDIA_ENCODER_SETTINGS *) malloc(sizeof(DBC_SERVA_MEDIA_ENCODER_SETTINGS));
  256. if (RetVal)
  257. {
  258. memset(RetVal, 0, sizeof(DBC_SERVA_MEDIA_ENCODER_SETTINGS));
  259. RetVal->CRF = 28;//20;
  260. strncpy( RetVal->preset, "slow", 15 );
  261. strncpy( RetVal->tune, "fastdecode", 15 );
  262. strncpy( RetVal->profile, "main", 15 );
  263. //RetVal->TH_MODE = FF_THREAD_FRAME;
  264. RetVal->bitrate = 666;
  265. strncpy( RetVal->CONTAINER, "mp4", 4 );
  266. strncpy( RetVal->CODEC, "h264", 4 );
  267. cArr = result->at(0);
  268. it = cArr->find("media_fmt");
  269. if (it != cArr->end())
  270. {
  271. strncpy(RetVal->CODEC, it->second.c_str(), 4);
  272. RetVal->CODEC[4] = (char) 0;
  273. };
  274. it = cArr->find("media_pck");
  275. if (it != cArr->end())
  276. {
  277. strncpy(RetVal->CONTAINER, it->second.c_str(), 4);
  278. RetVal->CONTAINER[4] = (char) 0;
  279. };
  280. it = cArr->find("media_brate");
  281. if (it != cArr->end())
  282. {
  283. RetVal->bitrate = atoi(it->second.c_str());
  284. };
  285. //it = cArr->find("media_special");
  286. //if (it != cArr->end())
  287. //{
  288. // RetVal->historyPreserveFreeSpaceMB = atoi(it->second.c_str());
  289. //};
  290. };
  291. };
  292. };
  293. deleteResult(result);
  294. };
  295. return RetVal;
  296. }
  297. DBC_SERVA_MEDIA_COMPOSER_RECORD *servaMySQLDBC::getComposerRequestNew(void){
  298. return NULL;
  299. }
  300. DBC_SERVA_MEDIA_COMPOSER_RECORD *servaMySQLDBC::getComposerRecordExpired( uint32_t exp_interval_sec ){
  301. return NULL;
  302. }
  303. CSTR servaMySQLDBC::getMediaUUID(uint64_t id)
  304. {
  305. CSTR RetVal = NULL;
  306. if (m_bIsConnected)
  307. {
  308. char tQBuf[MAX_PATH_LEN];
  309. AAssoc * result;
  310. sprintf(tQBuf, "SELECT `uuid` FROM `media_encoder_queue` WHERE `id`=%" PRIu64, id);
  311. #ifdef DEBUG_ALL
  312. LOG(tQBuf);
  313. #endif
  314. result = m_pDatabase->Query(tQBuf);
  315. if (result != NULL)
  316. {
  317. if (result->size() > 0)
  318. {
  319. Assoc * cArr;
  320. Assoc::iterator it;
  321. cArr = result->at(0);
  322. it = cArr->find("uuid");
  323. if (it != cArr->end())
  324. {
  325. RetVal = strdup(it->second.c_str());
  326. };
  327. };
  328. };
  329. deleteResult(result);
  330. };
  331. return RetVal;
  332. }
  333. MODBUS_MANAGER_DATA * servaMySQLDBC::getModBusManagerData(){
  334. MODBUS_MANAGER_DATA * RetVal = NULL;
  335. if (m_bIsConnected){
  336. char tQBuf[MAX_PATH_LEN];
  337. sprintf(tQBuf, "SELECT `modbus_auto_rise`,`modbus_health_level`,`modbus_hazard_level`,`modbus_auto_supress` FROM `system_props` WHERE `id`=1");
  338. #ifdef DEBUG_ALL
  339. LOG(tQBuf);
  340. #endif
  341. AAssoc * result;
  342. result = m_pDatabase->Query(tQBuf);
  343. if (result != NULL){
  344. if (result->size() > 0){
  345. RetVal = (MODBUS_MANAGER_DATA *) malloc(sizeof(MODBUS_MANAGER_DATA));
  346. if (RetVal){
  347. memset(RetVal, 0, sizeof(MODBUS_MANAGER_DATA));
  348. Assoc * cArr;
  349. Assoc::iterator it;
  350. cArr = result->at(0);
  351. it = cArr->find("modbus_auto_rise");
  352. if (it != cArr->end()){
  353. RetVal->automaticAlarmRisingTO = atoi(it->second.c_str());
  354. };
  355. it = cArr->find("modbus_health_level");
  356. if (it != cArr->end()){
  357. RetVal->helthSignalLevel = atoi(it->second.c_str());
  358. };
  359. it = cArr->find("modbus_hazard_level");
  360. if (it != cArr->end()){
  361. RetVal->hazardSignalLevel = atoi(it->second.c_str());
  362. };
  363. it = cArr->find("modbus_auto_supress");
  364. if (it != cArr->end()){
  365. RetVal->supressSignalBySessionEnd = (bool) atoi(it->second.c_str());
  366. };
  367. };
  368. };
  369. deleteResult(result);
  370. };
  371. };
  372. return RetVal;
  373. }
  374. MODBUS_RTU_INFO * servaMySQLDBC::getModBusRTU(uint64_t id)
  375. {
  376. MODBUS_RTU_INFO * RetVal = NULL;
  377. if (m_bIsConnected)
  378. {
  379. char tQBuf[MAX_PATH_LEN];
  380. AAssoc * result;
  381. sprintf(tQBuf, "SELECT * FROM `modbus_modules` WHERE `id`=%" PRIu64, id);
  382. #ifdef DEBUG_ALL
  383. LOG(tQBuf);
  384. #endif
  385. result = m_pDatabase->Query(tQBuf);
  386. if (result != NULL)
  387. {
  388. if (result->size() > 0)
  389. {
  390. RetVal = (MODBUS_RTU_INFO *) malloc(sizeof(MODBUS_RTU_INFO));
  391. if (RetVal)
  392. {
  393. memset(RetVal, 0, sizeof(MODBUS_RTU_INFO));
  394. RetVal->id = id;
  395. RetVal->input_base_addr = 0x00;
  396. RetVal->output_base_addr = 0x10;
  397. Assoc * cArr;
  398. Assoc::iterator it;
  399. cArr = result->at(0);
  400. it = cArr->find("platform_id");
  401. if (it != cArr->end())
  402. {
  403. RetVal->platform_id = atoll(it->second.c_str());
  404. };
  405. it = cArr->find("ip4");
  406. if (it != cArr->end())
  407. {
  408. strncpy(RetVal->ip, it->second.c_str(), 15);
  409. RetVal->ip[15] = (char) 0;
  410. };
  411. it = cArr->find("port");
  412. if (it != cArr->end())
  413. {
  414. RetVal->port = atoi(it->second.c_str());
  415. };
  416. it = cArr->find("status");
  417. if (it != cArr->end())
  418. {
  419. RetVal->status = atoi(it->second.c_str());
  420. };
  421. it = cArr->find("values");
  422. if (it != cArr->end())
  423. {
  424. uint16_t bb = atoi(it->second.c_str()) & 0xFFFF;
  425. RetVal->c_OutBits = bb & 0xFF;
  426. RetVal->c_InBits = ( bb >> 8 ) & 0xFF;
  427. };
  428. it = cArr->find("crossbar_a");
  429. if (it != cArr->end())
  430. {
  431. uint8_t bb = atoi(it->second.c_str()) & 0xFF;
  432. RetVal->crossbar[0] = bb & 0x0F;
  433. RetVal->crossbar[4] = ( bb & 0xF0 ) >> 4;
  434. };
  435. it = cArr->find("crossbar_b");
  436. if (it != cArr->end())
  437. {
  438. uint8_t bb = atoi(it->second.c_str()) & 0xFF;
  439. RetVal->crossbar[1] = bb & 0x0F;
  440. RetVal->crossbar[5] = ( bb & 0xF0 ) >> 4;
  441. };
  442. it = cArr->find("crossbar_c");
  443. if (it != cArr->end())
  444. {
  445. uint8_t bb = atoi(it->second.c_str()) & 0xFF;
  446. RetVal->crossbar[2] = bb & 0x0F;
  447. RetVal->crossbar[6] = ( bb & 0xF0 ) >> 4;
  448. };
  449. it = cArr->find("crossbar_d");
  450. if (it != cArr->end())
  451. {
  452. uint8_t bb = atoi(it->second.c_str()) & 0xFF;
  453. RetVal->crossbar[3] = bb & 0x0F;
  454. RetVal->crossbar[7] = ( bb & 0xF0 ) >> 4;
  455. };
  456. it = cArr->find("func");
  457. if (it != cArr->end())
  458. {
  459. RetVal->func= atoi(it->second.c_str());
  460. };
  461. };
  462. };
  463. deleteResult(result);
  464. };
  465. };
  466. return RetVal;
  467. }
  468. DBC_IS_MODULE_DATA * servaMySQLDBC::getModuleData(uint64_t id)
  469. {
  470. DBC_IS_MODULE_DATA * RetVal = NULL;
  471. if (m_bIsConnected)
  472. {
  473. char tQBuf[MAX_PATH_LEN];
  474. AAssoc * result;
  475. sprintf(tQBuf, "SELECT * FROM `metro_modules` WHERE `id`=%" PRIu64, id);
  476. #ifdef DEBUG_ALL
  477. LOG(tQBuf);
  478. #endif
  479. result = m_pDatabase->Query(tQBuf);
  480. if (result != NULL)
  481. {
  482. if (result->size() > 0)
  483. {
  484. RetVal = (DBC_IS_MODULE_DATA *) malloc(sizeof(DBC_IS_MODULE_DATA));
  485. if (RetVal)
  486. {
  487. memset(RetVal, 0, sizeof(DBC_IS_MODULE_DATA));
  488. RetVal->id = id;
  489. Assoc * cArr;
  490. Assoc::iterator it;
  491. cArr = result->at(0);
  492. it = cArr->find("track_id");
  493. if (it != cArr->end())
  494. {
  495. RetVal->track_id = atoll(it->second.c_str());
  496. };
  497. it = cArr->find("side");
  498. if (it != cArr->end())
  499. {
  500. RetVal->side = it->second.c_str()[0];
  501. };
  502. it = cArr->find("status");
  503. if (it != cArr->end())
  504. {
  505. RetVal->status = it->second.c_str()[0];
  506. };
  507. it = cArr->find("IP4");
  508. if (it != cArr->end())
  509. {
  510. strncpy(RetVal->ip4, it->second.c_str(), 15);
  511. RetVal->ip4[15] = (char) 0;
  512. };
  513. };
  514. };
  515. deleteResult(result);
  516. };
  517. };
  518. return RetVal;
  519. }
  520. char servaMySQLDBC::getMojoWM(uint64_t id)
  521. {
  522. char RetVal = 'N';
  523. if (m_bIsConnected)
  524. {
  525. char tQBuf[MAX_PATH_LEN];
  526. AAssoc * result;
  527. sprintf(tQBuf, "SELECT `status` FROM `metro_modules` WHERE `id`=%" PRIu64 "", id);
  528. #ifdef DEBUG_ALL
  529. LOG(tQBuf);
  530. #endif
  531. result = m_pDatabase->Query(tQBuf);
  532. if (result != NULL)
  533. {
  534. if (result->size() > 0)
  535. {
  536. Assoc * cArr;
  537. Assoc::iterator it;
  538. cArr = result->at(0);
  539. it = cArr->find("status");
  540. if (it != cArr->end())
  541. {
  542. RetVal = it->second.c_str()[0];
  543. };
  544. };
  545. deleteResult(result);
  546. };
  547. };
  548. return RetVal;
  549. }
  550. DBC_RPC_WEB_CMD * servaMySQLDBC::fetchWebCmd(uint64_t id)
  551. {
  552. DBC_RPC_WEB_CMD * RetVal = NULL;
  553. if (m_bIsConnected)
  554. {
  555. char tQBuf[MAX_PATH_LEN];
  556. AAssoc * result;
  557. sprintf(tQBuf, "SELECT `id`,`cmd`,`aux_id`,`param` FROM `mem_web_queue` WHERE `module_id`=%" PRIu64 " AND `status`=0 LIMIT 1", id);
  558. #ifdef DEBUG_ALL
  559. LOG(tQBuf);
  560. #endif
  561. result = m_pDatabase->Query(tQBuf);
  562. if (result != NULL)
  563. {
  564. if (result->size() > 0)
  565. {
  566. RetVal = (DBC_RPC_WEB_CMD *) malloc(sizeof(DBC_RPC_WEB_CMD));
  567. if (RetVal)
  568. {
  569. memset(RetVal, 0, sizeof(DBC_RPC_WEB_CMD));
  570. Assoc * cArr;
  571. Assoc::iterator it;
  572. cArr = result->at(0);
  573. it = cArr->find("id");
  574. if (it != cArr->end())
  575. {
  576. RetVal->id = atoll(it->second.c_str());
  577. };
  578. it = cArr->find("cmd");
  579. if (it != cArr->end())
  580. {
  581. RetVal->cmd = atoi(it->second.c_str());
  582. };
  583. it = cArr->find("aux_id");
  584. if (it != cArr->end())
  585. {
  586. RetVal->aux_id = atoll(it->second.c_str());
  587. };
  588. it = cArr->find("param");
  589. if (it != cArr->end())
  590. {
  591. strncpy(RetVal->param, it->second.c_str(), 64);
  592. RetVal->param[64] = (char) 0;
  593. };
  594. };
  595. };
  596. deleteResult(result);
  597. };
  598. };
  599. return RetVal;
  600. }
  601. uint64_t servaMySQLDBC::getBottomLRF(uint64_t id)
  602. {
  603. uint64_t RetVal = 0;
  604. if (m_bIsConnected)
  605. {
  606. char tQBuf[MAX_PATH_LEN];
  607. AAssoc * result;
  608. sprintf(tQBuf, "SELECT `id` FROM `lrf_sensors` WHERE `role`='B' AND `mojo_id`=%d", id);
  609. #ifdef DEBUG_ALL
  610. LOG(tQBuf);
  611. #endif
  612. result = m_pDatabase->Query(tQBuf);
  613. if (result != NULL)
  614. {
  615. if (result->size() > 0)
  616. {
  617. Assoc * cArr;
  618. Assoc::iterator it;
  619. cArr = result->at(0);
  620. it = cArr->find("id");
  621. if (it != cArr->end())
  622. {
  623. RetVal = atoll(it->second.c_str());
  624. };
  625. };
  626. };
  627. deleteResult(result);
  628. };
  629. return RetVal;
  630. }
  631. uint32_t servaMySQLDBC::getCloudLTS(uint8_t Obj, uint64_t id)
  632. {
  633. uint32_t RetVal = 0;
  634. if (m_bIsConnected)
  635. {
  636. char tQBuf[MAX_PATH_LEN];
  637. AAssoc * result;
  638. sprintf(tQBuf, "SELECT `ts` FROM `mem_online_cloud` WHERE `object_id`=%" PRIu64 " AND `object_type`=%d", id, Obj);
  639. #ifdef DEBUG_ALL
  640. LOG(tQBuf);
  641. #endif
  642. result = m_pDatabase->Query(tQBuf);
  643. if (result != NULL)
  644. {
  645. if (result->size() > 0)
  646. {
  647. Assoc * cArr;
  648. Assoc::iterator it;
  649. cArr = result->at(0);
  650. it = cArr->find("ts");
  651. if (it != cArr->end())
  652. {
  653. RetVal = atoi(it->second.c_str());
  654. };
  655. };
  656. };
  657. deleteResult(result);
  658. };
  659. return RetVal;
  660. }
  661. uint8_t servaMySQLDBC::getCloudStatus(uint8_t Obj, uint64_t id)
  662. {
  663. uint8_t RetVal = 0;
  664. if (m_bIsConnected)
  665. {
  666. char tQBuf[MAX_PATH_LEN];
  667. AAssoc * result;
  668. sprintf(tQBuf, "SELECT `status` FROM `mem_online_cloud` WHERE `object_id`=%" PRIu64 " AND `object_type`=%d", id, Obj);
  669. #ifdef DEBUG_ALL
  670. LOG(tQBuf);
  671. #endif
  672. result = m_pDatabase->Query(tQBuf);
  673. if (result != NULL)
  674. {
  675. if (result->size() > 0)
  676. {
  677. Assoc * cArr;
  678. Assoc::iterator it;
  679. cArr = result->at(0);
  680. it = cArr->find("status");
  681. if (it != cArr->end())
  682. {
  683. RetVal = atoi(it->second.c_str());
  684. };
  685. };
  686. };
  687. deleteResult(result);
  688. };
  689. return RetVal;
  690. }
  691. bool servaMySQLDBC::getDBLoggingSettings(void)
  692. {
  693. bool RetVal = false;
  694. if (m_bIsConnected)
  695. {
  696. char tQBuf[MAX_PATH_LEN];
  697. AAssoc * result;
  698. sprintf(tQBuf, "SELECT `use_db_logging` FROM `system_props` WHERE `id`=1");
  699. #ifdef DEBUG_ALL
  700. LOG(tQBuf);
  701. #endif
  702. result = m_pDatabase->Query(tQBuf);
  703. if (result != NULL)
  704. {
  705. if (result->size() > 0)
  706. {
  707. Assoc * cArr;
  708. Assoc::iterator it;
  709. cArr = result->at(0);
  710. it = cArr->find("use_db_logging");
  711. if (it != cArr->end())
  712. {
  713. RetVal = (bool) atoi(it->second.c_str());
  714. };
  715. };
  716. };
  717. deleteResult(result);
  718. };
  719. return RetVal;
  720. }
  721. uint64_t servaMySQLDBC::getRecentMediaId()
  722. {
  723. uint64_t RetVal = 0;
  724. if (m_bIsConnected)
  725. {
  726. char tQBuf[MAX_PATH_LEN];
  727. AAssoc * result;
  728. sprintf(tQBuf, "SELECT `id` FROM `media_encoder_queue` WHERE `status`=1 ORDER BY `ts` LIMIT 1");
  729. #ifdef DEBUG_ALL
  730. LOG(tQBuf);
  731. #endif
  732. result = m_pDatabase->Query(tQBuf);
  733. if (result != NULL)
  734. {
  735. if (result->size() > 0)
  736. {
  737. Assoc * cArr;
  738. Assoc::iterator it;
  739. cArr = result->at(0);
  740. it = cArr->find("id");
  741. if (it != cArr->end())
  742. {
  743. RetVal = atoll(it->second.c_str());
  744. };
  745. };
  746. };
  747. deleteResult(result);
  748. };
  749. return RetVal;
  750. }
  751. DBC_RPC_MEDIA_INFO * servaMySQLDBC::getRemoteMediaInfo(uint64_t id)
  752. {
  753. DBC_RPC_MEDIA_INFO * RetVal = NULL;
  754. if (m_bIsConnected)
  755. {
  756. char tQBuf[MAX_PATH_LEN];
  757. AAssoc * result;
  758. sprintf(tQBuf, "SELECT * FROM `media_encoder_queue` WHERE `id`=%" PRIu64, id);
  759. #ifdef DEBUG_ALL
  760. LOG(tQBuf);
  761. #endif
  762. result = m_pDatabase->Query(tQBuf);
  763. if (result != NULL)
  764. {
  765. if (result->size() > 0)
  766. {
  767. Assoc * cArr;
  768. Assoc::iterator it;
  769. RetVal = (DBC_RPC_MEDIA_INFO *) malloc(sizeof(DBC_RPC_MEDIA_INFO));
  770. if (RetVal)
  771. {
  772. cArr = result->at(0);
  773. it = cArr->find("module_id");
  774. if (it != cArr->end())
  775. {
  776. RetVal->module_id = atoll(it->second.c_str());
  777. };
  778. it = cArr->find("session_id");
  779. if (it != cArr->end())
  780. {
  781. RetVal->session_id = atoll(it->second.c_str());
  782. };
  783. it = cArr->find("uuid");
  784. if (it != cArr->end())
  785. {
  786. strncpy(RetVal->uuid, it->second.c_str(), 64);
  787. RetVal->uuid[64] = (char) 0;
  788. };
  789. it = cArr->find("width");
  790. if (it != cArr->end())
  791. {
  792. RetVal->width = atoi(it->second.c_str());
  793. };
  794. it = cArr->find("height");
  795. if (it != cArr->end())
  796. {
  797. RetVal->height = atoi(it->second.c_str());
  798. };
  799. it = cArr->find("fps");
  800. if (it != cArr->end())
  801. {
  802. RetVal->fps = atoi(it->second.c_str());
  803. };
  804. it = cArr->find("fmt");
  805. if (it != cArr->end())
  806. {
  807. strncpy(RetVal->fmt, it->second.c_str(), 5);
  808. RetVal->fmt[5] = (char) 0;
  809. };
  810. };
  811. };
  812. };
  813. deleteResult(result);
  814. };
  815. return RetVal;
  816. }
  817. DBC_RPC_MEDIA_INFO_EX * servaMySQLDBC::getRemoteMediaInfoEx(uint64_t id)
  818. {
  819. DBC_RPC_MEDIA_INFO_EX * RetVal = NULL;
  820. if (m_bIsConnected)
  821. {
  822. char tQBuf[MAX_PATH_LEN];
  823. AAssoc * result;
  824. sprintf(tQBuf, "SELECT * FROM `media_encoder_queue` WHERE `id`=%" PRIu64, id);
  825. #ifdef DEBUG_ALL
  826. LOG(tQBuf);
  827. #endif
  828. result = m_pDatabase->Query(tQBuf);
  829. if (result != NULL)
  830. {
  831. if (result->size() > 0)
  832. {
  833. Assoc * cArr;
  834. Assoc::iterator it;
  835. RetVal = (DBC_RPC_MEDIA_INFO_EX *) malloc(sizeof(DBC_RPC_MEDIA_INFO_EX));
  836. if (RetVal)
  837. {
  838. cArr = result->at(0);
  839. it = cArr->find("module_id");
  840. if (it != cArr->end())
  841. {
  842. RetVal->module_id = atoll(it->second.c_str());
  843. };
  844. it = cArr->find("session_id");
  845. if (it != cArr->end())
  846. {
  847. RetVal->session_id = atoll(it->second.c_str());
  848. };
  849. it = cArr->find("ts");
  850. if (it != cArr->end())
  851. {
  852. RetVal->ts = atoi(it->second.c_str());
  853. };
  854. it = cArr->find("tsms");
  855. if (it != cArr->end())
  856. {
  857. RetVal->tms = atoi(it->second.c_str());
  858. };
  859. it = cArr->find("uuid");
  860. if (it != cArr->end())
  861. {
  862. strncpy(RetVal->uuid, it->second.c_str(), 64);
  863. RetVal->uuid[64] = (char) 0;
  864. };
  865. it = cArr->find("width");
  866. if (it != cArr->end())
  867. {
  868. RetVal->width = atoi(it->second.c_str());
  869. };
  870. it = cArr->find("height");
  871. if (it != cArr->end())
  872. {
  873. RetVal->height = atoi(it->second.c_str());
  874. };
  875. it = cArr->find("fps");
  876. if (it != cArr->end())
  877. {
  878. RetVal->fps = atoi(it->second.c_str());
  879. };
  880. it = cArr->find("fmt");
  881. if (it != cArr->end())
  882. {
  883. strncpy(RetVal->fmt, it->second.c_str(), 5);
  884. RetVal->fmt[5] = (char) 0;
  885. };
  886. };
  887. };
  888. };
  889. deleteResult(result);
  890. };
  891. return RetVal;
  892. }
  893. MODBUS_POST_DATA *servaMySQLDBC::getScadaPostData( uint64_t id ){
  894. MODBUS_POST_DATA *RetVal = NULL;
  895. if (m_bIsConnected){
  896. char tQBuf[MAX_PATH_LEN];
  897. AAssoc * result;
  898. sprintf(tQBuf, "SELECT `platform_id`, `src`, `status`, `type` FROM `metro_platforms_mboxes` WHERE `id`=%" PRIu64, id);
  899. #ifdef DEBUG_ALL
  900. LOG(tQBuf);
  901. #endif
  902. result = m_pDatabase->Query(tQBuf);
  903. if (result != NULL){
  904. if (result->size() > 0){
  905. Assoc * cArr;
  906. Assoc::iterator it;
  907. RetVal = (MODBUS_POST_DATA *) malloc(sizeof(MODBUS_POST_DATA));
  908. if (RetVal){
  909. memset( RetVal, 0, sizeof( MODBUS_POST_DATA ));
  910. cArr = result->at(0);
  911. it = cArr->find("platform_id");
  912. if (it != cArr->end()){
  913. RetVal->platform_id = atoll(it->second.c_str());
  914. };
  915. it = cArr->find("src");
  916. if (it != cArr->end()){
  917. RetVal->src = atoll(it->second.c_str());
  918. };
  919. it = cArr->find("status");
  920. if (it != cArr->end())
  921. {
  922. RetVal->status = atoi(it->second.c_str());
  923. };
  924. it = cArr->find("type");
  925. if (it != cArr->end())
  926. {
  927. RetVal->type = atoi(it->second.c_str());
  928. };
  929. };
  930. };
  931. };
  932. deleteResult(result);
  933. };
  934. return RetVal;
  935. }
  936. int servaMySQLDBC::getScadaPostStatus( uint64_t platform_id, SERVER_SCADA_POST_TYPE mtyp, uint64_t src ){
  937. int retVal = -1;
  938. if( m_bIsConnected ){
  939. char tQBuf[MAX_PATH_LEN];
  940. AAssoc * result;
  941. if( mtyp != SCADA_POST_TYPE_NA ){
  942. if ( src ) {
  943. sprintf(tQBuf, "SELECT `status` FROM `metro_platforms_mboxes` WHERE `platform_id`=%" PRIu64 " AND `type`=%d AND `src`=%" PRIu64, platform_id, mtyp, src );
  944. } else {
  945. sprintf(tQBuf, "SELECT `status` FROM `metro_platforms_mboxes` WHERE `platform_id`=%" PRIu64 " AND `type`=%d", platform_id, mtyp );
  946. };
  947. } else {
  948. sprintf( tQBuf, "SELECT `status` FROM `metro_platforms_mboxes` WHERE `platform_id`=%" PRIu64 " ORDER BY LIMIT 1", platform_id );
  949. };
  950. #ifdef DEBUG_ALL
  951. LOG(tQBuf);
  952. #endif
  953. result = m_pDatabase->Query(tQBuf);
  954. if( result != NULL ){
  955. if( result->size() > 0 ){
  956. Assoc * cArr = result->at(0);
  957. Assoc::iterator it = cArr->find("status");
  958. if( it != cArr->end() ){
  959. retVal = atoi(it->second.c_str());
  960. };
  961. };
  962. };
  963. deleteResult(result);
  964. };
  965. return retVal;
  966. }
  967. DBC_SERVA_CONFIG * servaMySQLDBC::getServaConfig()
  968. {
  969. DBC_SERVA_CONFIG * RetVal = NULL;
  970. if (m_bIsConnected)
  971. {
  972. char tQBuf[MAX_PATH_LEN];
  973. AAssoc * result;
  974. sprintf(tQBuf, "SELECT * FROM `system_props` WHERE `id`=1");
  975. #ifdef DEBUG_ALL
  976. LOG(tQBuf);
  977. #endif
  978. result = m_pDatabase->Query(tQBuf);
  979. if (result != NULL)
  980. {
  981. if (result->size() > 0)
  982. {
  983. Assoc * cArr;
  984. Assoc::iterator it;
  985. RetVal = (DBC_SERVA_CONFIG *) malloc(sizeof(DBC_SERVA_CONFIG));
  986. if (RetVal)
  987. {
  988. memset(RetVal, 0, sizeof(DBC_SERVA_CONFIG));
  989. cArr = result->at(0);
  990. it = cArr->find("encoder_limit");
  991. if (it != cArr->end())
  992. {
  993. RetVal->encoderLimit = atoi(it->second.c_str());
  994. };
  995. it = cArr->find("histo_days");
  996. if (it != cArr->end())
  997. {
  998. RetVal->historyDaysLimit = atoi(it->second.c_str());
  999. };
  1000. it = cArr->find("histo_perc");
  1001. if (it != cArr->end())
  1002. {
  1003. RetVal->historyPreserveFreeSpacePerc = atoi(it->second.c_str());
  1004. };
  1005. it = cArr->find("histo_megs");
  1006. if (it != cArr->end())
  1007. {
  1008. RetVal->historyPreserveFreeSpaceMB = atoi(it->second.c_str());
  1009. };
  1010. it = cArr->find("histo_limit");
  1011. if (it != cArr->end())
  1012. {
  1013. RetVal->historyAutoDeleteLimit = atoi(it->second.c_str());
  1014. };
  1015. it = cArr->find("composer_proceed_delay");
  1016. if (it != cArr->end())
  1017. {
  1018. RetVal->composerProceedDelay = atoi(it->second.c_str());
  1019. };
  1020. // RetVal->lts = time(NULL);
  1021. // it = cArr->find("uuid");
  1022. // if( it != cArr->end() ){
  1023. // strncpy( RetVal->uuid, it->second.c_str(), 64 );
  1024. // RetVal->uuid[64] = (char)0;
  1025. // };
  1026. };
  1027. };
  1028. };
  1029. deleteResult(result);
  1030. };
  1031. return RetVal;
  1032. }
  1033. SESSION_DATA * servaMySQLDBC::getSessionData(uint64_t id)
  1034. {
  1035. SESSION_DATA * RetVal = NULL;
  1036. if (m_bIsConnected)
  1037. {
  1038. char tQBuf[MAX_PATH_LEN];
  1039. AAssoc * result;
  1040. sprintf(tQBuf, "SELECT * FROM `sessions` WHERE `id`=%" PRIu64, id);
  1041. #ifdef DEBUG_ALL
  1042. LOG(tQBuf);
  1043. #endif
  1044. result = m_pDatabase->Query(tQBuf);
  1045. if (result != NULL)
  1046. {
  1047. if (result->size() > 0)
  1048. {
  1049. Assoc * cArr;
  1050. Assoc::iterator it;
  1051. RetVal = (SESSION_DATA *) malloc(sizeof(SESSION_DATA));
  1052. if (RetVal)
  1053. {
  1054. memset(RetVal, 0, sizeof(SESSION_DATA));
  1055. RetVal->db_id = id;
  1056. cArr = result->at(0);
  1057. it = cArr->find("ts");
  1058. if (it != cArr->end())
  1059. {
  1060. RetVal->sts = atoi(it->second.c_str());
  1061. };
  1062. it = cArr->find("ts_ms");
  1063. if (it != cArr->end())
  1064. {
  1065. RetVal->sms = atoi(it->second.c_str());
  1066. };
  1067. it = cArr->find("track_id");
  1068. if (it != cArr->end())
  1069. {
  1070. RetVal->track_id = atoi(it->second.c_str());
  1071. };
  1072. it = cArr->find("lts");
  1073. if( it != cArr->end() ){
  1074. RetVal->lts = atoi( it->second.c_str() );
  1075. };
  1076. it = cArr->find("src");
  1077. if( it != cArr->end() ){
  1078. RetVal->src = it->second.c_str()[0];
  1079. };
  1080. //RetVal->lts = time(NULL); //? Why ?
  1081. it = cArr->find("uuid");
  1082. if (it != cArr->end())
  1083. {
  1084. strncpy(RetVal->uuid, it->second.c_str(), 64);
  1085. RetVal->uuid[64] = (char) 0;
  1086. };
  1087. it = cArr->find("final");
  1088. if (it != cArr->end())
  1089. {
  1090. RetVal->final = it->second.c_str()[0];
  1091. };
  1092. };
  1093. };
  1094. };
  1095. deleteResult(result);
  1096. };
  1097. return RetVal;
  1098. }
  1099. uint64_t servaMySQLDBC::getSessionOlderThan(uint32_t ts, uint8_t min_lvl)
  1100. {
  1101. uint64_t RetVal = 0;
  1102. if (m_bIsConnected)
  1103. {
  1104. char tQBuf[MAX_PATH_LEN];
  1105. AAssoc * result;
  1106. sprintf(tQBuf, "SELECT `id` FROM `sessions` WHERE `ts`<=%d AND `status`<=%d AND `final`!='N' LIMIT 1", ts, min_lvl);
  1107. #ifdef DEBUG_ALL
  1108. LOG(tQBuf);
  1109. #endif
  1110. result = m_pDatabase->Query(tQBuf);
  1111. if (result != NULL)
  1112. {
  1113. if (result->size() > 0)
  1114. {
  1115. Assoc * cArr;
  1116. Assoc::iterator it;
  1117. cArr = result->at(0);
  1118. it = cArr->find("id");
  1119. if (it != cArr->end())
  1120. {
  1121. RetVal = atoll(it->second.c_str());
  1122. };
  1123. };
  1124. };
  1125. deleteResult(result);
  1126. };
  1127. return RetVal;
  1128. }
  1129. uint64_t servaMySQLDBC::getSessionOldest(uint8_t min_lvl)
  1130. {
  1131. uint64_t RetVal = 0;
  1132. if (m_bIsConnected)
  1133. {
  1134. char tQBuf[MAX_PATH_LEN];
  1135. AAssoc * result;
  1136. sprintf(tQBuf, "SELECT `id` FROM `sessions` WHERE `status`<=%d AND `final`!='N' ORDER BY `ts` LIMIT 1", min_lvl);
  1137. #ifdef DEBUG_ALL
  1138. LOG(tQBuf);
  1139. #endif
  1140. result = m_pDatabase->Query(tQBuf);
  1141. if (result != NULL)
  1142. {
  1143. if (result->size() > 0)
  1144. {
  1145. Assoc * cArr;
  1146. Assoc::iterator it;
  1147. cArr = result->at(0);
  1148. it = cArr->find("id");
  1149. if (it != cArr->end())
  1150. {
  1151. RetVal = atoll(it->second.c_str());
  1152. };
  1153. };
  1154. };
  1155. deleteResult(result);
  1156. };
  1157. return RetVal;
  1158. }
  1159. uint16_t servaMySQLDBC::getSessionTimeOut()
  1160. {
  1161. uint16_t RetVal = 120;
  1162. if (m_bIsConnected)
  1163. {
  1164. char tQBuf[MAX_PATH_LEN];
  1165. AAssoc * result;
  1166. sprintf(tQBuf, "SELECT `session_end` FROM `system_props` WHERE `id`=1");
  1167. #ifdef DEBUG_ALL
  1168. LOG(tQBuf);
  1169. #endif
  1170. result = m_pDatabase->Query(tQBuf);
  1171. if (result != NULL)
  1172. {
  1173. if (result->size() > 0)
  1174. {
  1175. Assoc * cArr;
  1176. Assoc::iterator it;
  1177. cArr = result->at(0);
  1178. it = cArr->find("session_end");
  1179. if (it != cArr->end())
  1180. {
  1181. RetVal = atoi(it->second.c_str()) - 1;
  1182. if (RetVal)
  1183. {
  1184. RetVal *= 60;
  1185. }
  1186. else
  1187. {
  1188. RetVal = 30;
  1189. }
  1190. };
  1191. };
  1192. };
  1193. deleteResult(result);
  1194. };
  1195. return RetVal;
  1196. }
  1197. uint64_t servaMySQLDBC::getSessionTrackId(uint64_t id)
  1198. {
  1199. uint64_t RetVal = 0;
  1200. if (m_bIsConnected)
  1201. {
  1202. char tQBuf[MAX_PATH_LEN];
  1203. AAssoc * result;
  1204. sprintf(tQBuf, "SELECT `track_id` FROM `sessions` WHERE `id`=%" PRIu64, id);
  1205. #ifdef DEBUG_ALL
  1206. LOG(tQBuf);
  1207. #endif
  1208. result = m_pDatabase->Query(tQBuf);
  1209. if (result != NULL)
  1210. {
  1211. if (result->size() > 0)
  1212. {
  1213. Assoc * cArr;
  1214. Assoc::iterator it;
  1215. cArr = result->at(0);
  1216. it = cArr->find("track_id");
  1217. if (it != cArr->end())
  1218. {
  1219. RetVal = atoll(it->second.c_str());
  1220. };
  1221. };
  1222. };
  1223. deleteResult(result);
  1224. };
  1225. return RetVal;
  1226. }
  1227. uint64_t servaMySQLDBC::getSessionWithUnmergedVideo( uint32_t delay_secs ){
  1228. uint64_t RetVal = 0;
  1229. if (m_bIsConnected)
  1230. {
  1231. char tQBuf[MAX_PATH_LEN];
  1232. AAssoc * result;
  1233. if ( delay_secs ) {
  1234. uint32_t sts = (uint32_t) time( NULL );
  1235. sts -= delay_secs-1;
  1236. sprintf(tQBuf, "SELECT `id` FROM `sessions` WHERE `final`='Y' AND `ts` < %d ORDER BY `ts` LIMIT 1", sts );
  1237. } else {
  1238. sprintf(tQBuf, "SELECT `id` FROM `sessions` WHERE `final`='Y' ORDER BY `ts` LIMIT 1");
  1239. }
  1240. #ifdef DEBUG_ALL
  1241. LOG(tQBuf);
  1242. #endif
  1243. result = m_pDatabase->Query(tQBuf);
  1244. if (result != NULL)
  1245. {
  1246. if (result->size() > 0)
  1247. {
  1248. Assoc * cArr;
  1249. Assoc::iterator it;
  1250. cArr = result->at(0);
  1251. it = cArr->find("id");
  1252. if (it != cArr->end())
  1253. {
  1254. RetVal = atoll(it->second.c_str());
  1255. };
  1256. };
  1257. };
  1258. deleteResult(result);
  1259. };
  1260. return RetVal;
  1261. }
  1262. SCADA_TRACK_INFO * servaMySQLDBC::getTrackSCADA(uint64_t id)
  1263. {
  1264. SCADA_TRACK_INFO * RetVal = NULL;
  1265. if (m_bIsConnected)
  1266. {
  1267. RetVal = (SCADA_TRACK_INFO *) malloc(sizeof(SCADA_TRACK_INFO));
  1268. if (RetVal)
  1269. {
  1270. char tQBuf[MAX_PATH_LEN];
  1271. AAssoc * result;
  1272. memset(RetVal, 0, sizeof(SCADA_TRACK_INFO));
  1273. sprintf(tQBuf, "SELECT `platform_id`,`side` FROM `metro_tracks` WHERE `id`=%" PRIu64, id);
  1274. #ifdef DEBUG_ALL
  1275. LOG(tQBuf);
  1276. #endif
  1277. result = m_pDatabase->Query(tQBuf);
  1278. if (result != NULL)
  1279. {
  1280. if (result->size() > 0)
  1281. {
  1282. Assoc * cArr;
  1283. Assoc::iterator it;
  1284. cArr = result->at(0);
  1285. it = cArr->find("platform_id");
  1286. if (it != cArr->end())
  1287. {
  1288. RetVal->platform_id = atoll(it->second.c_str());
  1289. };
  1290. it = cArr->find("side");
  1291. if (it != cArr->end())
  1292. {
  1293. RetVal->side = it->second.c_str()[0];
  1294. };
  1295. };
  1296. };
  1297. deleteResult(result);
  1298. }
  1299. };
  1300. return RetVal;
  1301. }
  1302. DBC_IS_TRACK_DATA * servaMySQLDBC::getTrackData(uint64_t id)
  1303. {
  1304. DBC_IS_TRACK_DATA * RetVal = NULL;
  1305. if (m_bIsConnected)
  1306. {
  1307. char tQBuf[MAX_PATH_LEN];
  1308. AAssoc * result;
  1309. sprintf(tQBuf, "SELECT * FROM `metro_tracks` WHERE `id`=%" PRIu64, id);
  1310. #ifdef DEBUG_ALL
  1311. LOG(tQBuf);
  1312. #endif
  1313. result = m_pDatabase->Query(tQBuf);
  1314. if (result != NULL)
  1315. {
  1316. if (result->size() > 0)
  1317. {
  1318. RetVal = (DBC_IS_TRACK_DATA *) malloc(sizeof(DBC_IS_TRACK_DATA));
  1319. if (RetVal)
  1320. {
  1321. memset(RetVal, 0, sizeof(DBC_IS_TRACK_DATA));
  1322. RetVal->id = id;
  1323. Assoc * cArr;
  1324. Assoc::iterator it;
  1325. cArr = result->at(0);
  1326. it = cArr->find("platform_id");
  1327. if (it != cArr->end())
  1328. {
  1329. RetVal->platform_id = atoll(it->second.c_str());
  1330. };
  1331. it = cArr->find("side");
  1332. if (it != cArr->end())
  1333. {
  1334. RetVal->side = it->second.c_str()[0];
  1335. };
  1336. it = cArr->find("far_module_id");
  1337. if (it != cArr->end())
  1338. {
  1339. RetVal->fmid = atoll(it->second.c_str());
  1340. };
  1341. it = cArr->find("near_module_id");
  1342. if (it != cArr->end())
  1343. {
  1344. RetVal->nmid = atoll(it->second.c_str());
  1345. };
  1346. it = cArr->find("name");
  1347. if (it != cArr->end())
  1348. {
  1349. strncpy(RetVal->name, it->second.c_str(), 64);
  1350. RetVal->name[64] = (char) 0;
  1351. };
  1352. it = cArr->find("short");
  1353. if (it != cArr->end())
  1354. {
  1355. strncpy(RetVal->abbr, it->second.c_str(), 32);
  1356. RetVal->abbr[32] = (char) 0;
  1357. };
  1358. };
  1359. };
  1360. deleteResult(result);
  1361. };
  1362. };
  1363. return RetVal;
  1364. }
  1365. uint64_t servaMySQLDBC::getTrackIdByMojo(uint64_t id)
  1366. {
  1367. uint64_t RetVal = 0;
  1368. if (m_bIsConnected)
  1369. {
  1370. char tQBuf[MAX_PATH_LEN];
  1371. AAssoc * result;
  1372. sprintf(tQBuf, "SELECT `track_id` FROM `metro_modules` WHERE `id`=%" PRIu64, id);
  1373. #ifdef DEBUG_ALL
  1374. LOG(tQBuf);
  1375. #endif
  1376. result = m_pDatabase->Query(tQBuf);
  1377. if (result != NULL)
  1378. {
  1379. if (result->size() > 0)
  1380. {
  1381. Assoc * cArr;
  1382. Assoc::iterator it;
  1383. cArr = result->at(0);
  1384. it = cArr->find("track_id");
  1385. if (it != cArr->end())
  1386. {
  1387. RetVal = atoll(it->second.c_str());
  1388. };
  1389. };
  1390. };
  1391. deleteResult(result);
  1392. };
  1393. return RetVal;
  1394. }
  1395. uint64_t servaMySQLDBC::getTrackIdByPlatform(uint64_t id, char side )
  1396. {
  1397. uint64_t RetVal = 0;
  1398. if (m_bIsConnected)
  1399. {
  1400. char tQBuf[MAX_PATH_LEN];
  1401. AAssoc * result;
  1402. sprintf(tQBuf, "SELECT `id` FROM `metro_tracks` WHERE `platform_id`=%" PRIu64 " AND `side`='%c'", id, side );
  1403. #ifdef DEBUG_ALL
  1404. LOG(tQBuf);
  1405. #endif
  1406. result = m_pDatabase->Query(tQBuf);
  1407. if (result != NULL)
  1408. {
  1409. if (result->size() > 0)
  1410. {
  1411. Assoc * cArr;
  1412. Assoc::iterator it;
  1413. cArr = result->at(0);
  1414. it = cArr->find("id");
  1415. if (it != cArr->end())
  1416. {
  1417. RetVal = atoll(it->second.c_str());
  1418. };
  1419. };
  1420. };
  1421. deleteResult(result);
  1422. };
  1423. return RetVal;
  1424. }
  1425. uint64_t servaMySQLDBC::getUpperLRF(uint64_t id)
  1426. {
  1427. uint64_t RetVal = 0;
  1428. if (m_bIsConnected)
  1429. {
  1430. char tQBuf[MAX_PATH_LEN];
  1431. AAssoc * result;
  1432. sprintf(tQBuf, "SELECT `id` FROM `lrf_sensors` WHERE `role`='U' AND `mojo_id`=%d", id);
  1433. #ifdef DEBUG_ALL
  1434. LOG(tQBuf);
  1435. #endif
  1436. result = m_pDatabase->Query(tQBuf);
  1437. if (result != NULL)
  1438. {
  1439. if (result->size() > 0)
  1440. {
  1441. Assoc * cArr;
  1442. Assoc::iterator it;
  1443. cArr = result->at(0);
  1444. it = cArr->find("id");
  1445. if (it != cArr->end())
  1446. {
  1447. RetVal = atoll(it->second.c_str());
  1448. };
  1449. };
  1450. };
  1451. deleteResult(result);
  1452. };
  1453. return RetVal;
  1454. }
  1455. DBC_MEDIA_COMPOSER_DATA * servaMySQLDBC::getVideoComposerData()
  1456. {
  1457. DBC_MEDIA_COMPOSER_DATA * RetVal = NULL;
  1458. if (m_bIsConnected)
  1459. {
  1460. char tQBuf[MAX_PATH_LEN];
  1461. AAssoc * result;
  1462. sprintf(tQBuf, "SELECT * FROM `system_props` WHERE `id`=1");
  1463. #ifdef DEBUG_ALL
  1464. LOG(tQBuf);
  1465. #endif
  1466. result = m_pDatabase->Query(tQBuf);
  1467. if (result != NULL)
  1468. {
  1469. if (result->size() > 0)
  1470. {
  1471. Assoc * cArr;
  1472. Assoc::iterator it;
  1473. RetVal = (DBC_MEDIA_COMPOSER_DATA *) malloc(sizeof(DBC_MEDIA_COMPOSER_DATA));
  1474. if (RetVal)
  1475. {
  1476. memset(RetVal, 0, sizeof(DBC_MEDIA_COMPOSER_DATA));
  1477. cArr = result->at(0);
  1478. it = cArr->find("composer_out_width");
  1479. if (it != cArr->end())
  1480. {
  1481. RetVal->out_width = atoi(it->second.c_str());
  1482. };
  1483. it = cArr->find("composer_out_height");
  1484. if (it != cArr->end())
  1485. {
  1486. RetVal->out_height = atoi(it->second.c_str());
  1487. };
  1488. it = cArr->find("composer_out_fps");
  1489. if (it != cArr->end())
  1490. {
  1491. RetVal->out_fps = atoi(it->second.c_str());
  1492. };
  1493. it = cArr->find("composer_prepend_ef");
  1494. if (it != cArr->end())
  1495. {
  1496. RetVal->prependEmptyFrames = (bool) atoi(it->second.c_str());
  1497. };
  1498. it = cArr->find("composer_debug_mode");
  1499. if (it != cArr->end())
  1500. {
  1501. RetVal->debugMode = (bool) atoi(it->second.c_str());
  1502. };
  1503. };
  1504. };
  1505. };
  1506. deleteResult(result);
  1507. };
  1508. return RetVal;
  1509. }
  1510. DBC_UINT64_LIST * servaMySQLDBC::listMediaQueueItems(uint8_t status)
  1511. {
  1512. DBC_UINT64_LIST * tVal = NULL;
  1513. if (m_bIsConnected)
  1514. {
  1515. char tQBuf[MAX_PATH_LEN];
  1516. AAssoc * result;
  1517. sprintf(tQBuf, "SELECT `id` FROM `media_encoder_queue` WHERE `status`=%d", status);
  1518. #ifdef DEBUG_ALL
  1519. LOG(tQBuf);
  1520. #endif
  1521. result = m_pDatabase->Query(tQBuf);
  1522. if (result != NULL)
  1523. {
  1524. if (result->size() > 0)
  1525. {
  1526. Assoc * cArr;
  1527. tVal = new DBC_UINT64_LIST();
  1528. if (tVal != NULL)
  1529. {
  1530. Assoc::iterator it;
  1531. for (int i = 0; i < result->size(); i++)
  1532. {
  1533. cArr = result->at(i);
  1534. it = cArr->find("id");
  1535. if (it != cArr->end())
  1536. {
  1537. tVal->push_back(atoll(it->second.c_str()));
  1538. };
  1539. };
  1540. };
  1541. };
  1542. };
  1543. deleteResult(result);
  1544. };
  1545. return tVal;
  1546. }
  1547. DBC_UINT64_LIST * servaMySQLDBC::listMetroModules(char status)
  1548. {
  1549. DBC_UINT64_LIST * tVal = NULL;
  1550. if (m_bIsConnected)
  1551. {
  1552. char tQBuf[MAX_PATH_LEN];
  1553. AAssoc * result;
  1554. sprintf(tQBuf, "SELECT `id` FROM `metro_modules` WHERE `status`='%c'", status);
  1555. #ifdef DEBUG_ALL
  1556. LOG(tQBuf);
  1557. #endif
  1558. result = m_pDatabase->Query(tQBuf);
  1559. if (result != NULL)
  1560. {
  1561. if (result->size() > 0)
  1562. {
  1563. Assoc * cArr;
  1564. tVal = new DBC_UINT64_LIST();
  1565. if (tVal != NULL)
  1566. {
  1567. Assoc::iterator it;
  1568. for (int i = 0; i < result->size(); i++)
  1569. {
  1570. cArr = result->at(i);
  1571. it = cArr->find("id");
  1572. if (it != cArr->end())
  1573. {
  1574. tVal->push_back(atoll(it->second.c_str()));
  1575. };
  1576. };
  1577. };
  1578. };
  1579. };
  1580. deleteResult(result);
  1581. };
  1582. return tVal;
  1583. }
  1584. DBC_UINT64_LIST * servaMySQLDBC::listPlatformModBusRTU(uint64_t platform_id, char mode ){
  1585. DBC_UINT64_LIST * tVal = NULL;
  1586. if (m_bIsConnected)
  1587. {
  1588. char tQBuf[MAX_PATH_LEN];
  1589. AAssoc * result;
  1590. if ( mode == 'A' ) { // All Modules
  1591. sprintf(tQBuf, "SELECT `id` FROM `modbus_modules` WHERE `platform_id`=%" PRIu64, platform_id);
  1592. } else {
  1593. sprintf(tQBuf, "SELECT `id` FROM `modbus_modules` WHERE `wm`='%c' AND `platform_id`=%" PRIu64, mode, platform_id);
  1594. }
  1595. #ifdef DEBUG_ALL
  1596. LOG(tQBuf);
  1597. #endif
  1598. result = m_pDatabase->Query(tQBuf);
  1599. if (result != NULL)
  1600. {
  1601. if (result->size() > 0)
  1602. {
  1603. Assoc * cArr;
  1604. tVal = new DBC_UINT64_LIST();
  1605. if (tVal != NULL)
  1606. {
  1607. Assoc::iterator it;
  1608. for (int i = 0; i < result->size(); i++)
  1609. {
  1610. cArr = result->at(i);
  1611. it = cArr->find("id");
  1612. if (it != cArr->end())
  1613. {
  1614. tVal->push_back(atoll(it->second.c_str()));
  1615. };
  1616. };
  1617. };
  1618. };
  1619. };
  1620. deleteResult(result);
  1621. };
  1622. return tVal;
  1623. }
  1624. DBC_UINT64_LIST * servaMySQLDBC::listModBusRTUs(uint8_t status, char mode)
  1625. {
  1626. DBC_UINT64_LIST * tVal = NULL;
  1627. if (m_bIsConnected){
  1628. char tQBuf[MAX_PATH_LEN];
  1629. AAssoc * result;
  1630. if (status) {
  1631. sprintf(tQBuf, "SELECT `id` FROM `modbus_modules` WHERE `wm`='%c' AND `status`=%d", mode, status);
  1632. } else {
  1633. if ( mode == 'A' ) {
  1634. sprintf(tQBuf, "SELECT `id` FROM `modbus_modules`");
  1635. } else {
  1636. sprintf(tQBuf, "SELECT `id` FROM `modbus_modules` WHERE `wm`='%c'", mode);
  1637. };
  1638. };
  1639. #ifdef DEBUG_ALL
  1640. LOG(tQBuf);
  1641. #endif
  1642. result = m_pDatabase->Query(tQBuf);
  1643. if (result != NULL){
  1644. if (result->size() > 0){
  1645. Assoc * cArr;
  1646. tVal = new DBC_UINT64_LIST();
  1647. if (tVal != NULL){
  1648. Assoc::iterator it;
  1649. for (int i = 0; i < result->size(); i++){
  1650. cArr = result->at(i);
  1651. it = cArr->find("id");
  1652. if (it != cArr->end()){
  1653. tVal->push_back(atoll(it->second.c_str()));
  1654. };
  1655. };
  1656. };
  1657. };
  1658. };
  1659. deleteResult(result);
  1660. };
  1661. return tVal;
  1662. }
  1663. DBC_UINT64_LIST * servaMySQLDBC::listPlatformModules(uint64_t id){
  1664. DBC_UINT64_LIST * tVal = NULL;
  1665. if (m_bIsConnected){
  1666. char tQBuf[MAX_PATH_LEN];
  1667. AAssoc * result;
  1668. sprintf(tQBuf, "SELECT `mod`.`id` FROM `metro_modules` `mod` LEFT JOIN `metro_tracks` `tra` ON ( `tra`.`id` = `mod`.`track_id` ) WHERE `mod`.`status`='E' AND `tra`.`platform_id`=%" PRIu64, id);
  1669. #ifdef DEBUG_ALL
  1670. LOG(tQBuf);
  1671. #endif
  1672. result = m_pDatabase->Query(tQBuf);
  1673. if (result != NULL){
  1674. if (result->size() > 0){
  1675. Assoc * cArr;
  1676. tVal = new DBC_UINT64_LIST();
  1677. if (tVal != NULL){
  1678. Assoc::iterator it;
  1679. for (int i = 0; i < result->size(); i++){
  1680. cArr = result->at(i);
  1681. it = cArr->find("id");
  1682. if (it != cArr->end()){
  1683. tVal->push_back(atoll(it->second.c_str()));
  1684. };
  1685. };
  1686. };
  1687. };
  1688. };
  1689. deleteResult(result);
  1690. };
  1691. return tVal;
  1692. }
  1693. DBC_UINT64_LIST * servaMySQLDBC::listPlatforms(char mode)
  1694. {
  1695. DBC_UINT64_LIST * tVal = NULL;
  1696. if (m_bIsConnected)
  1697. {
  1698. char tQBuf[MAX_PATH_LEN];
  1699. AAssoc * result;
  1700. sprintf(tQBuf, "SELECT `id` FROM `metro_platforms` WHERE `status`='%c'", mode);
  1701. #ifdef DEBUG_ALL
  1702. LOG(tQBuf);
  1703. #endif
  1704. result = m_pDatabase->Query(tQBuf);
  1705. if (result != NULL)
  1706. {
  1707. if (result->size() > 0)
  1708. {
  1709. Assoc * cArr;
  1710. tVal = new DBC_UINT64_LIST();
  1711. if (tVal != NULL)
  1712. {
  1713. Assoc::iterator it;
  1714. for (int i = 0; i < result->size(); i++)
  1715. {
  1716. cArr = result->at(i);
  1717. it = cArr->find("id");
  1718. if (it != cArr->end())
  1719. {
  1720. tVal->push_back(atoll(it->second.c_str()));
  1721. };
  1722. };
  1723. };
  1724. };
  1725. };
  1726. deleteResult(result);
  1727. };
  1728. return tVal;
  1729. }
  1730. DBC_UINT64_LIST *servaMySQLDBC::listScadaPosts( uint64_t platform_id ){
  1731. DBC_UINT64_LIST * tVal = NULL;
  1732. if (m_bIsConnected)
  1733. {
  1734. char tQBuf[MAX_PATH_LEN];
  1735. AAssoc * result;
  1736. sprintf(tQBuf, "SELECT `id` FROM `metro_platforms_mboxes` WHERE `platform_id`=%" PRIu64, platform_id );
  1737. #ifdef DEBUG_ALL
  1738. LOG(tQBuf);
  1739. #endif
  1740. result = m_pDatabase->Query(tQBuf);
  1741. if (result != NULL)
  1742. {
  1743. if (result->size() > 0)
  1744. {
  1745. Assoc * cArr;
  1746. tVal = new DBC_UINT64_LIST();
  1747. if (tVal != NULL)
  1748. {
  1749. Assoc::iterator it;
  1750. for (int i = 0; i < result->size(); i++)
  1751. {
  1752. cArr = result->at(i);
  1753. it = cArr->find("id");
  1754. if (it != cArr->end())
  1755. {
  1756. tVal->push_back(atoll(it->second.c_str()));
  1757. };
  1758. };
  1759. };
  1760. };
  1761. };
  1762. deleteResult(result);
  1763. };
  1764. return tVal;
  1765. };
  1766. // Escapes for a quoted MySQL string literal without using the connection (mysql_real_escape_string
  1767. // needs the access mutex, which the log path must not wait for)
  1768. static void logEscape(const char * src, char * dst, size_t dstSize)
  1769. {
  1770. size_t o = 0;
  1771. for (const char * c = (src != NULL) ? src : ""; *c && o + 2 < dstSize; c++)
  1772. {
  1773. char e = 0;
  1774. switch (*c)
  1775. {
  1776. case '\\': e = '\\'; break;
  1777. case '\'': e = '\''; break;
  1778. case '"' : e = '"'; break;
  1779. case '\n': e = 'n'; break;
  1780. case '\r': e = 'r'; break;
  1781. case 0x1a: e = 'Z'; break;
  1782. default : break;
  1783. };
  1784. if (e)
  1785. {
  1786. dst[o++] = '\\';
  1787. dst[o++] = e;
  1788. }
  1789. else
  1790. {
  1791. dst[o++] = *c;
  1792. }
  1793. };
  1794. dst[o] = (char) 0;
  1795. }
  1796. /*
  1797. Called by the database log service from inside the log broadcast: must never block on the database
  1798. (see MySQL_Connector::TrySilentQuery). Returns false if the connection is busy right now; the log
  1799. service keeps the line and retries later.
  1800. */
  1801. bool servaMySQLDBC::putIntoLog(CSTR A, CSTR B, CSTR C)
  1802. {
  1803. if (! m_bIsConnected || m_pDatabase == NULL)
  1804. {
  1805. return false;
  1806. }
  1807. char tType[8], tTS[48], tMsg[MAX_PATH_LEN];
  1808. logEscape(A, tType, sizeof(tType));
  1809. logEscape(B, tTS, sizeof(tTS));
  1810. logEscape(C, tMsg, sizeof(tMsg));
  1811. char tQBuf[MAX_PATH_LEN + 128];
  1812. snprintf(tQBuf, sizeof(tQBuf), "INSERT INTO `server_log_messages` SET lvl = '%s', `ts`='%s', `msg`='%s'", tType, tTS, tMsg);
  1813. return m_pDatabase->TrySilentQuery(tQBuf);
  1814. }
  1815. uint64_t servaMySQLDBC::registerMojo(CSTR A, CSTR B)
  1816. {
  1817. uint64_t RetVal = 0;
  1818. char tQBuf[MAX_PATH_LEN];
  1819. if (m_bIsConnected)
  1820. {
  1821. AAssoc * result;
  1822. sprintf(tQBuf, "SELECT `id` FROM `metro_modules` WHERE `IP4`='%s' AND `identity`='%s'", A, B);
  1823. #ifdef DEBUG_ALL
  1824. LOG(tQBuf);
  1825. #endif
  1826. result = m_pDatabase->Query(tQBuf);
  1827. if (result != NULL)
  1828. {
  1829. if (result->size() > 0)
  1830. {
  1831. Assoc * cArr;
  1832. Assoc::iterator it;
  1833. cArr = result->at(0);
  1834. it = cArr->find("id");
  1835. if (it != cArr->end())
  1836. {
  1837. RetVal = atoll(it->second.c_str());
  1838. };
  1839. };
  1840. };
  1841. deleteResult(result);
  1842. };
  1843. // if ( RetVal ) {
  1844. // sprintf( tQBuf, "INSERT INTO `mem_online_cloud` SET `id` FROM `metro_modules` WHERE `IP4`='%s' AND `identity`='%s'", A, B );
  1845. // m_pDatabase->SilentQuery( tQBuf );
  1846. // };
  1847. return RetVal;
  1848. }
  1849. bool servaMySQLDBC::registerServer(uint32_t SiteID, CSTR identity, int PID, uint32_t * ServID, uint32_t * ServNode)
  1850. {
  1851. if (m_bIsConnected)
  1852. {
  1853. // m_nSiteID = SiteID;
  1854. char tQBuf[MAX_PATH_LEN];
  1855. sprintf(tQBuf, "INSERT INTO servers SET `site_id`=%d, `identity`='%s', `version_string`='%s', `online`=1, `ts`=UNIX_TIMESTAMP(now()), pid=%d ON DUPLICATE KEY UPDATE `version_string`='%s', `ts`=UNIX_TIMESTAMP(now()), `online`=1, pid=%d",
  1856. SiteID, identity, _BUILD_STRING_, PID, _BUILD_STRING_, PID);
  1857. #ifdef DEBUG_ALL
  1858. LOG(tQBuf);
  1859. #endif
  1860. m_pDatabase->SilentQuery(tQBuf);
  1861. //*ServID = getServerID( identity );
  1862. // m_nServerID = *ServID;
  1863. if (*ServID)
  1864. {
  1865. // sprintf(tQBuf,"INSERT INTO nodes SET `site_id`=%d, `aux_id`='%d', `type`= 0, `online`=1, `name`='Server Node' ON DUPLICATE KEY UPDATE `online`=1", m_nSiteID, *ServID );
  1866. #ifdef DEBUG_ALL
  1867. LOG(tQBuf);
  1868. #endif
  1869. *ServNode = (uint32_t) m_pDatabase->QueryID(tQBuf);
  1870. // if( *ServNode == 0 ){
  1871. // *ServNode = getServerNode( *ServID );
  1872. // };
  1873. // m_nServerNodeID = *ServNode;
  1874. // Clenup Nodes and services ...
  1875. sprintf(tQBuf, "UPDATE nodes SET `online`=0 WHERE `server_id`=%d ", *ServID);
  1876. #ifdef DEBUG_ALL
  1877. LOG(tQBuf);
  1878. #endif
  1879. m_pDatabase->SilentQuery(tQBuf);
  1880. sprintf(tQBuf, "UPDATE cameras SET `online`=0 WHERE `site_id`=%d ", SiteID);
  1881. #ifdef DEBUG_ALL
  1882. LOG(tQBuf);
  1883. #endif
  1884. m_pDatabase->SilentQuery(tQBuf);
  1885. sprintf(tQBuf, "UPDATE media_streams SET `valid`=0 WHERE `site_id`=%d ", SiteID);
  1886. #ifdef DEBUG_ALL
  1887. LOG(tQBuf);
  1888. #endif
  1889. m_pDatabase->SilentQuery(tQBuf);
  1890. sprintf(tQBuf, "UPDATE media_server_streams SET `valid`=0, `online`=0 WHERE `site_id`=%d ", SiteID);
  1891. #ifdef DEBUG_ALL
  1892. LOG(tQBuf);
  1893. #endif
  1894. m_pDatabase->SilentQuery(tQBuf);
  1895. // cleanResources( tServerNodeID );
  1896. return setNodeOnline(0, 1); // m_nServerNodeID );
  1897. }
  1898. };
  1899. return false;
  1900. }
  1901. uint32_t servaMySQLDBC::registerVideoTransfer(uint32_t srcNode, CSTR uuid, uint32_t dataSize, CSTR fmt, uint32_t ts)
  1902. {
  1903. if (m_bIsConnected)
  1904. {
  1905. char tQBuf[MAX_PATH_LEN];
  1906. sprintf(tQBuf, "INSERT INTO `media_encoder_queue` SET `src`=%d, `uuid`='%s', `size`=%d, `fmt`='%s', `ts`=%d", srcNode, uuid, dataSize, fmt, ts);
  1907. #ifdef DEBUG_ALL
  1908. LOG(tQBuf);
  1909. #endif
  1910. return (uint32_t) m_pDatabase->QueryID(tQBuf);
  1911. };
  1912. return 0;
  1913. }
  1914. bool servaMySQLDBC::removeMediaComposerItem( uint64_t rec_id ){
  1915. if (m_bIsConnected)
  1916. {
  1917. char tQBuf[MAX_PATH_LEN];
  1918. sprintf(tQBuf, "DELETE FROM `media_composer_queue` WHERE `id`=%" PRIu64, rec_id );
  1919. #ifdef DEBUG_ALL
  1920. LOG(tQBuf);
  1921. #endif
  1922. m_pDatabase->SilentQuery(tQBuf);
  1923. return true;
  1924. };
  1925. return false;
  1926. }
  1927. bool servaMySQLDBC::removeRemoteMediaInfo(uint64_t id)
  1928. {
  1929. if (m_bIsConnected)
  1930. {
  1931. char tQBuf[MAX_PATH_LEN];
  1932. sprintf(tQBuf, "DELETE FROM `media_encoder_queue` WHERE `id`=%" PRIu64, id);
  1933. #ifdef DEBUG_ALL
  1934. LOG(tQBuf);
  1935. #endif
  1936. m_pDatabase->SilentQuery(tQBuf);
  1937. return true;
  1938. };
  1939. return false;
  1940. }
  1941. bool servaMySQLDBC::removeWebCmd(uint64_t id)
  1942. {
  1943. if (m_bIsConnected)
  1944. {
  1945. char tQBuf[MAX_PATH_LEN];
  1946. sprintf(tQBuf, "DELETE FROM `mem_web_queue` WHERE `id`=%" PRIu64, id);
  1947. #ifdef DEBUG_ALL
  1948. LOG(tQBuf);
  1949. #endif
  1950. m_pDatabase->SilentQuery(tQBuf);
  1951. return true;
  1952. };
  1953. return false;
  1954. }
  1955. bool servaMySQLDBC::unregisterServer()
  1956. {
  1957. if (setNodeOffline(0))
  1958. { // m_nServerNodeID ) ){
  1959. char tQBuf[CTEXT];
  1960. sprintf(tQBuf, "UPDATE servers SET `online`=0, `ts`=UNIX_TIMESTAMP(now()) WHERE `id`=%d", 1); // m_nServerID );
  1961. #ifdef DEBUG_ALL
  1962. LOG(tQBuf);
  1963. #endif
  1964. m_pDatabase->SilentQuery(tQBuf);
  1965. return true;
  1966. };
  1967. return false;
  1968. }
  1969. bool servaMySQLDBC::setNodeOnline(uint32_t NodeID, uint8_t status)
  1970. {
  1971. if (m_bIsConnected)
  1972. {
  1973. char tQBuf[CTEXT];
  1974. if (NodeID)
  1975. {
  1976. sprintf(tQBuf, "UPDATE nodes SET `online`=%d WHERE `id`=%d", status, NodeID);
  1977. #ifdef DEBUG_ALL
  1978. LOG(tQBuf);
  1979. #endif
  1980. m_pDatabase->SilentQuery(tQBuf);
  1981. sprintf(tQBuf, "UPDATE `resources` SET `active`=1 WHERE `node_id`=%d", NodeID);
  1982. #ifdef DEBUG_ALL
  1983. LOG(tQBuf);
  1984. #endif
  1985. m_pDatabase->SilentQuery(tQBuf);
  1986. return true;
  1987. };
  1988. };
  1989. return false;
  1990. }
  1991. bool servaMySQLDBC::setNodeOffline(uint32_t NodeID)
  1992. {
  1993. if (m_bIsConnected)
  1994. {
  1995. char tQBuf[CTEXT];
  1996. if (NodeID)
  1997. {
  1998. sprintf(tQBuf, "UPDATE nodes SET `online`=0 WHERE `id` = %d", NodeID);
  1999. #ifdef DEBUG_ALL
  2000. LOG(tQBuf);
  2001. #endif
  2002. m_pDatabase->SilentQuery(tQBuf);
  2003. sprintf(tQBuf, "UPDATE `resources` SET `active`=0 WHERE `node_id` = %d", NodeID);
  2004. #ifdef DEBUG_ALL
  2005. LOG(tQBuf);
  2006. #endif
  2007. m_pDatabase->SilentQuery(tQBuf);
  2008. return true;
  2009. };
  2010. };
  2011. return false;
  2012. }
  2013. bool servaMySQLDBC::sessionClose(uint64_t session_id)
  2014. {
  2015. if (m_bIsConnected)
  2016. {
  2017. char tQBuf[CTEXT];
  2018. sprintf(tQBuf, "UPDATE `sessions` SET `lts`=UNIX_TIMESTAMP(now()), `final`='Y' WHERE `id`=%" PRIu64, session_id);
  2019. #ifdef DEBUG_ALL
  2020. LOG(tQBuf);
  2021. #endif
  2022. m_pDatabase->SilentQuery(tQBuf);
  2023. return true;
  2024. };
  2025. return false;
  2026. }
  2027. uint64_t servaMySQLDBC::sessionCreate(uint64_t track_id, uint32_t ts, uint16_t tsms, CSTR uuid, char src)
  2028. {
  2029. if (m_bIsConnected)
  2030. {
  2031. char tQBuf[CTEXT];
  2032. sprintf(tQBuf, "INSERT INTO `sessions` SET `ts`=%d, `ts_ms`=%d, `lts`=UNIX_TIMESTAMP(now()), `track_id`=%" PRIu64 ", `uuid`='%s', `src`='%c'", ts, tsms, track_id, uuid, src);
  2033. #ifdef DEBUG_ALL
  2034. LOG(tQBuf);
  2035. #endif
  2036. return m_pDatabase->QueryID(tQBuf);
  2037. };
  2038. return 0;
  2039. }
  2040. bool servaMySQLDBC::sessionStatAddEvt(uint64_t session_id)
  2041. {
  2042. if (m_bIsConnected)
  2043. {
  2044. char tQBuf[CTEXT];
  2045. sprintf(tQBuf, "UPDATE `sessions` SET `evt_cnt`=`evt_cnt`+1 WHERE `id`=%" PRIu64, session_id);
  2046. #ifdef DEBUG_ALL
  2047. LOG(tQBuf);
  2048. #endif
  2049. m_pDatabase->SilentQuery(tQBuf);
  2050. return true;
  2051. };
  2052. return false;
  2053. }
  2054. bool servaMySQLDBC::sessionStatAddVid(uint64_t session_id)
  2055. {
  2056. if (m_bIsConnected)
  2057. {
  2058. char tQBuf[CTEXT];
  2059. sprintf(tQBuf, "UPDATE `sessions` SET `vid_cnt`=`vid_cnt`+1 WHERE `id`=%" PRIu64, session_id);
  2060. #ifdef DEBUG_ALL
  2061. LOG(tQBuf);
  2062. #endif
  2063. m_pDatabase->SilentQuery(tQBuf);
  2064. return true;
  2065. };
  2066. return false;
  2067. }
  2068. bool servaMySQLDBC::setCloudStatus(uint8_t Obj, uint64_t id, uint32_t status, CSTR sid)
  2069. {
  2070. if (m_bIsConnected)
  2071. {
  2072. char tQBuf[CTEXT];
  2073. uint32_t CTS = time(NULL);
  2074. if (sid)
  2075. {
  2076. sprintf(tQBuf, "INSERT INTO `mem_online_cloud` SET `object_id`=%" PRIu64 ", `object_type`=%d, `status`=%d, `ts`=%d, `SID`='%s' ON DUPLICATE KEY UPDATE `status`=%d, `ts`=%d, `SID`='%s'", id, Obj, status, CTS, sid, status, CTS, sid);
  2077. }
  2078. else
  2079. {
  2080. sprintf(tQBuf, "INSERT INTO `mem_online_cloud` SET `object_id`=%" PRIu64 ", `object_type`=%d, `status`=%d, `ts`=%d ON DUPLICATE KEY UPDATE `status`=%d, `ts`=%d", id, Obj, status, CTS, status, CTS);
  2081. };
  2082. #ifdef DEBUG_ALL
  2083. LOG(tQBuf);
  2084. #endif
  2085. m_pDatabase->SilentQuery(tQBuf);
  2086. return true;
  2087. };
  2088. return false;
  2089. }
  2090. bool servaMySQLDBC::updateEncodeFormat(uint64_t id, CSTR ext)
  2091. {
  2092. if (m_bIsConnected)
  2093. {
  2094. char tQBuf[1096];
  2095. sprintf(tQBuf, "UPDATE `media_encoder_queue` SET `fmt`='%s' WHERE `id`=%" PRIu64, ext, id);
  2096. #ifdef DEBUG_ALL
  2097. LOG(tQBuf);
  2098. #endif
  2099. m_pDatabase->SilentQuery(tQBuf);
  2100. return true;
  2101. };
  2102. return false;
  2103. }
  2104. bool servaMySQLDBC::updateEncodeStatus(uint64_t dbid, uint8_t status, uint8_t perc)
  2105. {
  2106. if (m_bIsConnected)
  2107. {
  2108. char tQBuf[1096];
  2109. sprintf(tQBuf, "UPDATE `media_encoder_queue` SET `status`=%d, `process`=%d WHERE `id`=%" PRIu64, status, perc, dbid);
  2110. #ifdef DEBUG_ALL
  2111. LOG(tQBuf);
  2112. #endif
  2113. m_pDatabase->SilentQuery(tQBuf);
  2114. return true;
  2115. };
  2116. return false;
  2117. }
  2118. bool servaMySQLDBC::updateMediaComposerItem( uint64_t rec_id, char status, uint8_t perc ){
  2119. if (m_bIsConnected)
  2120. {
  2121. char tQBuf[1096];
  2122. sprintf(tQBuf, "UPDATE `media_composer_queue` SET `status`='%c', `process`=%d WHERE `id`=%" PRIu64, status, perc, rec_id);
  2123. #ifdef DEBUG_ALL
  2124. LOG(tQBuf);
  2125. #endif
  2126. m_pDatabase->SilentQuery(tQBuf);
  2127. return true;
  2128. };
  2129. return false;
  2130. }
  2131. bool servaMySQLDBC::updateModBusRTU(uint64_t dbid, uint8_t status, uint8_t inputs, uint8_t outputs)
  2132. {
  2133. if (m_bIsConnected)
  2134. {
  2135. uint16_t values = inputs;
  2136. values = (values << 8) | outputs;
  2137. char tQBuf[MAX_PATH_LEN];
  2138. sprintf(tQBuf, "UPDATE `modbus_modules` SET `status`=%d, `values`=%d WHERE `id`=%" PRIu64, status, values, dbid);
  2139. #ifdef DEBUG_ALL
  2140. LOG(tQBuf);
  2141. #endif
  2142. m_pDatabase->SilentQuery(tQBuf);
  2143. return true;
  2144. };
  2145. return false;
  2146. }
  2147. bool servaMySQLDBC::updateModuleData(uint64_t DBID, uint32_t UPPER_ID, uint32_t BOTTOM_ID, uint32_t CAM_ID, uint32_t CAM_STREAM_ID, CSTR vstr, CSTR lstr)
  2148. {
  2149. if (m_bIsConnected)
  2150. {
  2151. char tQBuf[MAX_PATH_LEN];
  2152. sprintf(tQBuf, "UPDATE `metro_modules` SET `cam_stream`=%d, `top_id`=%d, `bottom_id`=%d, `cam_id`=%d, `tls_version`='%s', `lls_version`='%s' WHERE `id`=%" PRIu64, CAM_STREAM_ID, UPPER_ID, BOTTOM_ID, CAM_ID, vstr, lstr, DBID);
  2153. #ifdef DEBUG_ALL
  2154. LOG(tQBuf);
  2155. #endif
  2156. m_pDatabase->SilentQuery(tQBuf);
  2157. return true;
  2158. };
  2159. return false;
  2160. }
  2161. bool servaMySQLDBC::setServerStatValue(SERVER_STAT_ENUM ptp, uint64_t value)
  2162. {
  2163. if (m_bIsConnected)
  2164. {
  2165. char tQBuf[MAX_PATH_LEN];
  2166. sprintf(tQBuf, "INSERT INTO `mem_server_stats` SET `prop_enumerating`=%d, `prop_type`=1, `prop_value`='%" PRIu64 "' ON DUPLICATE KEY UPDATE `prop_value`='%" PRIu64 "'", ptp, value, value);
  2167. #ifdef DEBUG_ALL
  2168. LOG(tQBuf);
  2169. #endif
  2170. m_pDatabase->SilentQuery(tQBuf);
  2171. return true;
  2172. };
  2173. return false;
  2174. }
  2175. bool servaMySQLDBC::setServerStatValue(SERVER_STAT_ENUM ptp, int64_t value)
  2176. {
  2177. if (m_bIsConnected)
  2178. {
  2179. char tQBuf[MAX_PATH_LEN];
  2180. sprintf(tQBuf, "INSERT INTO `mem_server_stats` SET `prop_enumerating`=%d, `prop_type`=1, `prop_value`='%" PRIi64 "' ON DUPLICATE KEY UPDATE `prop_value`='%" PRIi64 "'", ptp, value, value);
  2181. #ifdef DEBUG_ALL
  2182. LOG(tQBuf);
  2183. #endif
  2184. m_pDatabase->SilentQuery(tQBuf);
  2185. return true;
  2186. };
  2187. return false;
  2188. }
  2189. bool servaMySQLDBC::setServerStatValue(SERVER_STAT_ENUM ptp, uint32_t value)
  2190. {
  2191. if (m_bIsConnected)
  2192. {
  2193. char tQBuf[MAX_PATH_LEN];
  2194. sprintf(tQBuf, "INSERT INTO `mem_server_stats` SET `prop_enumerating`=%d, `prop_type`=2, `prop_value`='%d' ON DUPLICATE KEY UPDATE `prop_value`='%d'", ptp, value, value);
  2195. #ifdef DEBUG_ALL
  2196. LOG(tQBuf);
  2197. #endif
  2198. m_pDatabase->SilentQuery(tQBuf);
  2199. return true;
  2200. };
  2201. return false;
  2202. }
  2203. bool servaMySQLDBC::setServerStatValue(SERVER_STAT_ENUM ptp, int32_t value)
  2204. {
  2205. if (m_bIsConnected)
  2206. {
  2207. char tQBuf[MAX_PATH_LEN];
  2208. sprintf(tQBuf, "INSERT INTO `mem_server_stats` SET `prop_enumerating`=%d, `prop_type`=2, `prop_value`='%d' ON DUPLICATE KEY UPDATE `prop_value`='%d'", ptp, value, value);
  2209. #ifdef DEBUG_ALL
  2210. LOG(tQBuf);
  2211. #endif
  2212. m_pDatabase->SilentQuery(tQBuf);
  2213. return true;
  2214. };
  2215. return false;
  2216. }
  2217. bool servaMySQLDBC::setServerStatValue(SERVER_STAT_ENUM ptp, float value)
  2218. {
  2219. if (m_bIsConnected)
  2220. {
  2221. char tQBuf[MAX_PATH_LEN];
  2222. sprintf(tQBuf, "INSERT INTO `mem_server_stats` SET `prop_enumerating`=%d, `prop_type`=3, `prop_value`='%.5f' ON DUPLICATE KEY UPDATE `prop_value`='%.5f'", ptp, value, value);
  2223. #ifdef DEBUG_ALL
  2224. LOG(tQBuf);
  2225. #endif
  2226. m_pDatabase->SilentQuery(tQBuf);
  2227. return true;
  2228. };
  2229. return false;
  2230. }
  2231. bool servaMySQLDBC::setServerStatValue(SERVER_STAT_ENUM ptp, CSTR value)
  2232. {
  2233. if (m_bIsConnected)
  2234. {
  2235. char tQBuf[MAX_PATH_LEN];
  2236. sprintf(tQBuf, "INSERT INTO `mem_server_stats` SET `prop_enumerating`=%d, `prop_type`=4, `prop_value`='%s' ON DUPLICATE KEY UPDATE `prop_value`='%s'", ptp, value, value);
  2237. #ifdef DEBUG_ALL
  2238. LOG(tQBuf);
  2239. #endif
  2240. m_pDatabase->SilentQuery(tQBuf);
  2241. return true;
  2242. };
  2243. return false;
  2244. }
  2245. bool servaMySQLDBC::setSystemProp(CSTR ptr, CSTR ptt)
  2246. {
  2247. if (m_bIsConnected)
  2248. {
  2249. char tQBuf[MAX_PATH_LEN];
  2250. sprintf(tQBuf, "UPDATE `system_props` SET `%s`='%s' WHERE `id`=1", ptr, ptt);
  2251. #ifdef DEBUG_ALL
  2252. LOG(tQBuf);
  2253. #endif
  2254. m_pDatabase->SilentQuery(tQBuf);
  2255. return true;
  2256. };
  2257. return false;
  2258. }
  2259. bool servaMySQLDBC::updateScadaPostStatus( uint64_t msg_id, uint8_t status ){
  2260. if( m_bIsConnected ){
  2261. char tQBuf[MAX_PATH_LEN];
  2262. sprintf(tQBuf, "UPDATE `metro_platforms_mboxes` SET `status`=%d WHERE `id`=%" PRIu64, status, msg_id );
  2263. #ifdef DEBUG_ALL
  2264. LOG(tQBuf);
  2265. #endif
  2266. m_pDatabase->SilentQuery(tQBuf);
  2267. return true;
  2268. };
  2269. return false;
  2270. }
  2271. bool servaMySQLDBC::updateScadaPostStatus( uint64_t platform_id, SERVER_SCADA_POST_TYPE mtyp, uint64_t src, uint8_t status ){
  2272. if( m_bIsConnected ){
  2273. char tQBuf[MAX_PATH_LEN];
  2274. if( mtyp == SCADA_POST_TYPE_HELTH_STROBE ){
  2275. sprintf(tQBuf, "UPDATE `metro_platforms_mboxes` SET `status`=%d WHERE `platform_id`=%" PRIu64 " AND `src`=%" PRIu64 " AND `type`=%d", status, platform_id, src, mtyp);
  2276. } else {
  2277. // For the Health status - all statuses below must be set same
  2278. sprintf(tQBuf, "UPDATE `metro_platforms_mboxes` SET `status`=%d WHERE `platform_id`=%" PRIu64 " AND `src`=%" PRIu64 " AND `type`<=%d", status, platform_id, src, mtyp);
  2279. };
  2280. #ifdef DEBUG_ALL
  2281. LOG(tQBuf);
  2282. #endif
  2283. m_pDatabase->SilentQuery(tQBuf);
  2284. return true;
  2285. };
  2286. return false;
  2287. }
  2288. bool servaMySQLDBC::updateServerUtilisation(DBC_SYS_LOAD_INFO * ptr)
  2289. {
  2290. bool rval = true;
  2291. if (ptr == NULL)
  2292. {
  2293. return false;
  2294. }
  2295. if (rval)
  2296. {
  2297. rval = setServerStatValue(SERVER_LTS, ptr->C_TS);
  2298. }
  2299. if (rval)
  2300. {
  2301. rval = setServerStatValue(SERVER_CPU_1, ptr->cpu1);
  2302. }
  2303. if (rval)
  2304. {
  2305. rval = setServerStatValue(SERVER_CPU_5, ptr->cpu5);
  2306. }
  2307. if (rval)
  2308. {
  2309. rval = setServerStatValue(SERVER_CPU_15, ptr->cpu15);
  2310. }
  2311. if (rval)
  2312. {
  2313. rval = setServerStatValue(SERVER_MEM_T, ptr->T_MEM);
  2314. }
  2315. if (rval)
  2316. {
  2317. rval = setServerStatValue(SERVER_MEM_C, ptr->C_MEM);
  2318. }
  2319. if (rval)
  2320. {
  2321. rval = setServerStatValue(SERVER_MEM, ptr->mem);
  2322. }
  2323. if (rval)
  2324. {
  2325. rval = setServerStatValue(SERVER_DISK_T, ptr->T_DISK);
  2326. }
  2327. if (rval)
  2328. {
  2329. rval = setServerStatValue(SERVER_DISK_C, ptr->C_DISK);
  2330. }
  2331. if (rval)
  2332. {
  2333. rval = setServerStatValue(SERVER_DISK, ptr->disk);
  2334. }
  2335. if (rval)
  2336. {
  2337. rval = setServerStatValue(SERVER_SYS_TEMP, ptr->temperature);
  2338. }
  2339. if (rval)
  2340. {
  2341. rval = setServerStatValue(SERVER_CPU_CORES, ptr->CPU_CORES);
  2342. }
  2343. return rval;
  2344. }
  2345. bool servaMySQLDBC::updateSessionFinal(uint64_t id, char BB )
  2346. {
  2347. if (m_bIsConnected)
  2348. {
  2349. char tQBuf[MAX_PATH_LEN];
  2350. sprintf(tQBuf, "UPDATE `sessions` SET `final`='%c' WHERE `id`=%" PRIu64, BB, id);
  2351. #ifdef DEBUG_ALL
  2352. LOG(tQBuf);
  2353. #endif
  2354. m_pDatabase->SilentQuery(tQBuf);
  2355. return true;
  2356. };
  2357. return false;
  2358. }
  2359. bool servaMySQLDBC::updateSessionSource(uint64_t id, char BB )
  2360. {
  2361. if (m_bIsConnected)
  2362. {
  2363. char tQBuf[MAX_PATH_LEN];
  2364. sprintf(tQBuf, "UPDATE `sessions` SET `src`='%c' WHERE `id`=%" PRIu64, BB, id);
  2365. #ifdef DEBUG_ALL
  2366. LOG(tQBuf);
  2367. #endif
  2368. m_pDatabase->SilentQuery(tQBuf);
  2369. return true;
  2370. };
  2371. return false;
  2372. }
  2373. bool servaMySQLDBC::updateSessionStatus(uint64_t id, uint8_t status)
  2374. {
  2375. if (m_bIsConnected)
  2376. {
  2377. char tQBuf[MAX_PATH_LEN];
  2378. sprintf(tQBuf, "UPDATE `sessions` SET `status`=%d, `lts`=UNIX_TIMESTAMP(now()) WHERE `id`=%" PRIu64, status, id);
  2379. #ifdef DEBUG_ALL
  2380. LOG(tQBuf);
  2381. #endif
  2382. m_pDatabase->SilentQuery(tQBuf);
  2383. return true;
  2384. };
  2385. return false;
  2386. }
  2387. bool servaMySQLDBC::updateWebCmdStatus(uint64_t id, uint8_t status)
  2388. {
  2389. if (m_bIsConnected)
  2390. {
  2391. char tQBuf[MAX_PATH_LEN];
  2392. sprintf(tQBuf, "UPDATE `mem_web_queue` SET `status`=%d WHERE `id`=%" PRIu64, status, id);
  2393. #ifdef DEBUG_ALL
  2394. LOG(tQBuf);
  2395. #endif
  2396. m_pDatabase->SilentQuery(tQBuf);
  2397. return true;
  2398. };
  2399. return false;
  2400. }
  2401. #undef LOG
  2402. #undef LOG_ERROR