// @file sns_client_batch.proto
//
// @brief Defines message types for the Client Batch Sensor.
//
// @copyright
// Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries.
// All Rights Reserved.
// Confidential and Proprietary - Qualcomm Technologies, Inc.
//
// @details The Client Batch Sensor stores events of the requested
// Sensor Type in DDR along with UTC Time and Time Zone information.
// It delivers them to the client on request at a later point.
// Events are by default stored in main memory.
//
// The target sensor is identified by the SUID provided as part of the request.
// Each instance of the Client Batch Sensor shall support one target SUID only.
// Events will be batched until memory is exhausted, or the client issues a
// flush request. When either of this happens all batched events will be published
// and batch memory will be freed for it to continue batching subsequent events.
//
// This sensor supports batching requests only from external clients.
//
// ## Attribute Requirements:
// Client Batch Sensor must support the following attributes
// 1. SNS_STD_SENSOR_ATTRID_TYPE: "client_batch"
// 2. SNS_STD_SENSOR_ATTRID_STREAM_TYPE: SNS_STD_SENSOR_STREAM_TYPE_ON_CHANGE
// 3. SNS_STD_SENSOR_ATTRID_API attribute contains "sns_client_batch.proto"
//
// ## Processing Stream Requests:
// 1. A request message with message id SNS_CLIENT_BATCH_MSGID_SNS_CLIENT_BATCH_CONFIG
//    and payload sns_client_batch_config is used to start batching by the Client Batch Sensor.
//    If a subsequent request is received with a different SUID, that request will be rejected.
// 2. SNS_STD_MSGID_SNS_STD_FLUSH_REQ supported by the Client Batch Sensor as defined
//    in sns_std.proto. It will publish all stored events and after
//    flushing is complete reports a SNS_STD_MSGID_SNS_STD_FLUSH_EVENT.
//
// ## Publishing Stream Events:
// Client Batch Sensor generates events with message id
// SNS_CLIENT_BATCH_MSGID_SNS_CLIENT_BATCH_EVENT and payload sns_client_batch_event.
// 1. When a flush request is received or when memory is exhausted the Client Batch Sensor publishes
//    sns_client_batch_event messages each containing a stored event.
// 2. The timestamp of each sns_client_batch_event will correspond to the timestamp of the stored
//    Sensor event.
// 3. client batch sensor will publish SNS_CLIENT_BATCH_MSGID_SNS_CLIENT_BATCH_COMPLETE_EVENT at the
//    end of every batch

syntax = "proto2";
import "nanopb.proto";
import "sns_std_type.proto";

// @brief Message IDs for Client Batch Sensor.
enum sns_client_batch_msgid
{
  option (nanopb_enumopt).long_names = false;

  // @brief Message ID for configuring and activating the sensor.
  SNS_CLIENT_BATCH_MSGID_SNS_CLIENT_BATCH_CONFIG = 122;

  // @brief Message ID of events generated by the sensor.
  SNS_CLIENT_BATCH_MSGID_SNS_CLIENT_BATCH_EVENT  = 259;

  // @brief Message ID of the event generated at the end of every batch.
  SNS_CLIENT_BATCH_MSGID_SNS_CLIENT_BATCH_COMPLETE_EVENT = 260;
}

// @brief Client Batch Sensor will start storing all events
// specified through batch_msg_ids coming from requested SUID.
message sns_client_batch_config
{
  // @brief UID of the Sensor to be logged.
  optional sns_std_suid suid = 1;

  // @brief Island batching mode (default is false).
  // When false (default), Client Batch Sensor will use main memory batching.
  // When true, Client Batch Sensor will use island (low-power) batching mode.
  optional bool island_batching_mode = 2;

  // @brief Msg Ids of the underlying sensor to be batched.
  // All other events will be dropped.
  repeated uint32 batch_msg_ids = 3 [(nanopb).max_count = 10];
}

// @brief Client Batch Event
// Used to publish stored Events for the requested SUID.
message sns_client_batch_event
{
  // @brief UTC Time in seconds (since 1/1/1970 00:00:00).
  optional uint64 utc_time = 1;

  // @brief Time Zone in seconds.
  optional sint32 time_zone = 2;

  // @brief Message ID of the event.
  optional uint32 msg_id = 3;

  // @brief The event as binary payload.
  //  See specific proto file for definition of the event.
  repeated bytes event_payload = 4;
}

// @brief client batch complete event
// Associated message ID : SNS_CLIENT_BATCH_MSGID_SNS_CLIENT_BATCH_COMPLETE_EVENT
// Client Batch sensor will append this batch complete event at the end of every batch.
message sns_client_batch_complete
{
//empty message
}
