|
|
|
|||||
|
hard to use AMI,help me,please
The blow is a simple example only to explain what problem i encountered.
Chat.ice ----------------------------------------- #ifndef CHAT_ICE #define CHAT_ICE module Demo { interface Chat { ["ami"]bool login(string name); }; }; #endif // define CHAT_ICE ----------------------------------------- class ChatI : public Demo::Chat { //............ }; class A defined in C++ { public void login(); //............ private: std::string _name; bool _IsLogin; Demo::ChatPrx _chati; // * a member of class A } // implementation of functon login() using login_async void A::login() { AMI_Chat_loginPtr amiptr = new AMI_Chat_loginI; _chati->login_async(amiptr,"kin"); } ----------------------------------------- the question is : if i use synchronous programming model. it is very easy to get the value _IsLogin: _IsLogin = _chati->login("kin"); but now, how to change the data member A::_IsLogin when the AMI invloved???? class AMI_Chat_loginI : public Demo::AMI_Chat_login { void ice_response(bool res) { // //how to change the data member // A::_IsLogin when the AMI invloved???? // seems it is impossible to modefiy here // } void ice_exception(const ::Ice::Exception&){} };
__________________
kin Young university: Sun Yat-sen University url: http://www.sysu.edu.cn learning ICE.
Last edited by nyingchi : 09-18-2006 at 03:53 AM. |
|
|||||
i got it .thanks for your prompt reply which gives me lots of hints. because my english is poor , i dont know how to deliver my deep thanks for your kindly help. thanks. ![]()
__________________
kin Young university: Sun Yat-sen University url: http://www.sysu.edu.cn learning ICE.
|
|
|||||
now my solution is below. i use the following code to show my solution,not in details. will you tell me the advantage and disadvantafe of this solution? thanks. Chat.ice as before ----------------------------------------- AA.ice module Demo { interface AA { bool loginResult(bool ret); }; }; ----------------------------------------- class AAI : public Demo::AA { public: bool loginResult(bool ret, Ice::Current &); inline void IsLogin() { return _IsLogin; } // and so on ......... private: bool _IsLogin; } typedef IceUtil::Handle<AAI> AAPtr; ------------------------------------------- class A { public: A(const Ice::ObjectAdapter &adapter,const AAPtr aa): _adapter(adapter),_aai(aa); { Ice::Identity id; id.name = // some unique name; _adapter->add(_aai,id) }; void login(); void IsLogin() { return _aai.IsLogin(); }; private: AAPtr _aai // * a member of class A std::string _name; Demo::ChatPrx _chati; // * a member of class A Ice::ObjectAdapter _adapter; std::string _name; } // implementation of functon login() using login_async void A::login() { Ice::Identity id; id.name = // some unique name; AMI_Chat_loginPtr amiptr = new AMI_Chat_loginI(_adapter->createProxy(id)); _chati->login_async(amiptr,"kin"); } void A::loginResult(bool ret, const ::Ice::Current&) { _IsLogin= ret; // more codes here // the new value _IsLogin can be used anywhere in class A } ----------------------------------------- class AMI_Chat_loginI : public Demo::AMI_Chat_login { AMI_Chat_loginI(const Ice::ObjectPrx& proxy):_proxy(proxy) {}; void ice_response(bool res) { APrx proxy = APrx::uncheckedCast(_proxy); proxy ->loginResult(res); } void ice_exception(const ::Ice::Exception&){} private: Ice::ObjectPrx _proxy; }
__________________
kin Young university: Sun Yat-sen University url: http://www.sysu.edu.cn learning ICE.
Last edited by nyingchi : 09-18-2006 at 07:37 AM. |
|
||||||
|
Hi,
Why do you define another Slice interface, AA, just to pass the result of the login operation? It would be much simpler to just pass the reference of your `A' class as I've mentioned above. Cheers, Benoit. |
|
|||||
|
In my application, it is necessary to define another slice because it has more responsibilities.
the reference idea is more simple. and now i use it . ![]()
__________________
kin Young university: Sun Yat-sen University url: http://www.sysu.edu.cn learning ICE.
|
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Is it possible or how hard to port ICE to WinCE? | zhangzq71 | Help Center | 2 | 03-31-2005 09:13 AM |