Permalink
Browse files

From Stephan Huber, ZerConfDevice plugin for Windows and Apple

  • Loading branch information...
1 parent 5030175 commit fb35cb3f3cb8f5cc7f3f891f6730d303374d04ce @osg-training-guest osg-training-guest committed Dec 6, 2012
@@ -0,0 +1,71 @@
+/*
+ * AutoDiscovery.cpp
+ * cefix_alterable
+ *
+ * Created by Stephan Huber on 10.09.11.
+ * Copyright 2011 Digital Mind. All rights reserved.
+ *
+ */
+
+#include "AutoDiscovery.h"
+
+#ifdef __APPLE__
+#include "AutoDiscoveryBonjourImpl.h"
+#else
+#include "AutoDiscoveryWinImpl.h"
+#endif
+
+
+
+
+
+
+DiscoveredServicesCallback::DiscoveredServicesCallback()
+: osg::Referenced()
+{
+}
+
+
+AutoDiscovery::~AutoDiscovery()
+{
+ if (_clientImpl) {
+ delete _clientImpl;
+ _clientImpl = NULL;
+ }
+ deregisterServices();
+}
+
+
+void AutoDiscovery::registerService(const std::string& type, unsigned int port)
+{
+ deregisterServices();
+ _serverImpl = new AutoDiscoveryServerImpl(type, port);
+}
+
+void AutoDiscovery::deregisterServices()
+{
+ if (_serverImpl) {
+ delete _serverImpl;
+ _serverImpl = NULL;
+ }
+}
+
+
+
+void AutoDiscovery::update()
+{
+ if (_serverImpl)
+ _serverImpl->update();
+ if (_clientImpl)
+ _clientImpl->update();
+}
+
+void AutoDiscovery::discoverServices(const std::string& type, DiscoveredServicesCallback* cb)
+{
+ _clientImpl = new AutoDiscoveryClientImpl(type, cb);
+}
+
+bool AutoDiscovery::needsContinuousUpdate() const
+{
+ return (((_clientImpl) && _clientImpl->needsTimer()) || ((_serverImpl) && _serverImpl->needsTimer()));
+}
@@ -0,0 +1,47 @@
+/*
+ * AutoDiscovery.h
+ * cefix_alterable
+ *
+ * Created by Stephan Huber on 10.09.11.
+ * Copyright 2011 Digital Mind. All rights reserved.
+ *
+ */
+
+#pragma once
+
+#include <string>
+#include <osg/Referenced>
+
+
+class AutoDiscoveryServerImpl;
+class AutoDiscoveryClientImpl;
+
+
+class DiscoveredServicesCallback : public osg::Referenced {
+public:
+ DiscoveredServicesCallback();
+ virtual bool ignoreIP6Addresses() { return false; }
+ virtual void serviceAdded(const std::string& host, unsigned int port) = 0;
+ virtual void serviceRemoved(const std::string& host, unsigned int port) = 0;
+};
+
+class AutoDiscovery : public osg::Referenced {
+public:
+ AutoDiscovery() : _serverImpl(NULL), _clientImpl(NULL) {};
+
+ void registerService(const std::string& type, unsigned int port);
+ void deregisterServices();
+ void discoverServices(const std::string& type, DiscoveredServicesCallback* cb);
+
+ ~AutoDiscovery();
+
+ void update();
+
+ bool needsContinuousUpdate() const;
+
+private:
+
+ AutoDiscoveryServerImpl* _serverImpl;
+ AutoDiscoveryClientImpl* _clientImpl;
+
+};
@@ -0,0 +1,60 @@
+/*
+ * AutoDiscoveryBonjourImpl.h
+ * cefix_alterable
+ *
+ * Created by Stephan Huber on 10.09.11.
+ * Copyright 2011 Digital Mind. All rights reserved.
+ *
+ */
+
+#pragma once
+
+#include <string>
+#include <map>
+#include <vector>
+#include <osg/observer_ptr>
+
+#ifdef __OBJC__
+@class ServerController;
+@class ClientController;
+#else
+class ServerController;
+class ClientController;
+#endif
+
+class DiscoveredServicesCallback;
+
+
+class AutoDiscoveryServerImpl {
+
+public:
+ AutoDiscoveryServerImpl(const std::string& type, unsigned int port);
+ ~AutoDiscoveryServerImpl();
+
+ bool needsTimer() const { return false; }
+ void update() {}
+private:
+ ServerController* _controller;
+
+};
+
+class AutoDiscoveryClientImpl {
+public:
+ typedef std::pair< std::string, unsigned int> Address;
+ typedef std::vector<Address> AddressVector;
+ typedef std::map<void*, AddressVector> AddressMap;
+
+ AutoDiscoveryClientImpl(const std::string& type, DiscoveredServicesCallback* cb);
+ ~AutoDiscoveryClientImpl();
+ DiscoveredServicesCallback* getCallback() { return _cb.get(); }
+
+ void serviceAdded(void* key, const std::string& address, unsigned int port, bool is_ip6);
+ void servicesRemoved(void* key);
+ bool needsTimer() const { return false; }
+ void update() {}
+private:
+ ClientController* _controller;
+ osg::ref_ptr<DiscoveredServicesCallback> _cb;
+ AddressMap _addresses;
+
+};
Oops, something went wrong.

0 comments on commit fb35cb3

Please sign in to comment.