API Reference
secDetector provides an SDK for external systems. This section describes the APIs required for developing applications. There are only three APIs and two header files.
Header files:
secDetector/secDetector_sdk.h: contains API definitions.
secDetector/secDetector_topic.h: contains predefined macros required for calling APIs, such as the ID of a topic that can be subscribed to.
secSub
API for subscribing to topics.
Functions:
This API is used by applications to subscribe to different topics by specifying topic IDs, for example, file opening exception probes. You can view the definitions of topic IDs provided by secDetector in secDetector_topic.h. This API can be used to subscribe to multiple topics at a time. The topic IDs of multiple probes can be combined in bitmap format.
NOTE: A subscription generates a message reader. An application needs to subscribe to all required topics in a subscription API call. In this way, a reader can be used to collect messages. To change the subscribed topics, you can unsubscribe from the topics and subscribe to them again.
Function declaration:
void *secSub(const int topic);
Parameters:
- topic: input parameter, which specifies a set of topics to be subscribed to.
Return values:
- NULL: The subscription fails.
- NOT NULL: gRPC reader of the subscribed topics.
secUnsub
API for unsubscribing from topics.
Functions:
This API is used by applications to unsubscribe from topics by entering the reader obtained after the subscription is successful. After the unsubscription, applications will not receive messages from the unsubscribed topics. If a topic is not subscribed to by any application, it will not be executed.
Function declaration:
void secUnsub(void *reader);
Parameters:
- reader: input parameter, which specifies the message reader to be unsubscribed from.
Return values:
- None
secReadFrom
API for reading messages from subscribed topics.
Functions:
After a topic is successfully subscribed to using the subscription API, you can use this API to receive messages of the subscribed topic from secDetector before unsubscribing from the topic. This API is in blocking mode. It is recommended that applications use an independent thread to call the API cyclically. This function can be resumed only when there are messages in the subscribed topic.
Function declaration:
void secReadFrom(void *reader, char *data, int data_len);
Parameters:
- reader: input parameter, which specifies the message reader obtained after the subscription is successful.
- data: output parameter, which specifies the message buffer, a segment of memory provided by an application.
- data_len: input parameter, which specifies the size of the message buffer.
Return values:
- None