require_relative '../../../../../gen/Design.ORiN3.Common/V1/orin3_common_pb' require_relative '../../../../../gen/Message.ORiN3.Provider/V1/orin3_base_object_pb' require_relative '../../../../../gen/Message.ORiN3.Provider/V1/orin3_base_object_services_pb' require_relative '../../../../grpc/orin3/provider/orin3_binary_converter' module O3P include Message::ORiN3::Provider::V1::AutoGenerated end module O3 include Design::ORiN3::Common::V1::AutoGenerated include Message::ORiN3::Provider::V1::AutoGenerated::BaseObject end module Grpc module Client module ORiN3 module Provider class ORiN3BaseObject attr_reader :orin3_object_type, :created_datetime, :name, :type_name, :option def initialize(channel, internal_id) begin @channel = channel @internal_id = internal_id sut = O3::BaseObjectService::Stub.new(nil, :this_channel_is_insecure, channel_override: @channel) request = O3::GetObjectInfoRequest.new(common: O3P::CommonRequest.new, id: @internal_id) response = sut.get_object_info(request) if (response.common.result_code != :SUCCEEDED) raise MessageClientError.new(response.common.result_code, response.common.detail) end @name = response.name @type_name = response.type_name @option = response.option @created_datetime = Grpc::ORiN3::Provider::DateTimeConverter.from_int64(response.created_datetime) @orin3_object_type = response.object_type @extra = response.extra rescue MessageClientError raise rescue StandardError => e raise MessageClientError.new(e) end end def id @internal_id.unpack('H*').first.gsub(/(.{8})(.{4})(.{4})(.{4})(.{12})/, '\1-\2-\3-\4-\5') end def get_tag(key) begin sut = O3::BaseObjectService::Stub.new(nil, :this_channel_is_insecure, channel_override: @channel) request = O3::GetTagRequest.new(common: O3P::CommonRequest.new, id: @internal_id, key: key) response = sut.get_tag(request) if (response.common.result_code != :SUCCEEDED) raise MessageClientError.new(response.common.result_code, response.common.detail) end return ORiN3BinaryConverter.deserialize(response.tag) rescue MessageClientError raise rescue StandardError => e raise raise MessageClientError.new(e) end end def set_tag(key, tag, type = nil) begin sut = O3::BaseObjectService::Stub.new(nil, :this_channel_is_insecure, channel_override: @channel) if type == ORiN3BinaryConverter::DataType::StringArray puts ORiN3BinaryConverter.serialize(tag, type).unpack('H*')[0].scan(/../).join(' ') end request = O3::SetTagRequest.new(common: O3P::CommonRequest.new, id: @internal_id, key: key, tag: ORiN3BinaryConverter.serialize(tag, type)) response = sut.set_tag(request) if (response.common.result_code != :SUCCEEDED) raise MessageClientError.new(response.common.result_code, response.common.detail) end rescue MessageClientError raise rescue StandardError => e raise MessageClientError.new(e) end end def get_tag_keys begin sut = O3::BaseObjectService::Stub.new(nil, :this_channel_is_insecure, channel_override: @channel) request = O3::GetTagKeysRequest.new(common: O3P::CommonRequest.new, id: @internal_id) response = sut.get_tag_keys(request) if (response.common.result_code != :SUCCEEDED) raise MessageClientError.new(response.common.result_code, response.common.detail) end return response.keys rescue MessageClientError raise rescue StandardError => e raise MessageClientError.new(e) end end def remove_tag(key) begin sut = O3::BaseObjectService::Stub.new(nil, :this_channel_is_insecure, channel_override: @channel) request = O3::RemoveTagRequest.new(common: O3P::CommonRequest.new, id: @internal_id, key: key) response = sut.remove_tag(request) if (response.common.result_code != :SUCCEEDED) raise MessageClientError.new(response.common.result_code, response.common.detail) end rescue MessageClientError raise rescue StandardError => e raise MessageClientError.new(e) end end def get_status begin sut = O3::BaseObjectService::Stub.new(nil, :this_channel_is_insecure, channel_override: @channel) request = O3::GetStatusRequest.new(common: O3P::CommonRequest.new, id: @internal_id) response = sut.get_status(request) if (response.common.result_code != :SUCCEEDED) raise MessageClientError.new(response.common.result_code, response.common.detail) end return response.status rescue MessageClientError raise rescue StandardError => e raise MessageClientError.new(e) end end def execute(command_name) end def execute(command_name, argument) end private attr_reader :internal_id end end end end end