/*
	Copyright The containerd Authors.

	Licensed under the Apache License, Version 2.0 (the "License");
	you may not use this file except in compliance with the License.
	You may obtain a copy of the License at

		http://www.apache.org/licenses/LICENSE-2.0

	Unless required by applicable law or agreed to in writing, software
	distributed under the License is distributed on an "AS IS" BASIS,
	WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
	See the License for the specific language governing permissions and
	limitations under the License.
*/

syntax = "proto3";

package containerd.runtime.linux.shim.v1;

import "google/protobuf/any.proto";
import "google/protobuf/empty.proto";
import "google/protobuf/timestamp.proto";
import "github.com/containerd/containerd/api/types/mount.proto";
import "github.com/containerd/containerd/api/types/task/task.proto";

option go_package = "github.com/containerd/containerd/runtime/v1/shim/v1;shim";

// Shim service is launched for each container and is responsible for owning the IO
// for the container and its additional processes.  The shim is also the parent of
// each container and allows reattaching to the IO and receiving the exit status
// for the container processes.
service Shim {
	// State returns shim and task state information.
	rpc State(StateRequest) returns (StateResponse);

	rpc Create(CreateTaskRequest) returns (CreateTaskResponse);

	rpc Start(StartRequest) returns (StartResponse);

	rpc Delete(google.protobuf.Empty) returns (DeleteResponse);

	rpc DeleteProcess(DeleteProcessRequest) returns (DeleteResponse);

	rpc ListPids(ListPidsRequest) returns (ListPidsResponse);

	rpc Pause(google.protobuf.Empty) returns (google.protobuf.Empty);

	rpc Resume(google.protobuf.Empty) returns (google.protobuf.Empty);

	rpc Checkpoint(CheckpointTaskRequest) returns (google.protobuf.Empty);

	rpc Kill(KillRequest) returns (google.protobuf.Empty);

	rpc Exec(ExecProcessRequest) returns (google.protobuf.Empty);

	rpc ResizePty(ResizePtyRequest) returns (google.protobuf.Empty);

	rpc CloseIO(CloseIORequest) returns (google.protobuf.Empty);

	// ShimInfo returns information about the shim.
	rpc ShimInfo(google.protobuf.Empty) returns (ShimInfoResponse);

	rpc Update(UpdateTaskRequest) returns (google.protobuf.Empty);

	rpc Wait(WaitRequest) returns (WaitResponse);
}

message CreateTaskRequest {
	string id = 1;
	string bundle = 2;
	string runtime = 3;
	repeated containerd.types.Mount rootfs = 4;
	bool terminal = 5;
	string stdin = 6;
	string stdout = 7;
	string stderr = 8;
	string checkpoint = 9;
	string parent_checkpoint = 10;
	google.protobuf.Any options = 11;
}

message CreateTaskResponse {
	uint32 pid = 1;
}

message DeleteResponse {
	uint32 pid = 1;
	uint32 exit_status = 2;
	google.protobuf.Timestamp exited_at = 3;
}

message DeleteProcessRequest {
	string id = 1;
}

message ExecProcessRequest {
	string id = 1;
	bool terminal = 2;
	string stdin = 3;
	string stdout = 4;
	string stderr = 5;
	google.protobuf.Any spec = 6;
}

message ExecProcessResponse {
}

message ResizePtyRequest {
	string id = 1;
	uint32 width = 2;
	uint32 height = 3;
}

message StateRequest {
	string id = 1;
}

message StateResponse {
	string id = 1;
	string bundle = 2;
	uint32 pid = 3;
	containerd.v1.types.Status status = 4;
	string stdin = 5;
	string stdout = 6;
	string stderr = 7;
	bool terminal = 8;
	uint32 exit_status = 9;
	google.protobuf.Timestamp exited_at = 10;
}

message KillRequest {
	string id = 1;
	uint32 signal = 2;
	bool all = 3;
}

message CloseIORequest {
	string id = 1;
	bool stdin = 2;
}

message ListPidsRequest {
	string id = 1;
}

message ListPidsResponse {
	repeated containerd.v1.types.ProcessInfo processes = 1;
}

message CheckpointTaskRequest {
	string path = 1;
	google.protobuf.Any options = 2;
}

message ShimInfoResponse {
	uint32 shim_pid = 1;
}

message UpdateTaskRequest {
	google.protobuf.Any resources = 1;
}

message StartRequest {
	string id = 1;
}

message StartResponse {
	string id = 1;
	uint32 pid = 2;
}

message WaitRequest {
	string id = 1;
}

message WaitResponse {
	uint32 exit_status = 1;
	google.protobuf.Timestamp exited_at = 2;
}
