Skip to content

Commit

Permalink
More error handling improvements
Browse files Browse the repository at this point in the history
Added Set Call Status so servers can return a custom error for a call.
  • Loading branch information
ccifra committed Jan 17, 2022
1 parent b92c8db commit e9339e7
Show file tree
Hide file tree
Showing 9 changed files with 37 additions and 2 deletions.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
2 changes: 2 additions & 0 deletions labview source/gRPC lv Support/gprc-lvsupport.lvlib
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
<Item Name="Create Server.vi" Type="VI" URL="../Server API/Server/Create Server.vi"/>
<Item Name="Get Server DLL Path.vi" Type="VI" URL="../Server API/Server/Get Server DLL Path.vi"/>
<Item Name="Register Message Metadata.vi" Type="VI" URL="../Server API/Server/Register Message Metadata.vi"/>
<Item Name="Set Call Status.vi" Type="VI" URL="../Server API/Set Call Status.vi"/>
<Item Name="Start Server.vi" Type="VI" URL="../Server API/Server/Start Server.vi"/>
<Item Name="Stop Server.vi" Type="VI" URL="../Server API/Server/Stop Server.vi"/>
<Item Name="TranslateGrpcError.vi" Type="VI" URL="../Server API/TranslateGrpcError.vi"/>
Expand All @@ -79,6 +80,7 @@
<Item Name="typeDefs" Type="Folder">
<Item Name="Any.ctl" Type="VI" URL="../Server API/typeDefs/Any.ctl"/>
<Item Name="Generic Method Event Data.ctl" Type="VI" URL="../Server API/typeDefs/Generic Method Event Data.ctl"/>
<Item Name="gRPC Status Code.ctl" Type="VI" URL="../Server API/typeDefs/gRPC Status Code.ctl"/>
<Item Name="gRPCId Cluster UE.ctl" Type="VI" URL="../Server API/typeDefs/gRPCId Cluster UE.ctl"/>
<Item Name="gRPCId Cluster.ctl" Type="VI" URL="../Server API/typeDefs/gRPCId Cluster.ctl"/>
<Item Name="grpcId.ctl" Type="VI" URL="../Server API/typeDefs/grpcId.ctl"/>
Expand Down
19 changes: 17 additions & 2 deletions src/event_data.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ namespace grpc_labview
_status(CallStatus::Create),
_writeSemaphore(0),
_cancelled(false),
_requestDataReady(false)
_requestDataReady(false),
_callStatus(grpc::Status::OK)
{
Proceed(true);
}
Expand Down Expand Up @@ -65,6 +66,20 @@ namespace grpc_labview
return true;
}

//---------------------------------------------------------------------
//---------------------------------------------------------------------
void CallData::SetCallStatusError(std::string errorMessage)
{
_callStatus = grpc::Status(grpc::StatusCode::INTERNAL, errorMessage);
}

//---------------------------------------------------------------------
//---------------------------------------------------------------------
void CallData::SetCallStatusError(grpc::StatusCode statusCode, std::string errorMessage)
{
_callStatus = grpc::Status(statusCode, errorMessage);
}

//---------------------------------------------------------------------
//---------------------------------------------------------------------
void CallData::CallFinished()
Expand All @@ -84,7 +99,7 @@ namespace grpc_labview
else
{
_status = CallStatus::Finish;
_stream.Finish(grpc::Status::OK, this);
_stream.Finish(_callStatus, this);
}
}

Expand Down
13 changes: 13 additions & 0 deletions src/grpc_interop.cc
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,19 @@ LIBRARY_EXPORT int32_t CloseServerEvent(grpc_labview::gRPCid** id)
return 0;
}

//---------------------------------------------------------------------
//---------------------------------------------------------------------
LIBRARY_EXPORT int32_t SetCallStatus(grpc_labview::gRPCid** id, int grpcErrorCode, const char* errorMessage)
{
auto data = (*id)->CastTo<grpc_labview::GenericMethodData>();
if (data == nullptr)
{
return -1;
}
data->_call->SetCallStatusError((grpc::StatusCode)grpcErrorCode, errorMessage);
return 0;
}

//---------------------------------------------------------------------
//---------------------------------------------------------------------
LIBRARY_EXPORT int32_t IsCancelled(grpc_labview::gRPCid** id)
Expand Down
4 changes: 4 additions & 0 deletions src/grpc_server.h
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,8 @@ namespace grpc_labview
void CallFinished();
bool ReadNext();
void ReadComplete();
void SetCallStatusError(std::string errorMessage);
void SetCallStatusError(grpc::StatusCode statusCode, std::string errorMessage);

private:
LabVIEWgRPCServer* _server;
Expand All @@ -156,11 +158,13 @@ namespace grpc_labview
grpc::GenericServerContext _ctx;
grpc::GenericServerAsyncReaderWriter _stream;
grpc::ByteBuffer _rb;
grpc::Status _callStatus;

Semaphore _writeSemaphore;
std::shared_ptr<GenericMethodData> _methodData;
std::shared_ptr<LVMessage> _request;
std::shared_ptr<LVMessage> _response;

bool _cancelled;
bool _requestDataReady;

Expand Down
1 change: 1 addition & 0 deletions src/unpacked_fields.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <google/protobuf/any.pb.h>
#include <lv_message.h>
#include <message_metadata.h>
#include <math.h>

namespace grpc_labview
{
Expand Down

0 comments on commit e9339e7

Please sign in to comment.