Linux multi-monitor fullscreen support
[ryzomcore.git] / nel / samples / net / class_transport / gd_service.cpp
blobc2b0b2a583c7692ff4b8c39f2ba190a5a2d53a10
1 // NeL - MMORPG Framework <http://dev.ryzom.com/projects/nel/>
2 // Copyright (C) 2010 Winch Gate Property Limited
3 //
4 // This source file has been modified by the following contributors:
5 // Copyright (C) 2014 Jan BOON (Kaetemi) <jan.boon@kaetemi.be>
6 //
7 // This program is free software: you can redistribute it and/or modify
8 // it under the terms of the GNU Affero General Public License as
9 // published by the Free Software Foundation, either version 3 of the
10 // License, or (at your option) any later version.
12 // This program is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU Affero General Public License for more details.
17 // You should have received a copy of the GNU Affero General Public License
18 // along with this program. If not, see <http://www.gnu.org/licenses/>.
22 * Transport class example, gd server.
24 * This service have a class (CSharedClass) that send to other service when online.
26 * To run this program, ensure there is a file "gd_service.cfg"
27 * containing the location of the naming service (NSHost, NSPort)
28 * in the working directory. The naming service must be running.
32 // Includes
35 // We're using the NeL Service framework, and layer 5
36 #include "nel/net/service.h"
37 #include "nel/misc/time_nl.h"
38 #include "nel/misc/displayer.h"
40 #include "nel/net/transport_class.h"
42 #ifdef NL_OS_WINDOWS
43 # ifndef NL_COMP_MINGW
44 # define NOMINMAX
45 # endif
46 # include <windows.h>
47 #endif // NL_OS_WINDOWS
49 #ifndef NL_CT_CFG
50 #define NL_CT_CFG ""
51 #endif // NL_CT_CFG
54 // Namespace
57 using namespace std;
58 using namespace NLNET;
59 using namespace NLMISC;
62 // Shared Class
65 struct CSharedClass : public CTransportClass
67 uint32 i1, i2, i3;
68 float f1;
70 vector<uint32> vi1;
72 string str;
74 CEntityId eid;
76 CSharedClass () : i1(10), i2(10), i3(10), f1(10), str("str10") { vi1.push_back(111); vi1.push_back(222); vi1.push_back(255); }
78 virtual void description ()
80 className ("SharedClass");
81 property ("i1", PropUInt32, (uint32)11, i1);
82 property ("f1", PropFloat, 1.5f, f1);
83 // property ("i2", PropUInt32, (uint32)12, i2);
84 property ("i3", PropUInt32, (uint32)13, i3);
85 propertyCont ("vi1", PropUInt32, vi1);
86 property ("str", PropString, (string)"str12", str);
87 // property ("eid", PropEntityId, CEntityId::Unknown, eid);
90 virtual void callback (const string &name, uint8 sid)
92 nlinfo ("Yes! I receive a Shared class from '%s' %d", name.c_str(), sid);
97 // Variables
100 static CSharedClass SharedClass;
103 // Functions
106 static void cbUpService (const std::string &serviceName, uint16 sid, void *arg)
108 // When a service comes, send the new class
109 CSharedClass foo;
110 foo.send((TServiceId)sid);
114 // Service class
117 struct CGDService : public IService
119 void init()
121 // callback when a new service comes
122 CUnifiedNetwork::getInstance()->setServiceUpCallback("*", (TUnifiedNetCallback)cbUpService, NULL);
124 // init the class transport system
125 CTransportClass::init ();
127 // register the shared class
128 TRANSPORT_CLASS_REGISTER (CSharedClass);
131 void release ()
133 // release all the class transport system
134 CTransportClass::release ();
140 * Declare a service with the class IService, the names "GDS" (short) and "gd_service" (long).
141 * The port is automatically allocated (0) and the main callback array is empty.
143 NLNET_SERVICE_MAIN( CGDService, "GDS", "gd_service", 0, EmptyCallbackArray, NL_CT_CFG, "" )