Hide

common.h

#include <google/protobuf/stubscommon.h>
namespace google::protobuf

Contains basic types and utilities used by the rest of the library.

Classes in this file

Create a LogSilencer if you want to temporarily suppress all log messages.
Abstract interface for a callback.

class LogSilencer

#include <google/protobuf/stubscommon.h>
namespace google::protobuf

Create a LogSilencer if you want to temporarily suppress all log messages.

As long as any LogSilencer objects exist, non-fatal log messages will be discarded (the current LogHandler will not be called). Constructing a LogSilencer is thread-safe. You may accidentally suppress log messages occurring in another thread, but since messages are generally for debugging purposes only, this isn't a big deal. If you want to intercept log messages, use SetLogHandler().

Members

LogSilencer()
~LogSilencer()

class Closure

#include <google/protobuf/stubscommon.h>
namespace google::protobuf

Abstract interface for a callback.

When calling an RPC, you must provide a Closure to call when the procedure completes. See the Service interface in service.h.

To automatically construct a Closure which calls a particular function or method with a particular set of parameters, use the NewCallback() function. Example:

void FooDone(const FooResponse* response) {
  ...
}

void CallFoo() {
  ...
  // When done, call FooDone() and pass it a pointer to the response.
  Closure* callback = NewCallback(&FooDone, response);
  // Make the call.
  service->Foo(controller, request, response, callback);
}
Example that calls a method:
class Handler {
 public:
  ...

  void FooDone(const FooResponse* response) {
    ...
  }

  void CallFoo() {
    ...
    // When done, call FooDone() and pass it a pointer to the response.
    Closure* callback = NewCallback(this, &Handler::FooDone, response);
    // Make the call.
    service->Foo(controller, request, response, callback);
  }
};
Currently NewCallback() supports binding zero, one, or two arguments.

Callbacks created with NewCallback() automatically delete themselves when
executed.  They should be used when a callback is to be called exactly
once (usually the case with RPC callbacks).  If a callback may be called
a different number of times (including zero), create it with
NewPermanentCallback() instead.  You are then responsible for deleting the
callback (using the "delete" keyword as normal).

Note that NewCallback() is a bit touchy regarding argument types.  Generally,
the values you provide for the parameter bindings must exactly match the
types accepted by the callback function.  For example:
void Foo(string s);
NewCallback(&Foo, "foo");          // WON'T WORK:  const char* != string
NewCallback(&Foo, string("foo"));  // WORKS

Also note that the arguments cannot be references:

void Foo(const string& s);
string my_str;
NewCallback(&Foo, my_str);  // WON'T WORK:  Can't use referecnes.

However, correctly-typed pointers will work just fine.

Members

Closure()
virtual
~Closure()
virtual void
Run() = 0