google protobuf compiler doesn't generate class for service tag? - c++

I'm trying to use protobuf to generate a service using RpcChannel and RpcController. I referred to language guide of google protobuf and:
I've got sample proto file like this:
syntax = "proto2";
message SearchRequest
{
required string Request = 1;
}
message SearchResponse
{
required string Response = 2;
}
service SearchService {
rpc Search (SearchRequest) returns (SearchResponse);
}
Then I compiled it with:
protoc --cpp_out=./ examples.proto
I got .h and .cc files. But when I search the generated code, I only found classes for "Request" and "Response", but not a class for "SearchService":
examples.pb.h:class SearchRequest;
examples.pb.h:class SearchResponse;
examples.pb.h:class SearchRequest : public ::google::protobuf::Message {
examples.pb.h: // ##protoc_insertion_point(class_scope:SearchRequest)
examples.pb.h:class SearchResponse : public ::google::protobuf::Message {
examples.pb.h: // ##protoc_insertion_point(class_scope:SearchResponse)
The language guide web-page provided an example(https://developers.google.com/protocol-buffers/docs/proto#services) which requires to use class of "SearchService": but in the generated code, there's no search service. The guide didn't provide a complete sample of RpcChannel/RpcController usages.
So how can I fix the example to make it work? I searched google but didn't find any good cpp example that gives a complete sample of how RpcChannel/RpcController could work. Any hints or links?
Thanks!

protobuf does not offer RPC implementation by itself; you should use plugin interface to create your own, or use grpc.
For example, grpc uses grpc_cpp_plugin plugin for it.
$ protoc -I ../../protos --grpc_out=. --plugin=protoc-gen-grpc=`which grpc_cpp_plugin` ../../protos/route_guide.proto
https://github.com/grpc/grpc/blob/master/examples/cpp/cpptutorial.md

Related

How to add an project about idl on redhawk

When I add an idl project in redhawk following the steps below:
$ ./reconf
$ ./configure
$ sudo make
$ sudo make install
I can find the newly added idl file in the REDHAWK Target SDR directory.
REDHAWK Target SDR
When testing whether the idl file can be called, I have added the header file and have already called the function interface, but at compile time, the error is: undefined reference to 'xxxxxxxx'
eg:
#include <redhawk/XH_IDL_TEST/xh_idl_test.h>
class data_t_test_base : public Component, protected ThreadedComponent
{
public:
data_t_test_base(const char *uuid, const char *label);
~data_t_test_base();
void start() throw (CF::Resource::StartError, CORBA::SystemException);
void stop() throw (CF::Resource::StopError, CORBA::SystemException);
void releaseObject() throw (CF::LifeCycle::ReleaseError,CORBA::SystemException);
void loadProperties();
protected:
xh_idl_test::_objref_dataChar *XH;
private:
}
errors:
/home/sca/sca_com/data_t_test/cpp/data_t_test.cpp:21: undefined reference to `xh_idl_test::_objref_dataChar::pushPacket()'
May I ask how to solve this problem?
In REDHAWK, IDL is accessed through ports, either uses (output) or provides (input). Once the IDL project is installed in your system, on component add a Port. Edit the port's interface by clicking on "Browse...". On the "Select and interface" menu, click "Show all interfaces", and then select the interface you want.
In the case of either input or output ports, the appropriate stubs will be generated.

Writing custom checkers for Clang Static Analyzer

I've just finished following the "Getting Started" instructions from the clang analyzer page.
My XCode is currently using the checker build 278
Right now I'm trying to follow some guides I can find to write my own custom checkers like
http://blog.trailofbits.com/2014/04/27/using-static-analysis-and-clang-to-find-heartbleed/
http://bbannier.github.io/blog/2015/05/02/Writing-a-basic-clang-static-analysis-check.html
Was hoping that someone can point me in the right direction and I'm not very familiar with building clang projects.
Are there any IDE available that would help?
How should I add the custom checker I wrote to the build 278?
I have recently started using clang checker's and here's how I got my custom checker to work with clang.
You have to modify the Checkers.td to register your checker.
<path-to-llvm>/llvm/tools/clang/lib/StaticAnalyzer/Checkers/Checkers.td
I made a debug checker to I put it under debug group and added these lines:
def MyCustomChecker : Checker<"DebugUsingMyChecker">,
HelpText<"Print results of my custom checker">,
DescFile<"DebugCheckers.cpp">; //this is the file where we define the class file of our checker
Then edit the DebugCheckers.cpp to add your checker's class to be invoked by the newly registered checker.
<path-to-llvm>/llvm/tools/clang/lib/StaticAnalyzer/Checkers/DebugCheckers.cpp
And add under debug checkers tag
namespace
{
class MyCustomChecker : public Checker<check::ASTCodeBody> {
public:
void checkASTCodeBody(const Decl *D, AnalysisManager& mgr,
BugReporter &BR) const {
if (MyCustomChecker* CC = mgr.getAnalysis<CustomChecker>(D)) {
CC->dump(mgr.getSourceManager());
}
}
};
}
void ento::registerMyCustomChecker(CheckerManager &mgr) {
mgr.registerChecker<MyCustomChecker>();
}
After this, you can place the relevant class files in the folder:
<path-to-llvm>/llvm/tools/clang/lib/Analysis/
And edit the CMakeList.txt in that folder to include your class file.
Hope that clarifies the process. You can also read this link for more: http://clang-analyzer.llvm.org/checker_dev_manual.html
As far as IDE's are concerned, you can use any IDE which supports's CMake based projects (like CLion). You can look at this link for more: http://llvm.org/docs/CMake.html

Slick 3.0.0 and Scala 2.10.4

I was trying to create a scala program with slick 3.0 and I am getting the following error:
Error:scalac: bad symbolic reference. A signature in BasicDriver.class refers to term typesafe
in package com which is not available.
It may be completely missing from the current classpath, or the version on
the classpath might be incompatible with the version used when compiling BasicDriver.class.
I am using scala 2.10.4 and slick 2.10-3.0.0-RC1 and my IDE is IDEA 14.0.3 community edition
Any clue about this compilation error will be appreciated.
Thanks a lot!!!
This is how a BasicDriver.class defintion looks like
package scala.slick.profile
trait BasicDriver extends scala.AnyRef with scala.slick.profile.BasicProfile {
val profile : scala.slick.profile.BasicProfile = { /* compiled code */ }
override def toString() : java.lang.String = { /* compiled code */ }
final val driverConfig : com.typesafe.config.Config = { /* compiled code */ }
protected[this] def loadDriverConfig : com.typesafe.config.Config = { /* compiled code */ }
}
The error :
Error:scalac: bad symbolic reference. A signature in BasicDriver.class refers to term typesafe in package com which is not available. It may be completely missing from the current classpath, or the version on the classpath might be incompatible with the version used when compiling BasicDriver.class
is saying that com.typesafe for (com.typesafe.config.Config) is missing from the classpath .
I think the problem is with the dependencies added , try the master snapshot :
"com.typesafe.slick" % "slick_2.10" % "3.0.0-M1"

WS-Discovery & gSOAP set up in VS2013

My overarching goal is to create a small ONVIF client for getting camera information in either C or C++.
gSOAP seemed like a good candidate and first thing I wanted to achieve was to make a small console application which would list the addresses of a bunch of cameras I have on my network using WS-Discovery, something I've done before with a little .NET application.
The problem is I'm stumbling at the first hurdle and I'm a touch confused as to what I'm supposed to be doing. I started out by doing the following:
wsdl2h.exe -o WSDiscovery.h WS-Discovery.wsdl http://www.w3.org/2006/03/addressing/ws-addr.xsd
soapcpp2.exe -i -C -Iimport WSDiscovery.h -d output
,
I then made a project from the resulting soapC.cpp stdsoap2.cpp soapH.h soapStub.h. Adding in threads.h wsaapi.h wsddapi.h threads.c wsaapi.c wsddapi.c from gsoap
This doesn't compile however giving:
wsaapi.h(134): error C2061: syntax error : identifier 'wsa__FaultSubcodeValues'
I think I'm going very wrong here and I'm confused about exactly what a 'plugin' is in the context of gSOAP (my experience with external libraries like this is extremely limited and I have no real formal training in CS). Am I just supposed to be doing what I'm doing now with the wsdd files or are they supposed to be used as part of the soapcpp2.exe process? Am I actually supposed to be using wsdl2h.exe if I just want WS-Discovery?
I can't really make sense of the documentation and don't understand how I'm supposed to get this working. Some help would be greatly appreciated so I can crack on with the actual hard part!
I guess the problem is coming from usage of WS-Adressing plugins (wsaapi.h/.c) with http://www.w3.org/2006/03/addressing/ws-addr.xsd schema.
gSOAP contains the wsdl2h generated file that could be used by WS-discovery plugins (wsddapi.h/.c).
[GSOAP_DIR]/import/wsdd10.h for WS-Discovery 1.0 2005 that use WS-Adressing 2004/08
[GSOAP_DIR]/import/wsdd.h for WS-Discovery 1.1 2009 that use WS-Adressing 2005/08
As ONVIF use WS-Discovery 1.0 you could generate discovery implementation using :
soapcpp2 -Cx [GSOAP_DIR]/import/wsdd10.h -I [GSOAP_DIR]/import -d output
Next you should be able to build your project including wsddapi.c wsaapi.c soapClient.cpp soapC.cpp
You can find some of my experiments from github ws-discovery

How to run gSOAP code generator without internet connection?

I am trying to generate code using wsdl2h/soap2cpp for the onvif media WSDL http://www.onvif.org/onvif/ver10/media/wsdl/media.wsdl. This wsdl have some dependencies.
Reading the gSOAP FAQ http://www.cs.fsu.edu/~engelen/soapfaq.html, I finally extract the needed namespaces in following typemap.dat
trt = "http://www.onvif.org/ver10/media/wsdl"
tt = "http://www.onvif.org/ver10/schema"
wsnt = "http://docs.oasis-open.org/wsn/b-2"
wsrfbf = "http://docs.oasis-open.org/wsrf/bf-2"
wstop = "http://docs.oasis-open.org/wsn/t-1"
xop="http://www.w3.org/2004/08/xop/include"
wsa5 = <http://www.w3.org/2005/08/addressing>
With this mapping the gSOAP code generator run correctly :
wsdl2h media.wsdl
soapcpp2 -2ix media.h -I /usr/share/gsoap/import
But this need to have an internet connection. I would like to build with files that are stored locally.
In the wsdl2h help there is an option that looks interesting :
-i don't import (advanced option)
So I download what was downloaded by wsdl2h :
http://www.onvif.org/onvif/ver10/schema/onvif.xsd
http://docs.oasis-open.org/wsn/b-2.xsd
http://www.w3.org/2004/08/xop/include
http://docs.oasis-open.org/wsrf/bf-2.xsd
http://docs.oasis-open.org/wsn/t-1.xsd
And next run
wsdl2h -im media.wsdl onvif.xsd b-2.xsd include bf-2.xsd t-1.xsd
soapcpp2 -2ix media.h -I /usr/share/gsoap/import
But this fails with this kind of output :
** The gSOAP code generator for C and C++, soapcpp2 release 2.8.7
** Copyright (C) 2000-2011, Robert van Engelen, Genivia Inc.
** All Rights Reserved. This product is provided "as is", without any warranty.
** The soapcpp2 tool is released under one of the following two licenses:
** GPL or the commercial license by Genivia Inc.
media.h(164): syntax error
media.h(163): Syntax error: declaration expected
media.h(173): syntax error
...
In media.h the code reference strucure coming from ws-addressing. Next I tried different things importing more xsd but I did not find a way to resolve the missing dependencies.
Perhaps this is not the proper way to build from local file. Anyway I would like to avoid any modification in the wsdls and xsd files. An alternative could be a catalog to map the remote url to local url (like Apache CXF) but I did not find anything like this in gSOAP documentation.
Thanks for sharing your experiences.
I found only partial documentation of the typemap.dat format from gSOAP site http://www.cs.fsu.edu/~engelen/soapdoc2.html. However I noticed that some namespace definition use <url> instead of "url".
After some tries, this give a solution to the problem, defining namespace enclosed inside <>.
So I modified the typemap.dat like this :
trt=<http://www.onvif.org/ver10/media/wsdl>
tt=<http://www.onvif.org/ver10/schema>
wsnt=<http://docs.oasis-open.org/wsn/b-2>
wsrfbf=<http://docs.oasis-open.org/wsrf/bf-2>
wstop=<http://docs.oasis-open.org/wsn/t-1>
xop=<http://www.w3.org/2004/08/xop/include>
wsa5=<http://www.w3.org/2005/08/addressing>
Then it is possible to generate code from the media.wsdl without connecting to internet :
wsdl2h media.wsdl onvif.xsd b-2.xsd include bf-2.xsd t-1.xsd
soapcpp2 -2ix media.h -I /usr/share/gsoap/import