-
Notifications
You must be signed in to change notification settings - Fork 4
plugin sdk lifecycle
Understanding the plugin lifecycle is crucial for proper initialization, operation, and cleanup.
flowchart TB
Start[Plugin starts] --> Constructor
subgraph Phase1[" "]
Constructor["1. Constructor called<br/>Engine, Logger, Culture are NULL<br/>PluginGuid is Guid.Empty"]
end
Constructor --> Initialize
subgraph Phase2[" "]
Initialize["2. Initialize(engine, roleGuid, culture) called<br/>Engine, PluginGuid, Logger, Culture populated<br/>Report filters set and handlers registered"]
end
Initialize --> Loaded
subgraph Phase3[" "]
Loaded["3. OnPluginLoaded() called<br/>Called by Initialize()"]
end
Loaded --> Database
subgraph Phase4[" "]
Database["4. Database layer initialized (if IPluginDatabaseSupport)<br/>SetDatabaseInformation and start state machine"]
end
Database --> Started
subgraph Phase5[" "]
Started["5. OnPluginStart() called<br/>Database state may still be connecting"]
end
Started --> Running
subgraph Phase6[" "]
Running["6. Plugin runs<br/>Process queries, handle events/actions<br/>Update entity states"]
end
Running --> Shutdown[7. Plugin shutdown initiated]
Shutdown --> Dispose
subgraph Phase7[" "]
Dispose["8. Dispose() called<br/>Unsubscribe events, stop workers<br/>Dispose resources"]
end
Dispose --> Destroyed[9. Plugin instance destroyed]
| Method | When called | Purpose |
|---|---|---|
Constructor |
Plugin instantiation | Initialize member variables only |
Initialize() |
Called by the plugin host | Set base properties and run OnPluginLoaded()
|
OnPluginLoaded() |
End of Initialize()
|
Register handlers, filters, and services |
OnPluginStart() |
After database layer starts (if supported) | Start background work and runtime processing |
Dispose() |
Plugin shutdown | Clean up resources and unsubscribe events |
What's available:
- Engine - null
- Logger - null
- PluginGuid - Guid.Empty
- Culture - null
Initialize member variables only.
public MyPlugin()
{
m_httpClient = new HttpClient();
m_cancellation = new CancellationTokenSource();
}Do not access Engine, Logger, or PluginGuid in the constructor.
Called by the plugin host. Do not override this method.
What happens:
-
Engine,PluginGuid,Logger, andCultureare set - Report filters are applied from
SupportedQueriesandSupportedCustomReports - Query and entity event handlers are registered
-
OnPluginLoaded()is called
This work is handled by the base Plugin class.
First lifecycle method where you can use the Engine.
What's available:
- Engine - fully initialized
- Logger - ready to use
- PluginGuid - your role GUID
- Culture - current culture
- Database - may not be ready (if using database support)
What to do:
protected override void OnPluginLoaded()
{
// Set up event filters
Engine.SetEventFilter(new List<EventType>
{
EventType.AccessGranted,
EventType.DoorOpenedTooLong
});
// Subscribe to events
Engine.EventReceived += OnEventReceived;
Engine.ActionReceived += OnActionReceived;
Engine.EntitiesInvalidated += OnEntitiesInvalidated;
// Register request handlers using Plugin's protected helper methods
AddRequestHandler<MyRequest, MyResponse>(HandleRequest);
// Initialize services (but don't start long-running work yet)
InitializeExternalConnection();
// Report initial state
ModifyPluginState(new PluginStateEntry("Startup", "Plugin loaded"));
}What not to do:
- Do not start background workers yet
- Do not access the database yet (if using database support)
- Do not perform long-running initialization
Called after the database layer starts (if supported). The database state can still be connecting.
What's available:
- Engine - fully initialized
- Database state - may still be connecting (if using database support)
What to do:
protected override void OnPluginStart()
{
// Start background workers
m_backgroundWorker = Task.Run(() => BackgroundWork(m_cancellation.Token));
// Begin data processing
StartDataProcessing();
// Report ready state
ModifyPluginState(new PluginStateEntry("Running", "Plugin started"));
}This is the right place to:
- Start background workers
- Begin periodic tasks
- Start data processing
- Perform initialization that does not require a connected database
For database-dependent work, wait for DatabaseState.Connected in OnDatabaseStateChanged().
Called when the plugin is shutting down.
What to do:
protected override void Dispose(bool disposing)
{
if (disposing)
{
// Unsubscribe from all events
Engine.EventReceived -= OnEventReceived;
Engine.ActionReceived -= OnActionReceived;
Engine.EntitiesInvalidated -= OnEntitiesInvalidated;
// Stop background workers
m_cancellation?.Cancel();
// Remove request handlers
RemoveRequestHandler<MyRequest, MyResponse>(HandleRequest);
// Dispose managed resources
m_httpClient?.Dispose();
m_databaseConnection?.Dispose();
}
}Critical rules:
- Unsubscribe from events
- Stop background workers
- Dispose managed resources
- Handle partially initialized state
When a plugin implements IPluginDatabaseSupport, initialization happens in this order:
- Constructor
- Initialize() - base initialization and
OnPluginLoaded()runs - DatabaseManager.SetDatabaseInformation() - connection info provided
- Database layer created - reads
GetDatabaseUpgradeItems() - Database state machine starts
- Creating state calls
GetSpecificCreationScript()when database is missing - Upgrading state runs upgrade items when version is behind
- OnDatabaseStateChanged() notifications for database state changes
- OnPluginStart() is called
This means:
- In
OnPluginLoaded(), database may not be ready -
OnPluginStart()does not guaranteeDatabaseState.Connected - Use
OnDatabaseStateChanged()to wait forDatabaseState.Connected
See Plugin SDK Database for details.
Lifecycle methods are called by the plugin host. Callbacks from timers and task continuations run on background threads.
Key points:
- Use
Engine.QueueUpdate()orEngine.QueueUpdateAndWait()to update entities from background work
Example: queue an entity update from a timer callback.
private void OnTimerElapsed(object sender, ElapsedEventArgs e)
{
Engine.QueueUpdate(() =>
{
var entity = Engine.GetEntity<CustomEntity>(m_entityGuid);
entity.RunningState = State.Running;
});
}See Plugin SDK Threading for detailed threading patterns, QueueUpdate usage, async/await considerations, and background worker examples.
- Plugin SDK Overview - Plugin architecture and components
- Plugin SDK Threading - Threading model, QueueUpdate, async patterns
- Plugin SDK Events - Event subscription and handling
- Plugin SDK Queries - Query processing called during runtime
- Plugin SDK Database - Database initialization timing
- Plugin SDK State Management - Reporting state during lifecycle
-
Security Center SDK Developer Guide Overview of the SDK framework and how to build integrations with Security Center.
-
Platform SDK
- Platform SDK Overview Introduction to the Platform SDK and core concepts.
- SDK Certificates Details certificates, licensing, and connection validation.
- Entity Guide Explains the core entity model, inheritance, and how to work with entities.
- Entity Cache Guide Describes the engine's local entity cache and synchronization.
- SDK Transactions Covers batching operations for performance and consistency.
- ReportManager Querying entities and activity data from Security Center.
- Events and Actions Subscribing to events and handling actions.
- Logging with the Genetec SDK How to configure logging, diagnostics, and debug methods.
- Referencing SDK Assemblies Best practices for referencing assemblies and resolving them at runtime.
- SDK Compatibility Guide Understanding backward compatibility and versioning in the SDK.
-
Plugin SDK
- Plugin SDK Overview Introduction to plugin architecture and capabilities.
- Plugin SDK Certificates SDK certificate requirements for plugin roles.
- Plugin SDK Lifecycle Initialization and disposal patterns.
- Plugin SDK Threading Threading model, QueueUpdate, and async patterns.
- Plugin SDK Configuration Configuration storage and monitoring.
- Plugin SDK Restricted Configuration Secure credential storage and admin-only configuration.
- Plugin SDK Database Database integration and schema management.
- Plugin SDK Events Event subscription and handling.
- Plugin SDK Queries Query processing and response handling.
- Plugin SDK Request Manager Request/response communication with clients.
- Plugin SDK Entity Ownership Understanding plugin-owned entities, running state management, and ownership release.
- Plugin SDK Entity Mappings Using EntityMappings for plugin-specific configuration and external system integration.
- Plugin SDK State Management Reporting plugin health and diagnostics.
- Plugin SDK Server Management High availability and server failover.
- Custom Privileges Defining and enforcing custom privileges.
- Resolving Non-SDK Assemblies Handling third-party dependencies in plugins and workspace modules.
- Deploying Plugins Registering and deploying plugins and workspace modules.
-
Workspace SDK
- Workspace SDK Overview Introduction to client-side UI extensions for Security Desk and Config Tool.
- Creating Modules Module lifecycle, registration patterns, and assembly resolution.
- Tasks and Pages Menu items, page content, and navigation.
- Components Dashboard widgets, tiles, maps, credentials, and content builders.
- Tile Extensions Custom tile widgets, views, and properties panels.
- Services Built-in services for dialogs, maps, alarms, badges, and more.
- Contextual Actions Right-click context menu extensions.
- Options Extensions Custom settings pages in application preferences.
- Monitors Multi-monitor support and shared components.
- Commands Command execution, evaluation, and interception.
- Extending Events Adding custom fields to Security Center events.
- Map Extensions Custom map objects, layers, and providers.
- Timeline Providers Custom timeline event sources for video playback.
-
Macro SDK
- Macro SDK Overview How macros work, creating and configuring macro entities, automation, and monitoring.
- Macro SDK Developer Guide Developing macro code with the UserMacro class and Security Center SDK.
-
- Getting Started Setup, authentication, and basic configuration for the Web SDK.
- Referencing Entities Entity discovery, search capabilities, and parameter formats.
- Entity Operations CRUD operations, multi-value fields, and method execution.
- Partitions Managing partitions, entity membership, and user access control.
- Custom Fields Creating, reading, writing, and filtering custom entity fields.
- Custom Card Formats Managing custom credential card format definitions.
- Actions Control operations for doors, cameras, macros, and notifications.
- Events and Alarms Real-time event monitoring, alarm monitoring, and custom events.
- Incidents Incident management, creation, and attachment handling.
- Reports Activity reports, entity queries, and historical data retrieval.
- Performance Guide Optimization tips and best practices for efficient API usage.
- Reference Entity GUIDs, EntityType enumeration, and EventType enumeration.
- Under the Hood Technical architecture, query reflection, and SDK internals.
- Troubleshooting Common error resolution and debugging techniques.
- Media Gateway Guide Setup and configuration of the Media Gateway role for video streaming.
- Web Player Guide Complete guide to integrating GWP for live and playback video streaming.
- Web Player API Reference Full API documentation with interfaces, methods, properties, and events.
- Web Player Sample Application Comprehensive demo showcasing all GWP features with timeline and PTZ controls.
- Genetec Web Player Multiplexing Sample Multi-camera grid demo using a shared WebSocket connection.