Never mind that, I figured out what I was doing wrong. One little tiny 
character was missing:

[](kj::Maybe<Callable::Server> perhaps) {
... should have been ...
[](kj::Maybe<Callable::Server&> perhaps) {

On Wednesday, February 22, 2017 at 4:00:48 PM UTC+1, Johannes Zeppenfeld 
wrote:
>
> I've tried pursuing the CapabilityServerSet option, and have run into a 
> bit of a snag. Using the schema posted in the original post, here is the 
> current implementation of the server's Bootstrap class:
>
> class BootstrapImpl : public Bootstrap::Server {
> private:
>     kj::Promise<void> getCallable(GetCallableContext context) override {
>         // Create a callable to return to the client, storing it in the
>         // server capability set of callables.
>         Callable::Client callable = 
> _callables.add(kj::heap<CallableImpl>());
>         context.getResults().setCallable(callable);
>         
>         // Test if the callable can be retrieved.
>         // Normally I'd just return kj::READY_NOW here.
>         return _callables.getLocalServer(callable).then(
>             [](kj::Maybe<Callable::Server> perhaps) {
>                 KJ_IF_MAYBE(callable, perhaps) {
>                     std::cout << "Callable lookup: " << callable << 
> std::endl;
>                 } else {
>                     std::cout << "Callable lookup failed." << std::endl;
>                 }
>             }
>         );
>     }
>     
> private:
>     capnp::CapabilityServerSet<Callable> _callables;
> };
>
> Unfortunately, the pointer returned by the getLocalServer lookup has 
> nothing to do with the actual address of the instantiate CallableImpl...
>
> CallableImpl():0x8249b0
> Callable lookup: 0x7fffc33b44a8
> ~CallableImpl():0x8249b0
>
> Am I doing something wrong? Is this a bug in Cap'n Proto? Any suggestions 
> for getting this to work?
>
> A full client and server code example is attached.
>
> Thanks!
> Johannes
>
>
>
> On Wednesday, February 22, 2017 at 9:22:47 AM UTC+1, Johannes Zeppenfeld 
> wrote:
>>
>> Thanks for the tip! I knew I couldn't have been the first person to need 
>> something like this, and installing from git is fine.
>>
>> However... getLocalServer returns a promise, which again makes it 
>> impossible to call the Callable functions from within the process method. 
>> Is there a way to get the server object directly? I don't see any way for 
>> the Client object to be a promise at this point...
>>
>> Otherwise I suppose I'd have to split the process method into two parts, 
>> first starting retrieval of all of the local server objects, joining the 
>> returned promises and then processing them in a second step. This becomes 
>> difficult when dealing with heterogeneous server object types though, e.g. 
>> if there are Actions for Callable and another type, e.g., Executable. Is 
>> there something similar to joinPromises that works with heterogeneous types?
>>
>> Thanks!
>> Johannes
>>
>> On Tuesday, February 21, 2017 at 7:21:43 PM UTC+1, David Renshaw wrote:
>>>
>>> You can accomplish that with CapabilityServerSet, which was added in 
>>> this commit: 
>>> https://github.com/sandstorm-io/capnproto/commit/8b8f8a2fc25d69c8a43ee0ac987521c2c4d5108c
>>>  
>>> .
>>>
>>> Unfortunately, there has not yet been a release that includes 
>>> CapabilityServerSet, so you would need to install Cap'n Proto from git to 
>>> make use of it.
>>>
>>> On Tue, Feb 21, 2017 at 1:06 PM, Johannes Zeppenfeld <[email protected]> 
>>> wrote:
>>>
>>>> Knowing that the answer to the question in the subject is probably 
>>>> "don't do that", I'm looking for a way to support database-like 
>>>> transactions (i.e., event-loop atomic operations) spanning multiple server 
>>>> objects.
>>>>
>>>> Here's a simplified schema to help explain the problem:
>>>>
>>>> # A transaction holds a list of actions that should be processed in a 
>>>> single
>>>> # event-loop atomic operation.
>>>> struct Transaction {
>>>>     actions @0 :List(Action);
>>>>     
>>>>     struct Action {
>>>>         union {
>>>>             nop @0 :Void;
>>>>             execute @1 :Callable;
>>>>             #doSomething @2 :AnotherType;
>>>>             #etc...
>>>>         }
>>>>     }
>>>> }
>>>>
>>>> # A callable is a server-side object conveying the capability of calling
>>>> # some server function as part of a transaction.
>>>> interface Callable { }
>>>>
>>>> # Some other interface that serves callables (simplified example) and
>>>> # processes transactions.
>>>> interface Bootstrap {
>>>>     getCallable @0 (name :Text) -> (callable :Callable);
>>>>     
>>>>     process @1 (transaction :Transaction);
>>>> }
>>>>
>>>> A client can obtain Callables from the server through e.g. the 
>>>> Bootstrap interface, and should then be able to pass that Callable as part 
>>>> of a Transaction back to the server. The Callable::Server implementation 
>>>> contains a std::function that should be called for any Callable that is 
>>>> executed as part of a transaction.
>>>>
>>>> Unfortunately (although it totally makes sense), the Transaction Reader 
>>>> available in the Bootstrap implementation's process method only provides a 
>>>> Callable::Client, without a possibility (as far as I can tell) of 
>>>> retrieving the associated Callable::Server object. Thus it is not possible 
>>>> to retrieve nor call the std::function object associated with the Callable.
>>>>
>>>> Adding a call method to the Callable interface would allow it to be 
>>>> called by the process method or directly by the client, but not (again as 
>>>> far as I can tell) in an event-loop atomic manner as part of a transaction.
>>>>
>>>> I hope that the scenario above is understandable. If not I'd be more 
>>>> than happy to elaborate on points that are not clear.
>>>>
>>>> Am I overlooking something that would allow somehow calling the 
>>>> std::function of a Callable implementation from within the process method? 
>>>> Does anyone have a different suggestion for achieving something like this?
>>>>
>>>> I would like to avoid implementing a custom capability system that 
>>>> replaces Callable with a struct containing an id. But perhaps it is the 
>>>> only way?
>>>>
>>>> Thanks!
>>>> Johannes
>>>>
>>>> -- 
>>>> You received this message because you are subscribed to the Google 
>>>> Groups "Cap'n Proto" group.
>>>> To unsubscribe from this group and stop receiving emails from it, send 
>>>> an email to [email protected].
>>>> Visit this group at https://groups.google.com/group/capnproto.
>>>>
>>>
>>>

-- 
You received this message because you are subscribed to the Google Groups 
"Cap'n Proto" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
Visit this group at https://groups.google.com/group/capnproto.

Reply via email to