/*  Copyright (C) 2012-2024 by László Nagy
    This file is part of Bear.

    Bear is a tool to generate compilation database for clang tooling.

    Bear is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    Bear is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

syntax = "proto3";

package rpc;

import "google/protobuf/timestamp.proto";
import "google/protobuf/empty.proto";
import "supervise.proto";

// Represents the remote sink of supervised process events.
//
// Events from a process execution can be sent from many actors (mostly
// supervisor processes). The events are collected in a common place
// in order to reconstruct of final report of a build process.
service Interceptor {

    // Register a process related events.
    rpc Register (Event) returns (google.protobuf.Empty) {}
}

// Represent a relevant life cycle event of a process.
//
// Currently it's only the process life cycle events (start, signal,
// terminate), but can be extended later with performance related
// events like monitoring the CPU usage or the memory allocation if
// those information are available.
message Event {

    // Required.
    uint64 rid = 1;

    // Required.
    // (ISO-8601 date-tie format with microsecond precision in UTC timezone)
    google.protobuf.Timestamp timestamp = 2;

    reserved 3 to 10;

    // Required.
    oneof event {
        Started started = 11;
        Terminated terminated = 12;
        Signalled signalled = 13;
    }

    // Represents a successful process execution.
    message Started {

        // Required.
        Execution execution = 1;

        // Required.
        uint32 pid = 2;

        // Optional.
        uint32 ppid = 3;
    }

    // Represents the termination of the supervised process.
    message Terminated {
        // Optional.
        // (Killed processes have no exit status.)
        int64 status = 1;
    }

    // Represents the supervised process received a signal.
    message Signalled {
        // Required.
        int32 number = 1;
    }
}
