diff options
-rw-r--r-- | sd/CppunitTest_sd_uimpress.mk | 1 | ||||
-rw-r--r-- | sd/source/ui/remotecontrol/AvahiNetworkService.cxx | 124 | ||||
-rw-r--r-- | sd/source/ui/remotecontrol/AvahiNetworkService.hxx | 7 | ||||
-rw-r--r-- | sd/source/ui/remotecontrol/DiscoveryService.cxx | 23 | ||||
-rw-r--r-- | sd/source/ui/remotecontrol/DiscoveryService.hxx | 12 | ||||
-rw-r--r-- | sd/source/ui/remotecontrol/OSXNetworkService.mm | 2 | ||||
-rw-r--r-- | sd/source/ui/remotecontrol/ZeroconfService.cxx | 45 | ||||
-rw-r--r-- | sd/source/ui/remotecontrol/ZeroconfService.hxx | 21 | ||||
-rw-r--r-- | sd/source/ui/sidebar/PanelFactory.cxx | 2 |
9 files changed, 145 insertions, 92 deletions
diff --git a/sd/CppunitTest_sd_uimpress.mk b/sd/CppunitTest_sd_uimpress.mk index 5fb5961196cb..8fa24f522ecc 100644 --- a/sd/CppunitTest_sd_uimpress.mk +++ b/sd/CppunitTest_sd_uimpress.mk @@ -75,6 +75,7 @@ $(eval $(call gb_CppunitTest_use_externals,sd_uimpress,\ boost_headers \ gtk \ dbus \ + avahi \ )) $(eval $(call gb_CppunitTest_add_exception_objects,sd_uimpress,\ diff --git a/sd/source/ui/remotecontrol/AvahiNetworkService.cxx b/sd/source/ui/remotecontrol/AvahiNetworkService.cxx index 2da4a74b6106..8947e8d3a024 100644 --- a/sd/source/ui/remotecontrol/AvahiNetworkService.cxx +++ b/sd/source/ui/remotecontrol/AvahiNetworkService.cxx @@ -1,22 +1,3 @@ -/*** - This file is part of avahi. - - avahi is free software; you can redistribute it and/or modify it - under the terms of the GNU Lesser General Public License as - published by the Free Software Foundation; either version 2.1 of the - License, or (at your option) any later version. - - avahi is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General - Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with avahi; if not, write to the Free Software - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 - USA. -***/ - #ifdef HAVE_CONFIG_H #include <config.h> #endif @@ -30,72 +11,21 @@ #include <avahi-client/publish.h> #include <avahi-common/alternative.h> -#include <avahi-common/simple-watch.h> #include <avahi-common/malloc.h> #include <avahi-common/error.h> #include <avahi-common/timeval.h> +#include <avahi-common/thread-watch.h> #include "AvahiNetworkService.hxx" +static AvahiClient *client = NULL; +static AvahiThreadedPoll *threaded_poll = NULL; static AvahiEntryGroup *group = NULL; -static AvahiSimplePoll *simple_poll = NULL; static char *name = NULL; static void create_services(AvahiClient *c); -static void entry_group_callback(AvahiEntryGroup *g, AvahiEntryGroupState state, AVAHI_GCC_UNUSED void *userdata); - static void client_callback(AvahiClient *c, AvahiClientState state, AVAHI_GCC_UNUSED void * userdata); -int start_avahi_service(const char * serviceName){ - AvahiClient *client = NULL; - int error; - int ret = 1; - - name = avahi_strdup(serviceName); - - /* Allocate main loop object */ - if (!(simple_poll = avahi_simple_poll_new())) { - fprintf(stderr, "Failed to create simple poll object.\n"); - goto fail; - } - - /* Allocate a new client */ - client = avahi_client_new(avahi_simple_poll_get(simple_poll), static_cast<AvahiClientFlags>(0), client_callback, NULL, &error); - - /* Check wether creating the client object succeeded */ - if (!client) { - fprintf(stderr, "Failed to create client: %s\n", avahi_strerror(error)); - goto fail; - } - - /* Run the main loop */ - avahi_simple_poll_loop(simple_poll); - - ret = 0; - -fail: - - /* Cleanup things */ - - if (client) - avahi_client_free(client); - - if (simple_poll) - avahi_simple_poll_free(simple_poll); - - avahi_free(name); - - return ret; -} - - -void clean_avahi_service(){ - if (simple_poll) - avahi_simple_poll_free(simple_poll); - - avahi_free(name); -} - static void entry_group_callback(AvahiEntryGroup *g, AvahiEntryGroupState state, AVAHI_GCC_UNUSED void *userdata) { assert(g == group || group == NULL); group = g; @@ -129,7 +59,7 @@ static void entry_group_callback(AvahiEntryGroup *g, AvahiEntryGroupState state, fprintf(stderr, "Entry group failure: %s\n", avahi_strerror(avahi_client_errno(avahi_entry_group_get_client(g)))); /* Some kind of failure happened while we were registering our services */ - avahi_simple_poll_quit(simple_poll); + avahi_threaded_poll_quit(threaded_poll); break; case AVAHI_ENTRY_GROUP_UNCOMMITED: @@ -167,12 +97,12 @@ static void create_services(AvahiClient *c) { * same name should be put in the same entry group. */ /* Add the service for IPP */ - if ((ret = avahi_entry_group_add_service(group, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, static_cast<AvahiPublishFlags>(0), name, "_impressremote._tcp", NULL, NULL, 1599, "test=blah", r, NULL)) < 0) { + if ((ret = avahi_entry_group_add_service(group, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, static_cast<AvahiPublishFlags>(0), name, "_impressremote._libreoffice._tcp", NULL, NULL, 1599, "local", r, NULL)) < 0) { if (ret == AVAHI_ERR_COLLISION) goto collision; - fprintf(stderr, "Failed to add _ipp._tcp service: %s\n", avahi_strerror(ret)); + fprintf(stderr, "Failed to add _impressremote._libreoffice._tcp service: %s\n", avahi_strerror(ret)); goto fail; } @@ -201,7 +131,7 @@ collision: return; fail: - avahi_simple_poll_quit(simple_poll); + avahi_shutdown(); } static void client_callback(AvahiClient *c, AvahiClientState state, AVAHI_GCC_UNUSED void * userdata) { @@ -220,7 +150,7 @@ static void client_callback(AvahiClient *c, AvahiClientState state, AVAHI_GCC_UN case AVAHI_CLIENT_FAILURE: fprintf(stderr, "Client failure: %s\n", avahi_strerror(avahi_client_errno(c))); - avahi_simple_poll_quit(simple_poll); + avahi_shutdown(); break; @@ -245,4 +175,40 @@ static void client_callback(AvahiClient *c, AvahiClientState state, AVAHI_GCC_UN case AVAHI_CLIENT_CONNECTING: ; } -}
\ No newline at end of file +} + + + + +void avahi_setup(const char * sname) { + /* Call this when the application starts up. */ + int error = 0; + name = avahi_strdup( sname ); + if (!(threaded_poll = avahi_threaded_poll_new())) { + fprintf(stderr, "avahi_threaded_poll_new '%s' failed.\n", name); + return; + } + + if (!(client = avahi_client_new(avahi_threaded_poll_get(threaded_poll), static_cast<AvahiClientFlags>(0), client_callback, NULL, &error))) { + fprintf(stderr, "avahi_client_new failed.\n"); + return; + } + + create_services(client); + + /* Finally, start the event loop thread */ + if (avahi_threaded_poll_start(threaded_poll) < 0) { + fprintf(stderr, "avahi_threaded_poll_start failed.\n"); + return; + } + + fprintf(stderr, "setup done.\n"); +} + +void avahi_shutdown(void) { + /* Call this when the app shuts down */ + + avahi_threaded_poll_stop(threaded_poll); + avahi_client_free(client); + avahi_threaded_poll_free(threaded_poll); +} diff --git a/sd/source/ui/remotecontrol/AvahiNetworkService.hxx b/sd/source/ui/remotecontrol/AvahiNetworkService.hxx index cc223e0aad35..64feb9948043 100644 --- a/sd/source/ui/remotecontrol/AvahiNetworkService.hxx +++ b/sd/source/ui/remotecontrol/AvahiNetworkService.hxx @@ -1,5 +1,6 @@ #ifndef AVAHI_NETWORK_SERVICE_H #define AVAHI_NETWORK_SERVICE_H - int start_avahi_service(const char * serviceName); - void clean_avahi_service(); -#endif
\ No newline at end of file + + void avahi_setup(const char *); + void avahi_shutdown(void); +#endif diff --git a/sd/source/ui/remotecontrol/DiscoveryService.cxx b/sd/source/ui/remotecontrol/DiscoveryService.cxx index cae88f148270..1e2472c1c81b 100644 --- a/sd/source/ui/remotecontrol/DiscoveryService.cxx +++ b/sd/source/ui/remotecontrol/DiscoveryService.cxx @@ -12,6 +12,8 @@ #include <string.h> #include <algorithm> #include <vector> +#include <thread> +#include <iostream> #include <comphelper/processfactory.hxx> #include <rtl/strbuf.hxx> @@ -52,13 +54,17 @@ using namespace sd; DiscoveryService::DiscoveryService() { #ifdef MACOSX - OSXNetworkService * service = [[OSXNetworkService alloc] init]; - [service publishImpressRemoteServiceOnLocalNetworkWithName: @""]; +// Bonjour for OSX + osxservice = [[OSXNetworkService alloc] init]; + [osxservice publishImpressRemoteServiceOnLocalNetworkWithName: @""]; #endif - #ifdef LINUX // Avahi for Linux - start_avahi_service("HP"); + char hostname[1024]; + hostname[1023] = '\0'; + gethostname(hostname, 1023); + std::cerr << " AVAHI SETUP Called" << std::endl; + avahi_setup(hostname); #endif mSocket = socket( AF_INET, SOCK_DGRAM, IPPROTO_UDP ); @@ -99,7 +105,11 @@ DiscoveryService::DiscoveryService() DiscoveryService::~DiscoveryService() { #ifdef LINUX - clean_avahi_service(); + avahi_shutdown(); + #endif + + #ifdef MACOSX + [osxservice dealloc]; #endif #ifdef WNT @@ -107,12 +117,10 @@ DiscoveryService::~DiscoveryService() #else close( mSocket ); #endif -// #endif } void SAL_CALL DiscoveryService::run() { -// #ifndef MACOSX char aBuffer[BUFFER_SIZE]; while ( true ) { @@ -136,7 +144,6 @@ void SAL_CALL DiscoveryService::run() } } } -// #endif } DiscoveryService *sd::DiscoveryService::spService = NULL; diff --git a/sd/source/ui/remotecontrol/DiscoveryService.hxx b/sd/source/ui/remotecontrol/DiscoveryService.hxx index 846b2119fcaf..15e98cc6e249 100644 --- a/sd/source/ui/remotecontrol/DiscoveryService.hxx +++ b/sd/source/ui/remotecontrol/DiscoveryService.hxx @@ -20,6 +20,15 @@ #include <rtl/ref.hxx> #include <osl/thread.hxx> +#ifdef MACOSX + #include <osl/conditn.hxx> // Include this early to avoid error as check() gets defined by some SDK header to empty + #include <premac.h> + #import <CoreFoundation/CoreFoundation.h> + #include <postmac.h> + #import "OSXNetworkService.h" +#endif + + /** * The port for use for the main communication between LibO and remote control app. */ @@ -48,6 +57,9 @@ namespace sd virtual void SAL_CALL run(); // osl::DatagramSocket mSocket; + #ifdef MACOSX + OSXNetworkService * osxservice; + #endif int mSocket; }; diff --git a/sd/source/ui/remotecontrol/OSXNetworkService.mm b/sd/source/ui/remotecontrol/OSXNetworkService.mm index 8e81def93ef4..f4feb3e72cae 100644 --- a/sd/source/ui/remotecontrol/OSXNetworkService.mm +++ b/sd/source/ui/remotecontrol/OSXNetworkService.mm @@ -17,7 +17,7 @@ - (void) publishImpressRemoteServiceOnLocalNetworkWithName:(NSString *)sName { - netService = [[NSNetService alloc] initWithDomain:@"local" type:@"_impressremote._tcp" name:sName port:1599]; + netService = [[NSNetService alloc] initWithDomain:@"local" type:@"_impressremote._libreoffice._tcp" name:sName port:1599]; if (netService != nil) { diff --git a/sd/source/ui/remotecontrol/ZeroconfService.cxx b/sd/source/ui/remotecontrol/ZeroconfService.cxx new file mode 100644 index 000000000000..9c105a7e0071 --- /dev/null +++ b/sd/source/ui/remotecontrol/ZeroconfService.cxx @@ -0,0 +1,45 @@ +#include "ZeroconfService.hxx" +#include <string> + + +ZeroconfService::ZeroconfService(string aname = "", uint aport = 1599) + :port(aport), name(aname) +{ + // Defined in subclasses + this->setup(); + + mSocket = socket( AF_INET, SOCK_DGRAM, IPPROTO_UDP ); + + sockaddr_in aAddr; + memset(&aAddr, 0, sizeof(aAddr)); + aAddr.sin_family = AF_INET; + aAddr.sin_addr.s_addr = htonl(INADDR_ANY); + aAddr.sin_port = htons( PORT_DISCOVERY ); + + int rc = bind( mSocket, (sockaddr*) &aAddr, sizeof(sockaddr_in) ); + + if (rc) + { + SAL_WARN("sd", "DiscoveryService: bind failed: " << errno); + return; // would be better to throw, but unsure if caller handles that + } + + struct ip_mreq multicastRequest; + + multicastRequest.imr_multiaddr.s_addr = inet_addr( "239.0.0.1" ); + multicastRequest.imr_interface.s_addr = htonl(INADDR_ANY); + + rc = setsockopt( mSocket, IPPROTO_IP, IP_ADD_MEMBERSHIP, + #ifdef WNT + (const char*) + #endif + &multicastRequest, sizeof(multicastRequest)); + + if (rc) + { + SAL_WARN("sd", "DiscoveryService: setsockopt failed: " << errno); + return; // would be better to throw, but unsure if caller handles that + } + + SAL_WARN("sd", "ZeroconfService created: " << name << " port:"<< port); +}
\ No newline at end of file diff --git a/sd/source/ui/remotecontrol/ZeroconfService.hxx b/sd/source/ui/remotecontrol/ZeroconfService.hxx new file mode 100644 index 000000000000..f7dc1b56d32c --- /dev/null +++ b/sd/source/ui/remotecontrol/ZeroconfService.hxx @@ -0,0 +1,21 @@ +#ifndef ZEROCONF_SERVICE +#define ZEROCONF_SERVICE + +#include <string> + +class ZeroconfService +{ +private: + string name; + uint port; + +public: + ZeroconfService(string aname = "", uint aport = 1599); + ~ZeroconfService(); + // Clean up the service when closing + virtual void clear() = 0; + // Bonjour for OSX, Avahi for Linux + virtual void setup() = 0; +}; + +#endif diff --git a/sd/source/ui/sidebar/PanelFactory.cxx b/sd/source/ui/sidebar/PanelFactory.cxx index dbdd48b593bd..c2f0a7441eb2 100644 --- a/sd/source/ui/sidebar/PanelFactory.cxx +++ b/sd/source/ui/sidebar/PanelFactory.cxx @@ -78,7 +78,7 @@ Reference<XInterface> SAL_CALL PanelFactory_createInstance ( if (!bSidebar) { SAL_WARN( "sd", "Creating a disabled sidebar factory" ); - return NULL; + return NULL; } return Reference<XInterface>(static_cast<XWeak*>(new PanelFactory(rxContext))); |