#pragma once #ifndef ANSCLOUD_DEVICE_AGENT_H #define ANSCLOUD_DEVICE_AGENT_H #include #include #include #include #include #include #ifdef ANSCLOUD_DEVICE_EXPORTS #define ANSCLOUD_DEVICE_API __declspec(dllexport) #else #define ANSCLOUD_DEVICE_API __declspec(dllimport) #endif namespace anscloud { //============================================================================= // DeviceAgent Configuration //============================================================================= struct DeviceAgentConfig { BrokerConfig broker; DeviceCredentials credentials; // Telemetry intervals (seconds) int heartbeat_interval_sec = 30; int metrics_interval_sec = 60; int snapshot_interval_sec = 0; // 0 = disabled // Device info std::string firmware_version; std::string ansvis_version; std::string ip_address; std::string local_api_endpoint; // e.g. "http://127.0.0.1:8080" }; //============================================================================= // Application callback types - your app implements these //============================================================================= using CommandHandler = std::function; using MetricsProvider = std::function; using CameraListProvider = std::function()>; using InferenceProvider = std::function; using SnapshotProvider = std::function; // returns base64 JPEG //============================================================================= // Agent runtime status //============================================================================= struct AgentStatus { bool connected = false; bool running = false; uint64_t uptime_seconds = 0; uint64_t commands_received = 0; uint64_t commands_executed = 0; uint64_t heartbeats_sent = 0; uint64_t telemetry_sent = 0; uint64_t events_published = 0; uint64_t reconnect_count = 0; std::string last_error; }; //============================================================================= // DeviceAgent - AIBOX cloud agent // // Inject your existing RabbitMQ C++ API via BrokerFactory: // // DeviceAgent agent([](){ return std::make_unique(); }); // agent.configure(config); // agent.set_command_handler(...); // agent.start(); // non-blocking // //============================================================================= class ANSCLOUD_DEVICE_API DeviceAgent { public: // Construct with broker factory (your RabbitMQ API) explicit DeviceAgent(BrokerFactory factory); ~DeviceAgent(); // Non-copyable, movable DeviceAgent(const DeviceAgent&) = delete; DeviceAgent& operator=(const DeviceAgent&) = delete; DeviceAgent(DeviceAgent&&) noexcept; DeviceAgent& operator=(DeviceAgent&&) noexcept; //--- Configuration (call before start) ----------------------------------- void configure(const DeviceAgentConfig& config); void set_command_handler(CommandHandler handler); void set_metrics_provider(MetricsProvider provider); void set_camera_list_provider(CameraListProvider provider); void set_inference_provider(InferenceProvider provider); void set_snapshot_provider(SnapshotProvider provider); //--- Lifecycle (non-blocking) -------------------------------------------- bool start(); // Connects, declares queues, starts background threads void stop(); // Publishes offline, disconnects, stops threads bool is_running() const; bool is_connected() const; //--- Manual publishing --------------------------------------------------- void publish_event(const DeviceEvent& event); void publish_telemetry(const DeviceTelemetry& telemetry); void send_heartbeat_now(); void send_metrics_now(); //--- Status & callbacks -------------------------------------------------- AgentStatus get_status() const; void on_connection_changed(ConnectionCallback cb); void on_error(ErrorCallback cb); void on_broadcast(std::function cb); private: class Impl; std::unique_ptr m_impl; }; } // namespace anscloud #endif // ANSCLOUD_DEVICE_AGENT_H