Page 1 of 1

C++ API v0.9.6 released

Posted: 11 Jun 2013, 09:27
by Bax
We just released an updated version of the C++ API containing important new features.
Please make sure you read the first comment to this post, as it contains important informations before starting to use the new API.

Release notes
[NEW] BlueBox support added.
[NEW] API refactoring to introduce smart pointers, for better memory management.
[NEW] Funtions having strings as parameters refactored to use values instead of pointers.
[NEW] UTF8 support.
[FIX] Missing "reason" in socket close event.
[FIX] Events processing/dispatching crash when ThreadSafeMode is active.
[FIX] Incorrect behavior of dump() method in SFSArray and SFSObject classes.
[FIX] Error in large messages compression/decompression.
[FIX] ByteArray class not publicily available.

The new API can be downloaded it at this URL: http://www.smartfoxserver.com/download/sfs2x#p=updates (scroll at the bottom)
We also refactored and updated the examples pack here: http://www.smartfoxserver.com/download/sfs2x#p=examples (scroll at the bottom)

Re: C++ API v0.9.6 released

Posted: 11 Jun 2013, 09:47
by MBagnati
Please note that API version 0.9.6 includes features that have an impact on already existing applications:
  • review of parameters in API methods to simplify the exchange of strings and values
  • smart pointers to manage memory usage
So, when you decide to update to version 0.9.6 you should plan a little time to adjust your existing application.

Mainly you must:

  • Change SmartFox initialization

    Replace

    Code: Select all

          Sfs2X::SmartFox* m_ptrSmartFox;               
          m_ptrSmartFox = new Sfs2X::SmartFox(true);

    with

    Code: Select all

          boost::shared_ptr<Sfs2X::SmartFox> m_ptrSmartFox;
          m_ptrSmartFox = boost::shared_ptr<Sfs2X::SmartFox>(new Sfs2X::SmartFox(true));

  • Change registration of event listener

    Replace

    Code: Select all

          m_ptrSmartFox->AddEventListener(SFSEvent::CONNECTION, new EventListenerDelegate(CMyClass::OnSmartFoxConnection, (void*)this));

          void CMyClass::OnSmartFoxConnection(void* ptrContext, BaseEvent* ptrEvent)
          {
             // Get the pointer to my class
             CMyClass* ptrMyClass = (CMyClass*)ptrContext;
             ...

    with

    Code: Select all

          m_ptrSmartFox->AddEventListener(SFSEvent::CONNECTION, boost::shared_ptr<EventListenerDelegate> (new EventListenerDelegate(CMyClass::OnSmartFoxConnection, (unsigned long long)this)));
       
          void CMyClass::OnSmartFoxConnection(unsigned long long ptrContext, boost::shared_ptr<BaseEvent> ptrEvent)
          {
             // Get the pointer to my class
             CMyClass* ptrMyClass = (CMyClass*)ptrContext;
             ...


    Note that the second parameter of event listener delegate (in the above example set to (unsigned long long)this) can be used to pass any opaque information to event handler.

  • Change method call

    Replace

    Code: Select all

          string* filename = new string(".\\Configuration\\sfs-config.xml");   
          m_ptrSmartFox->LoadConfig(filename, true);

    with

    Code: Select all

          m_ptrSmartFox->LoadConfig(".\\Configuration\\sfs-config.xml", true);

    Replace

    Code: Select all

          std::string* stdUsername = new string("UserName");
          std::string* stdZoneName = new string("BasicExamples");

          // Perform login request
          LoginRequest* request = new LoginRequest(stdUsername, NULL, stdZoneName);


    with

    Code: Select all

          boost::shared_ptr<IRequest> request (new LoginRequest("UserName", "", "BasicExamples"));


  • Change event handler

    Replace

    Code: Select all

       void CMyClass::OnSmartFoxPublicMessage(void* ptrContext, BaseEvent* ptrEvent)
       {
          // Get the pointer to my class
          CMyClass* ptrMyClass = (CMyClass*)ptrContext;

          User* ptrNotifiedUser = (User*)((*(ptrEvent->Params()))["sender"]);

          string* ptrNotifiedMessage = (string*)((*(ptrEvent->Params()))["message"]);
          CString csNotifiedMessage(ptrNotifiedMessage->c_str());
       }


    with

    Code: Select all

       void CMyClass::OnSmartFoxPublicMessage(unsigned long long ptrContext, boost::shared_ptr<BaseEvent> ptrEvent)
       {
          // Get the pointer to my class
          CMyClass* ptrMyClass = (CMyClass*)ptrContext;

          boost::shared_ptr<map<string, boost::shared_ptr<void>>> ptrEventParams = ptrEvent->Params();
       
          boost::shared_ptr<void> ptrEventParamValueSender = (*ptrEventParams)["sender"];
          boost::shared_ptr<User> ptrNotifiedUser = ((boost::static_pointer_cast<User>))(ptrEventParamValueSender);

          boost::shared_ptr<void> ptrEventParamValueMessage = (*ptrEventParams)["message"];
          boost::shared_ptr<string> ptrNotifiedMessage = ((boost::static_pointer_cast<string>))(ptrEventParamValueMessage);
       }