Skip to content

Commit

Permalink
Remove id from Session message (#784)
Browse files Browse the repository at this point in the history
* Remove id from Session message type.
Motivation:
* Having both name and id is somewhat confusing
* It makes using the session in interactive tools like bloom RPC difficult, since oneof is a little complex to use.

I don't think ID should ever be used.  There are a lot of advantages to keeping the data on the wire "time invariant" or independent on server state.  For example we are trying to do batching to improve throughput when doing "cloud based measurements" as part of various LTIs and hopefully products.

Even if we remove id we can still maintain the current behavior by generating a name if the client does not specify.
Clients who use name should not need to make any changes to their code.
The wire format does not break for clients who use name so we don't even need to require clients change.
The wire format does not really break for clients that use id since they can't set it and our server will stop setting it.
Clients who use id should be treating Session as an opaque structure since there is nothing they can do with name.
  • Loading branch information
ccifra authored Nov 14, 2022
1 parent 4d287b9 commit ca6a68a
Show file tree
Hide file tree
Showing 71 changed files with 3,803 additions and 3,955 deletions.
626 changes: 311 additions & 315 deletions generated/nidaqmx/nidaqmx_service.cpp

Large diffs are not rendered by default.

310 changes: 154 additions & 156 deletions generated/nidcpower/nidcpower_service.cpp

Large diffs are not rendered by default.

278 changes: 138 additions & 140 deletions generated/nidigitalpattern/nidigitalpattern_service.cpp

Large diffs are not rendered by default.

194 changes: 96 additions & 98 deletions generated/nidmm/nidmm_service.cpp

Large diffs are not rendered by default.

163 changes: 80 additions & 83 deletions generated/nifake/nifake_service.cpp

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion generated/nifake_extension/nifake_extension_service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ namespace nifake_extension_grpc {
}
try {
auto vi_grpc_session = request->vi();
ViSession vi = session_repository_->access_session(vi_grpc_session.id(), vi_grpc_session.name());
ViSession vi = session_repository_->access_session(vi_grpc_session.name());
ViInt32 param = request->param();
auto status = library_->AddCoolFunctionality(vi, param);
if (!status_ok(status)) {
Expand Down
77 changes: 35 additions & 42 deletions generated/nifake_non_ivi/nifake_non_ivi_service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ namespace nifake_non_ivi_grpc {
}
try {
auto handle_grpc_session = request->handle();
FakeHandle handle = session_repository_->access_session(handle_grpc_session.id(), handle_grpc_session.name());
session_repository_->remove_session(handle_grpc_session.id(), handle_grpc_session.name());
FakeHandle handle = session_repository_->access_session(handle_grpc_session.name());
session_repository_->remove_session(handle_grpc_session.name());
auto status = library_->Close(handle);
if (!status_ok(status)) {
return ConvertApiErrorStatusForFakeHandle(context, status, handle);
Expand All @@ -83,8 +83,8 @@ namespace nifake_non_ivi_grpc {
}
try {
auto secondary_session_handle_grpc_session = request->secondary_session_handle();
SecondarySessionHandle secondary_session_handle = secondary_session_handle_resource_repository_->access_session(secondary_session_handle_grpc_session.id(), secondary_session_handle_grpc_session.name());
secondary_session_handle_resource_repository_->remove_session(secondary_session_handle_grpc_session.id(), secondary_session_handle_grpc_session.name());
SecondarySessionHandle secondary_session_handle = secondary_session_handle_resource_repository_->access_session(secondary_session_handle_grpc_session.name());
secondary_session_handle_resource_repository_->remove_session(secondary_session_handle_grpc_session.name());
auto status = library_->CloseSecondarySession(secondary_session_handle);
if (!status_ok(status)) {
return ConvertApiErrorStatusForSecondarySessionHandle(context, status, secondary_session_handle);
Expand All @@ -106,20 +106,19 @@ namespace nifake_non_ivi_grpc {
}
try {
auto handle_grpc_session = request->handle();
FakeHandle handle = session_repository_->access_session(handle_grpc_session.id(), handle_grpc_session.name());
FakeHandle handle = session_repository_->access_session(handle_grpc_session.name());

auto initiating_session_id = session_repository_->access_session_id(handle_grpc_session.id(), handle_grpc_session.name());
auto initiating_session_name = handle_grpc_session.name();
auto init_lambda = [&] () {
FakeCrossDriverHandle cross_driver_session;
int status = library_->GetCrossDriverSession(handle, &cross_driver_session);
return std::make_tuple(status, cross_driver_session);
};
uint32_t session_id = 0;
const std::string& grpc_device_session_name = request->session_name();
int status = fake_cross_driver_handle_resource_repository_->add_dependent_session(grpc_device_session_name, init_lambda, initiating_session_id, session_id);
std::string session_name = request->session_name();
int status = fake_cross_driver_handle_resource_repository_->add_dependent_session(session_name, init_lambda, initiating_session_name);
response->set_status(status);
if (status == 0) {
response->mutable_cross_driver_session()->set_id(session_id);
response->mutable_cross_driver_session()->set_name(session_name);
}
return ::grpc::Status::OK;
}
Expand Down Expand Up @@ -200,7 +199,7 @@ namespace nifake_non_ivi_grpc {
}
try {
auto handle_grpc_session = request->handle();
FakeHandle handle = session_repository_->access_session(handle_grpc_session.id(), handle_grpc_session.name());
FakeHandle handle = session_repository_->access_session(handle_grpc_session.name());
int32 attribute;
switch (request->attribute_enum_case()) {
case nifake_non_ivi_grpc::GetMarbleAttributeDoubleRequest::AttributeEnumCase::kAttribute: {
Expand Down Expand Up @@ -243,7 +242,7 @@ namespace nifake_non_ivi_grpc {
}
try {
auto handle_grpc_session = request->handle();
FakeHandle handle = session_repository_->access_session(handle_grpc_session.id(), handle_grpc_session.name());
FakeHandle handle = session_repository_->access_session(handle_grpc_session.name());
int32 attribute;
switch (request->attribute_enum_case()) {
case nifake_non_ivi_grpc::GetMarbleAttributeInt32Request::AttributeEnumCase::kAttribute: {
Expand Down Expand Up @@ -292,7 +291,7 @@ namespace nifake_non_ivi_grpc {
}
try {
auto handle_grpc_session = request->handle();
FakeHandle handle = session_repository_->access_session(handle_grpc_session.id(), handle_grpc_session.name());
FakeHandle handle = session_repository_->access_session(handle_grpc_session.name());
int32 attribute;
switch (request->attribute_enum_case()) {
case nifake_non_ivi_grpc::GetMarbleAttributeInt32ArrayRequest::AttributeEnumCase::kAttribute: {
Expand Down Expand Up @@ -355,15 +354,14 @@ namespace nifake_non_ivi_grpc {
auto status = library_->Init(session_name, &handle);
return std::make_tuple(status, handle);
};
uint32_t session_id = 0;
const std::string& grpc_device_session_name = request->session_name();
std::string grpc_device_session_name = request->session_name();
auto cleanup_lambda = [&] (FakeHandle id) { library_->Close(id); };
int status = session_repository_->add_session(grpc_device_session_name, init_lambda, cleanup_lambda, session_id);
int status = session_repository_->add_session(grpc_device_session_name, init_lambda, cleanup_lambda);
if (!status_ok(status)) {
return ConvertApiErrorStatusForFakeHandle(context, status, 0);
}
response->set_status(status);
response->mutable_handle()->set_id(session_id);
response->mutable_handle()->set_name(grpc_device_session_name);
return ::grpc::Status::OK;
}
catch (nidevice_grpc::NonDriverException& ex) {
Expand All @@ -380,22 +378,21 @@ namespace nifake_non_ivi_grpc {
}
try {
auto cross_driver_session_grpc_session = request->cross_driver_session();
int32 cross_driver_session = fake_cross_driver_handle_resource_repository_->access_session(cross_driver_session_grpc_session.id(), cross_driver_session_grpc_session.name());
int32 cross_driver_session = fake_cross_driver_handle_resource_repository_->access_session(cross_driver_session_grpc_session.name());

auto init_lambda = [&] () {
FakeHandle handle;
auto status = library_->InitFromCrossDriverSession(cross_driver_session, &handle);
return std::make_tuple(status, handle);
};
uint32_t session_id = 0;
const std::string& grpc_device_session_name = request->session_name();
std::string grpc_device_session_name = request->session_name();
auto cleanup_lambda = [&] (FakeHandle id) { library_->Close(id); };
int status = session_repository_->add_session(grpc_device_session_name, init_lambda, cleanup_lambda, session_id);
int status = session_repository_->add_session(grpc_device_session_name, init_lambda, cleanup_lambda);
if (!status_ok(status)) {
return ConvertApiErrorStatusForFakeHandle(context, status, 0);
}
response->set_status(status);
response->mutable_handle()->set_id(session_id);
response->mutable_handle()->set_name(grpc_device_session_name);
return ::grpc::Status::OK;
}
catch (nidevice_grpc::NonDriverException& ex) {
Expand All @@ -417,23 +414,22 @@ namespace nifake_non_ivi_grpc {
cross_driver_session_array_request.begin(),
cross_driver_session_array_request.end(),
std::back_inserter(cross_driver_session_array),
[&](auto session) { return fake_cross_driver_handle_resource_repository_->access_session(session.id(), session.name()); });
[&](auto session) { return fake_cross_driver_handle_resource_repository_->access_session(session.name()); });
int32 number_of_cross_driver_sessions = static_cast<int32>(request->cross_driver_session_array().size());

auto init_lambda = [&] () {
FakeHandle handle;
auto status = library_->InitFromCrossDriverSessionArray(cross_driver_session_array.data(), number_of_cross_driver_sessions, &handle);
return std::make_tuple(status, handle);
};
uint32_t session_id = 0;
const std::string& grpc_device_session_name = request->session_name();
std::string grpc_device_session_name = request->session_name();
auto cleanup_lambda = [&] (FakeHandle id) { library_->Close(id); };
int status = session_repository_->add_session(grpc_device_session_name, init_lambda, cleanup_lambda, session_id);
int status = session_repository_->add_session(grpc_device_session_name, init_lambda, cleanup_lambda);
if (!status_ok(status)) {
return ConvertApiErrorStatusForFakeHandle(context, status, 0);
}
response->set_status(status);
response->mutable_handle()->set_id(session_id);
response->mutable_handle()->set_name(grpc_device_session_name);
return ::grpc::Status::OK;
}
catch (nidevice_grpc::NonDriverException& ex) {
Expand All @@ -455,15 +451,14 @@ namespace nifake_non_ivi_grpc {
auto status = library_->InitSecondarySession(&secondary_session_handle);
return std::make_tuple(status, secondary_session_handle);
};
uint32_t session_id = 0;
const std::string& grpc_device_session_name = request->session_name();
std::string grpc_device_session_name = request->session_name();
auto cleanup_lambda = [&] (SecondarySessionHandle id) { library_->CloseSecondarySession(id); };
int status = secondary_session_handle_resource_repository_->add_session(grpc_device_session_name, init_lambda, cleanup_lambda, session_id);
int status = secondary_session_handle_resource_repository_->add_session(grpc_device_session_name, init_lambda, cleanup_lambda);
if (!status_ok(status)) {
return ConvertApiErrorStatusForFakeHandle(context, status, 0);
}
response->set_status(status);
response->mutable_secondary_session_handle()->set_id(session_id);
response->mutable_secondary_session_handle()->set_name(grpc_device_session_name);
return ::grpc::Status::OK;
}
catch (nidevice_grpc::NonDriverException& ex) {
Expand All @@ -486,15 +481,14 @@ namespace nifake_non_ivi_grpc {
auto status = library_->InitWithHandleNameAsSessionName(handle_name, &handle);
return std::make_tuple(status, handle);
};
uint32_t session_id = 0;
const std::string& grpc_device_session_name = request->handle_name();
std::string grpc_device_session_name = request->handle_name();
auto cleanup_lambda = [&] (FakeHandle id) { library_->Close(id); };
int status = session_repository_->add_session(grpc_device_session_name, init_lambda, cleanup_lambda, session_id);
int status = session_repository_->add_session(grpc_device_session_name, init_lambda, cleanup_lambda);
if (!status_ok(status)) {
return ConvertApiErrorStatusForFakeHandle(context, status, 0);
}
response->set_status(status);
response->mutable_handle()->set_id(session_id);
response->mutable_handle()->set_name(grpc_device_session_name);
return ::grpc::Status::OK;
}
catch (nidevice_grpc::NonDriverException& ex) {
Expand All @@ -517,15 +511,14 @@ namespace nifake_non_ivi_grpc {
auto status = handle == 0xDEADBEEF ? -1 : 0;
return std::make_tuple(status, handle);
};
uint32_t session_id = 0;
const std::string& grpc_device_session_name = request->handle_name();
std::string grpc_device_session_name = request->handle_name();
auto cleanup_lambda = [&] (FakeHandle id) { library_->Close(id); };
int status = session_repository_->add_session(grpc_device_session_name, init_lambda, cleanup_lambda, session_id);
int status = session_repository_->add_session(grpc_device_session_name, init_lambda, cleanup_lambda);
if (!status_ok(status)) {
return ConvertApiErrorStatusForFakeHandle(context, status, 0);
}
response->set_status(status);
response->mutable_handle()->set_id(session_id);
response->mutable_handle()->set_name(grpc_device_session_name);
return ::grpc::Status::OK;
}
catch (nidevice_grpc::NonDriverException& ex) {
Expand Down Expand Up @@ -961,7 +954,7 @@ namespace nifake_non_ivi_grpc {
}
try {
auto handle_grpc_session = request->handle();
FakeHandle handle = session_repository_->access_session(handle_grpc_session.id(), handle_grpc_session.name());
FakeHandle handle = session_repository_->access_session(handle_grpc_session.name());
int32 attribute;
switch (request->attribute_enum_case()) {
case nifake_non_ivi_grpc::ResetMarbleAttributeRequest::AttributeEnumCase::kAttribute: {
Expand Down Expand Up @@ -1052,7 +1045,7 @@ namespace nifake_non_ivi_grpc {
}
try {
auto handle_grpc_session = request->handle();
FakeHandle handle = session_repository_->access_session(handle_grpc_session.id(), handle_grpc_session.name());
FakeHandle handle = session_repository_->access_session(handle_grpc_session.name());
int32 attribute;
switch (request->attribute_enum_case()) {
case nifake_non_ivi_grpc::SetMarbleAttributeDoubleRequest::AttributeEnumCase::kAttribute: {
Expand Down Expand Up @@ -1094,7 +1087,7 @@ namespace nifake_non_ivi_grpc {
}
try {
auto handle_grpc_session = request->handle();
FakeHandle handle = session_repository_->access_session(handle_grpc_session.id(), handle_grpc_session.name());
FakeHandle handle = session_repository_->access_session(handle_grpc_session.name());
int32 attribute;
switch (request->attribute_enum_case()) {
case nifake_non_ivi_grpc::SetMarbleAttributeInt32Request::AttributeEnumCase::kAttribute: {
Expand Down
Loading

0 comments on commit ca6a68a

Please sign in to comment.