Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » Developing U++ » U++ Developers corner » RPC_METHOD how to "define"
Re: RPC_METHOD how to "define" [message #47604 is a reply to message #47601] Sun, 05 February 2017 20:48 Go to previous messageGo to previous message
dolik.rce is currently offline  dolik.rce
Messages: 1791
Registered: August 2008
Location: Czech Republic
Ultimate Contributor

NilaT wrote on Sun, 05 February 2017 11:02
Mirek, my intention why I want it as member functions is, because my RPC Methods all need a database connection, so in one class function I open the connection and keep it open. And because I don't want to pass this PostgreSqlSession to all RPC Functions, I want to use a member.
As Mirek already said, global instance is just fine for this purpose. If you don't like global variables, than you can use the template Single<T>, just as I did in the example, to create single instance of some type T, which is shared by all the code that calls Single<T>(). Furthermore, for Sql connection, there are already application-wide variables SQL and SQLR for this (the second one can be used for readonly connections). These variables even allow to write some sql commands in simpler way.

NilaT wrote on Sun, 05 February 2017 11:02
Furthermore I need an Instance of a very big class and don't want to pass this either, so a member seems to be the best solution in my opinion.
No U++ solution for this, but again, global variable or any kind of singleton should do.

NilaT wrote on Sun, 05 February 2017 11:02
PS: Maybe you can explain this code? I mean... it compiles, but I really don't know what this does:
[](RpcData& rpc){Single<MyRpcClass>().Status(rpc);});
Single<> creates singleton instance, while "[](RpcData& rpc) {}" is a definition of lambda function from C++11. It is basically an anonymous function that takes RpcData& as parameter and calls your member function on the singleton as mentioned above.

Honza
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Requirement Printing in a batch -> new Feature for PrinterJob
Next Topic: C2280
Goto Forum:
  


Current Time: Fri Jun 06 15:08:28 CEST 2025

Total time taken to generate the page: 0.05761 seconds