odk/CustomTarget_build-examples.mk                                             
|    1 
 odk/CustomTarget_build-examples_java.mk                                        
|    2 
 odk/Package_examples.mk                                                        
|    8 
 odk/examples/DevelopersGuide/OfficeDev/TerminationTest/cxx/Makefile            
|   77 +++++++
 odk/examples/DevelopersGuide/OfficeDev/TerminationTest/cxx/TerminationTest.cxx 
|   98 ++++++++++
 odk/examples/DevelopersGuide/OfficeDev/TerminationTest/java/Makefile           
|    2 
 6 files changed, 183 insertions(+), 5 deletions(-)

New commits:
commit c299e54ce2edf2b8b3b21754ed9fd16cdf6167b3
Author:     RMZeroFour <ritobrot...@gmail.com>
AuthorDate: Wed Apr 10 01:37:42 2024 +0530
Commit:     Hossein <hoss...@libreoffice.org>
CommitDate: Tue Apr 30 15:01:19 2024 +0200

    tdf#143122 Port Java TerminationTest example to C++
    
    This patch ports odk/examples/DevelopersGuide/OfficeDev/TerminationTest
    example to C++.
    
    The original Java example code was moved to a java/ subdirectory, and
    the new C++ code was added to the cxx/ subdirectory. Necessary changes
    were made in the corresponding Makefiles.
    
    Along with the code in TerminationTest.java, the TerminateListener
    class was also ported and used in the same C++ file.
    
    Change-Id: I889b8893740bc8f80cdd9aa9925e83cadcea9592
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/165916
    Tested-by: Jenkins
    Tested-by: Hossein <hoss...@libreoffice.org>
    Reviewed-by: Hossein <hoss...@libreoffice.org>

diff --git a/odk/CustomTarget_build-examples.mk 
b/odk/CustomTarget_build-examples.mk
index 50131ecb4f99..476da4e61078 100644
--- a/odk/CustomTarget_build-examples.mk
+++ b/odk/CustomTarget_build-examples.mk
@@ -19,6 +19,7 @@ my_example_dirs = \
     DevelopersGuide/Database/DriverSkeleton \
     DevelopersGuide/Extensions/DialogWithHelp \
     DevelopersGuide/OfficeDev/FilterDevelopment/FlatXmlFilter_cpp \
+    DevelopersGuide/OfficeDev/TerminationTest/cxx \
     DevelopersGuide/ProfUNO/CppBinding \
     DevelopersGuide/ProfUNO/SimpleBootstrap_cpp \
     OLE/activex \
diff --git a/odk/CustomTarget_build-examples_java.mk 
b/odk/CustomTarget_build-examples_java.mk
index 15be0a2c6a47..7b4f9c8eb234 100644
--- a/odk/CustomTarget_build-examples_java.mk
+++ b/odk/CustomTarget_build-examples_java.mk
@@ -35,7 +35,7 @@ my_example_dirs_java = \
     DevelopersGuide/OfficeDev/Linguistic \
     DevelopersGuide/OfficeDev/PathSettings \
     DevelopersGuide/OfficeDev/PathSubstitution \
-    DevelopersGuide/OfficeDev/TerminationTest \
+    DevelopersGuide/OfficeDev/TerminationTest/java \
     DevelopersGuide/ProfUNO/InterprocessConn \
     DevelopersGuide/ProfUNO/Lifetime \
     DevelopersGuide/ProfUNO/SimpleBootstrap_java \
diff --git a/odk/Package_examples.mk b/odk/Package_examples.mk
index f575e70aae1e..f8a29340f53c 100644
--- a/odk/Package_examples.mk
+++ b/odk/Package_examples.mk
@@ -322,9 +322,11 @@ $(eval $(call 
gb_Package_add_files_with_dir,odk_examples,$(SDKDIRNAME)/examples,
     DevelopersGuide/OfficeDev/PathSettings/PathSettingsTest.java \
     DevelopersGuide/OfficeDev/PathSubstitution/Makefile \
     DevelopersGuide/OfficeDev/PathSubstitution/PathSubstitutionTest.java \
-    DevelopersGuide/OfficeDev/TerminationTest/Makefile \
-    DevelopersGuide/OfficeDev/TerminationTest/TerminateListener.java \
-    DevelopersGuide/OfficeDev/TerminationTest/TerminationTest.java \
+    DevelopersGuide/OfficeDev/TerminationTest/cxx/Makefile \
+    DevelopersGuide/OfficeDev/TerminationTest/cxx/TerminationTest.cxx \
+    DevelopersGuide/OfficeDev/TerminationTest/java/Makefile \
+    DevelopersGuide/OfficeDev/TerminationTest/java/TerminateListener.java \
+    DevelopersGuide/OfficeDev/TerminationTest/java/TerminationTest.java \
     DevelopersGuide/ProfUNO/CppBinding/Makefile \
     DevelopersGuide/ProfUNO/CppBinding/office_connect.cxx \
     DevelopersGuide/ProfUNO/CppBinding/string_samples.cxx \
diff --git 
a/odk/examples/DevelopersGuide/OfficeDev/TerminationTest/cxx/Makefile 
b/odk/examples/DevelopersGuide/OfficeDev/TerminationTest/cxx/Makefile
new file mode 100644
index 000000000000..354a4db7ff14
--- /dev/null
+++ b/odk/examples/DevelopersGuide/OfficeDev/TerminationTest/cxx/Makefile
@@ -0,0 +1,77 @@
+# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t; fill-column: 
100 -*-
+#
+# This file is part of the LibreOffice project.
+#
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+#
+
+# Builds the TerminationTest example of the SDK.
+
+PRJ=../../../../..
+SETTINGS=$(PRJ)/settings
+
+include $(SETTINGS)/settings.mk
+include $(SETTINGS)/std.mk
+
+# Define non-platform/compiler specific settings
+APP_NAME=TerminationTest
+
+OUT_APP_INC = $(OUT_INC)/$(APP_NAME)
+OUT_APP_GEN = $(OUT_MISC)/$(APP_NAME)
+OUT_APP_OBJ=$(OUT_OBJ)/$(APP_NAME)
+
+CXXFILES = TerminationTest.cxx
+
+OBJFILES = $(patsubst %.cxx,$(OUT_SLO_COMP)/%.$(OBJ_EXT),$(CXXFILES))
+
+# Targets
+.PHONY: ALL
+ALL : \
+       TerminationTest
+
+include $(SETTINGS)/stdtarget.mk
+
+$(OUT_APP_OBJ)/%.$(OBJ_EXT) : %.cxx $(SDKTYPEFLAG)
+       -$(MKDIR) $(subst /,$(PS),$(@D))
+       $(CC) $(CC_FLAGS) $(CC_INCLUDES) -I$(OUT_APP_INC) $(CC_DEFINES) 
$(CC_OUTPUT_SWITCH)$(subst /,$(PS),$@) $<
+
+$(OUT_BIN)/_$(APP_NAME)$(EXE_EXT) : $(OUT_APP_OBJ)/$(APP_NAME).$(OBJ_EXT)
+       -$(MKDIR) $(subst /,$(PS),$(@D))
+       -$(MKDIR) $(subst /,$(PS),$(OUT_APP_GEN))
+ifeq "$(OS)" "WIN"
+       $(LINK) $(EXE_LINK_FLAGS) /OUT:$@ /MAP:$(OUT_APP_GEN)/$(basename 
$(@F)).map \
+         $< $(CPPUHELPERLIB) $(CPPULIB) $(SALHELPERLIB) $(SALLIB)
+else
+       $(LINK) $(EXE_LINK_FLAGS) $(LINK_LIBS) -o $@ $< \
+         $(CPPUHELPERLIB) $(CPPULIB) $(SALHELPERLIB) $(SALLIB) $(STDC++LIB)
+ifeq "$(OS)" "MACOSX"
+       $(INSTALL_NAME_URELIBS_BIN)  $@
+endif
+endif
+
+$(OUT_BIN)/$(APP_NAME)$(EXE_EXT) : $(OUT_BIN)/_$(APP_NAME)$(EXE_EXT)
+       -$(MKDIR) $(subst /,$(PS),$(@D))
+       $(COPY) $(subst /,$(PS),$(BIN_DIR)/unoapploader$(EXE_EXT)) $(subst 
/,$(PS),$@)
+# workaround for touch problem under Windows with full qualified paths
+       make -t $@
+
+TerminationTest: $(OUT_BIN)/$(APP_NAME)$(EXE_EXT)
+       @echo 
--------------------------------------------------------------------------------
+       @echo Please use the following command to execute the example!
+       @echo -
+       @echo $(MAKE) TerminationTest.run
+       @echo 
--------------------------------------------------------------------------------
+
+%.run: $(OUT_BIN)/TerminationTest$(EXE_EXT)
+       cd $(subst /,$(PS),$(OUT_BIN)) && $(basename $@)
+
+.PHONY: clean
+clean :
+       -$(DELRECURSIVE) $(subst /,$(PS),$(OUT_APP_INC))
+       -$(DELRECURSIVE) $(subst /,$(PS),$(OUT_APP_GEN))
+       -$(DELRECURSIVE) $(subst /,$(PS),$(OUT_APP_OBJ))
+       -$(DEL) $(subst \,\,$(subst /,$(PS),$(OUT_BIN)/*TerminationTest*))
+
+# vim: set noet sw=4 ts=4:
diff --git 
a/odk/examples/DevelopersGuide/OfficeDev/TerminationTest/cxx/TerminationTest.cxx
 
b/odk/examples/DevelopersGuide/OfficeDev/TerminationTest/cxx/TerminationTest.cxx
new file mode 100644
index 000000000000..f783ca6ec89f
--- /dev/null
+++ 
b/odk/examples/DevelopersGuide/OfficeDev/TerminationTest/cxx/TerminationTest.cxx
@@ -0,0 +1,98 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; 
fill-column: 100 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#include <sal/main.h>
+#include <cppuhelper/bootstrap.hxx>
+#include <cppuhelper/implbase1.hxx>
+#include <com/sun/star/uno/XComponentContext.hpp>
+#include <com/sun/star/lang/XMultiComponentFactory.hpp>
+#include <com/sun/star/frame/XDesktop.hpp>
+#include <com/sun/star/frame/XTerminateListener.hpp>
+#include <com/sun/star/frame/TerminationVetoException.hpp>
+
+#include <iostream>
+
+using namespace ::cppu;
+using namespace ::css::uno;
+using namespace ::css::lang;
+using namespace ::css::frame;
+
+namespace
+{
+bool atWork = false;
+}
+
+class TerminateListener : public WeakImplHelper1<XTerminateListener>
+{
+public:
+    // XTerminateListener
+    virtual void SAL_CALL notifyTermination(const EventObject& event) 
SAL_OVERRIDE
+    {
+        std::cout << "About to terminate...
";
+    }
+
+    virtual void SAL_CALL queryTermination(const EventObject& event) 
SAL_OVERRIDE
+    {
+        // Test if we can terminate now
+        if (atWork)
+        {
+            std::cout << "Terminate while we are at work? You can't be serious 
;-)!
";
+            throw TerminationVetoException();
+        }
+    }
+
+    // XEventListener
+    virtual void SAL_CALL disposing(const EventObject& event) SAL_OVERRIDE {}
+};
+
+SAL_IMPLEMENT_MAIN()
+{
+    try
+    {
+        // Connect to, or create, an instance of the Office.
+        Reference<XComponentContext> xContext(bootstrap());
+        std::cout << "Connected to a running office...
";
+
+        // Get a reference to the multi-component factory, and use it
+        // to create a Desktop reference.
+        Reference<XMultiComponentFactory> xMCF(xContext->getServiceManager());
+        Reference<XDesktop> xDesktop(
+            xMCF->createInstanceWithContext("com.sun.star.frame.Desktop", 
xContext),
+            UNO_QUERY_THROW);
+
+        // Create our termination request listener, and register it.
+        TerminateListener listener;
+        Reference<XTerminateListener> xTerminateListener(listener, 
UNO_QUERY_THROW);
+        xDesktop->addTerminateListener(xTerminateListener);
+
+        // Try to terminate while we are at work.
+        atWork = true;
+        bool terminated = xDesktop->terminate();
+        std::cout << "The Office "
+                  << (terminated ? "has been terminated" : "is still running, 
we are at work.")
+                  << '
';
+
+        // Try to terminate when we are NOT at work.
+        atWork = false;
+        terminated = xDesktop->terminate();
+        std::cout << "The Office "
+                  << (terminated ? "has been terminated"
+                                 : "is still running. Something else prevents 
termination,"
+                                   "such as the quickstarter.")
+                  << '
';
+    }
+    catch (const RuntimeException& e)
+    {
+        std::cerr << e.Message << '
';
+        return 1;
+    }
+    return 0;
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s 
cinkeys+=0=break: */
diff --git a/odk/examples/DevelopersGuide/OfficeDev/TerminationTest/Makefile 
b/odk/examples/DevelopersGuide/OfficeDev/TerminationTest/java/Makefile
similarity index 99%
rename from odk/examples/DevelopersGuide/OfficeDev/TerminationTest/Makefile
rename to odk/examples/DevelopersGuide/OfficeDev/TerminationTest/java/Makefile
index ae3d607cfe72..8542ac3b5684 100644
--- a/odk/examples/DevelopersGuide/OfficeDev/TerminationTest/Makefile
+++ b/odk/examples/DevelopersGuide/OfficeDev/TerminationTest/java/Makefile
@@ -34,7 +34,7 @@
 
 # Builds the OfficeDevClipboard example of the Developers Guide.
 
-PRJ=../../../..
+PRJ=../../../../..
 SETTINGS=$(PRJ)/settings
 
 include $(SETTINGS)/settings.mk
diff --git 
a/odk/examples/DevelopersGuide/OfficeDev/TerminationTest/TerminateListener.java 
b/odk/examples/DevelopersGuide/OfficeDev/TerminationTest/java/TerminateListener.java
similarity index 100%
rename from 
odk/examples/DevelopersGuide/OfficeDev/TerminationTest/TerminateListener.java
rename to 
odk/examples/DevelopersGuide/OfficeDev/TerminationTest/java/TerminateListener.java
diff --git 
a/odk/examples/DevelopersGuide/OfficeDev/TerminationTest/TerminationTest.java 
b/odk/examples/DevelopersGuide/OfficeDev/TerminationTest/java/TerminationTest.java
similarity index 100%
rename from 
odk/examples/DevelopersGuide/OfficeDev/TerminationTest/TerminationTest.java
rename to 
odk/examples/DevelopersGuide/OfficeDev/TerminationTest/java/TerminationTest.java

Reply via email to