Author: arielch Date: Tue Feb 19 15:00:46 2013 New Revision: 1447746 URL: http://svn.apache.org/r1447746 Log: Add C++ example about osl_executeProcess
Added: openoffice/devtools/sdk-examples/ openoffice/devtools/sdk-examples/trunk/ openoffice/devtools/sdk-examples/trunk/cpp/ openoffice/devtools/sdk-examples/trunk/cpp/ProcessTest/ openoffice/devtools/sdk-examples/trunk/cpp/ProcessTest/src/ openoffice/devtools/sdk-examples/trunk/cpp/ProcessTest/src/Makefile (with props) openoffice/devtools/sdk-examples/trunk/cpp/ProcessTest/src/main.cxx openoffice/devtools/sdk-examples/trunk/cpp/ProcessTest/src/test.odt Added: openoffice/devtools/sdk-examples/trunk/cpp/ProcessTest/src/Makefile URL: http://svn.apache.org/viewvc/openoffice/devtools/sdk-examples/trunk/cpp/ProcessTest/src/Makefile?rev=1447746&view=auto ============================================================================== --- openoffice/devtools/sdk-examples/trunk/cpp/ProcessTest/src/Makefile (added) +++ openoffice/devtools/sdk-examples/trunk/cpp/ProcessTest/src/Makefile Tue Feb 19 15:00:46 2013 @@ -0,0 +1,114 @@ +#************************************************************** +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# +#************************************************************** + +# On *nix can be overridden with +# make PRJ=$OO_SDK_HOME +PRJ=../../../.. +SETTINGS=$(PRJ)/settings + +include $(SETTINGS)/settings.mk +include $(SETTINGS)/std.mk +include $(SETTINGS)/dk.mk + +# Define non-platform/compiler specific settings +APP_NAME=processtest +MAINTARGET=$(APP_NAME)_Example +TEST_DOC=test.odt + +#this should be in odk/settings/std.mk +OUT_DEPLOY=$(OUT)/deploy + +OUT_APP_INC=$(OUT_INC)/$(APP_NAME) +OUT_APP_GEN=$(OUT_MISC)/$(APP_NAME) +OUT_APP_OBJ=$(OUT_OBJ)/$(APP_NAME) +OUT_APP_LIB=$(SHAREDLIB_OUT)/$(APP_NAME) +OUT_APP_BIN=$(OUT_BIN)/$(APP_NAME) +OUT_APP_DEPLOY=$(OUT_DEPLOY)/$(APP_NAME) + +CXXFILES = main.cxx + +OBJFILES = $(patsubst %.cxx,$(OUT_APP_OBJ)/%.$(OBJ_EXT),$(CXXFILES)) + +TEST_DOC_URL=$(URLPREFIX)$(OUT_APP_BIN)/$(TEST_DOC) + + +ifneq "$(DEBUG)" "" + CC_DEFINES+=-DOSL_DEBUG_LEVEL=3 +endif + +# Targets +.PHONY: ALL +ALL : \ + $(MAINTARGET) + +include $(SETTINGS)/stdtarget.mk + +$(OUT_APP_OBJ)/%.$(OBJ_EXT) : %.cxx $(SDKTYPEFLAG) + -$(MKDIR) $(subst /,$(PS),$(@D)) + $(CC) $(CC_FLAGS) $(STL_INCLUDES) $(CC_INCLUDES) -I$(OUT_APP_INC) $(CC_DEFINES) $(CC_OUTPUT_SWITCH)$(subst /,$(PS),$@) $< + +$(OUT_APP_BIN)/_$(APP_NAME)$(EXE_EXT) : $(OBJFILES) + -$(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 \ + $(OBJFILES) $(CPPUHELPERLIB) $(CPPULIB) $(SALHELPERLIB) $(SALLIB) $(STLPORTLIB) +else + $(LINK) $(EXE_LINK_FLAGS) $(LINK_LIBS) -o $@ $(OBJFILES) \ + $(CPPUHELPERLIB) $(CPPULIB) $(SALHELPERLIB) $(SALLIB) $(STLPORTLIB) $(STDC++LIB) $(CPPUHELPERDYLIB) $(CPPUDYLIB) $(SALHELPERDYLIB) $(SALDYLIB) +ifeq "$(OS)" "MACOSX" + $(INSTALL_NAME_URELIBS_BIN) $@ +endif +endif + +$(OUT_APP_BIN)/$(APP_NAME)$(EXE_EXT) : $(OUT_APP_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 $@ + +$(OUT_APP_BIN)/$(TEST_DOC) : $(TEST_DOC) + -$(MKDIR) $(subst /,$(PS),$(@D)) + $(COPY) $(subst /,$(PS),$<) $(subst /,$(PS),$@) + + +$(MAINTARGET) : $(OUT_APP_BIN)/$(APP_NAME)$(EXE_EXT) + @echo -------------------------------------------------------------------------------- + @echo Please use the following command to execute the example! + @echo - + @echo $(MAKE) $(APP_NAME).run + @echo -------------------------------------------------------------------------------- + +LAUNCH_PROG=$(OFFICE_PROGRAM_PATH)$(PS)soffice$(EXE_EXT) +LAUNCH_DOC=$(OUT_APP_BIN)$(PS)$(TEST_DOC) + +$(APP_NAME).run: $(OUT_APP_BIN)/$(APP_NAME)$(EXE_EXT) $(OUT_APP_BIN)/$(TEST_DOC) + cd $(subst /,$(PS),$(OUT_APP_BIN)) && $(basename $@) \ + $(LAUNCH_PROG) $(LAUNCH_DOC) + +.PHONY: clean +clean : + -$(DELRECURSIVE) $(subst /,$(PS),$(OUT_APP_INC)) + -$(DELRECURSIVE) $(subst /,$(PS),$(OUT_APP_GEN)) + -$(DELRECURSIVE) $(subst /,$(PS),$(OUT_APP_OBJ)) + -$(DELRECURSIVE) $(subst /,$(PS),$(OUT_APP_LIB)) + -$(DELRECURSIVE) $(subst /,$(PS),$(OUT_APP_BIN)) + -$(DELRECURSIVE) $(subst /,$(PS),$(OUT_APP_DEPLOY)) Propchange: openoffice/devtools/sdk-examples/trunk/cpp/ProcessTest/src/Makefile ------------------------------------------------------------------------------ svn:eol-style = native Added: openoffice/devtools/sdk-examples/trunk/cpp/ProcessTest/src/main.cxx URL: http://svn.apache.org/viewvc/openoffice/devtools/sdk-examples/trunk/cpp/ProcessTest/src/main.cxx?rev=1447746&view=auto ============================================================================== --- openoffice/devtools/sdk-examples/trunk/cpp/ProcessTest/src/main.cxx (added) +++ openoffice/devtools/sdk-examples/trunk/cpp/ProcessTest/src/main.cxx Tue Feb 19 15:00:46 2013 @@ -0,0 +1,146 @@ +/************************************************************** + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + *************************************************************/ + +#include <sal/main.h> +#include <osl/process.h> +#include <osl/file.hxx> +#include <osl/file.hxx> +#include <rtl/ustring.hxx> + +#include <iostream> +#include <vector> + +using rtl::OUString; +using namespace std; +using namespace osl; + +SAL_IMPLEMENT_MAIN_WITH_ARGS( argc, argv ) +{ + oslProcessExitCode nExitCode = 1; + oslProcessError eError; + sal_Int32 nLen; + sal_Int32 n = osl_getCommandArgCount( ); + + if ( n != 2 ) + { + OUString sProgFile; + eError = osl_getExecutableFile( &sProgFile.pData ); + + if ( eError == osl_Process_E_None && ( nLen = sProgFile.getLength( ) ) ) + n = sProgFile.lastIndexOf( sal_Unicode( '/' ) ); + + if ( n != -1 && n < nLen ) + sProgFile = sProgFile.copy( ++n ); + + cerr << "Usage:\n\t" + << rtl::OUStringToOString( sProgFile, RTL_TEXTENCODING_UTF8 ).getStr( ) + << " <soffice_path> <file_to_open>\n"; + } + + OUString sExecutable, sFile, sURL; + + eError = osl_getCommandArg( 0, &sExecutable.pData ); + eError = osl_getCommandArg( 1, &sFile.pData ); + + if ( FileBase::getFileURLFromSystemPath( sExecutable, sURL ) != FileBase::E_None || !sURL.getLength( ) ) + { + cerr << "Cannot convert program path to URL\n"; + return nExitCode; + } + + sExecutable = sURL; + + if ( FileBase::getFileURLFromSystemPath( sFile, sURL ) != FileBase::E_None || !sURL.getLength( ) ) + { + cerr << "Cannot convert document path to URL\n"; + return nExitCode; + } + + // -nologo -nofirststartwizard -norestore -quickstart=no + vector< OUString > vArgs; + vArgs.push_back( OUString( RTL_CONSTASCII_USTRINGPARAM( "-nologo" ) ) ); + vArgs.push_back( OUString( RTL_CONSTASCII_USTRINGPARAM( "-norestore" ) ) ); + vArgs.push_back( OUString( RTL_CONSTASCII_USTRINGPARAM( "-nofirststartwizard" ) ) ); + vArgs.push_back( OUString( RTL_CONSTASCII_USTRINGPARAM( "-quickstart=no" ) ) ); + vArgs.push_back( sURL ); + + oslProcess aProcess; + eError = osl_executeProcess( + /* [in] The file URL of the executable to be started. + * Can be NULL in this case the file URL of the executable + * must be the first element in ustrArguments.*/ + sExecutable.pData, + /* [in] An array of argument strings. + * Can be NULL if strImageName is not NULL. + * If strImageName is NULL it is expected that the first element + * contains the file URL of the executable to start.*/ + &vArgs[0].pData, + /* [in] The number of arguments provided. + * If this number is 0 strArguments will be ignored.*/ + vArgs.size( ), + /* [in] A combination of int-constants to describe the mode of execution.*/ + osl_Process_WAIT | osl_Process_DETACHED, + /* [in] The user and his rights for which the process is started. + * May be NULL in which case the process will be started + * in the context of the current user.*/ + NULL, + /* [in] The file URL of the working directory of the new process. + * If the specified directory does not exist or + * is inaccessible the working directory of the newly created process + * is undefined. + * If this parameter is NULL or the caller provides an empty string + * the new process will have the same current working directory + * as the calling process.*/ + NULL, + /* [in] An array of strings describing environment variables + * that should be merged into the environment of the new process. + * Each string has to be in the form "variable=value". + * This parameter can be NULL in which case the new process gets + * the same environment as the parent process. */ + NULL, + /* [in] The number of environment variables to set.*/ + 0, + /* [out] Pointer to a oslProcess variable, + * which receives the handle of the newly created process. + * This parameter must not be NULL.*/ + &aProcess ); + + if ( eError != osl_Process_E_None ) + return nExitCode; + + oslProcessInfo info; + + info.Size = sizeof ( oslProcessInfo ); + eError = osl_getProcessInfo( aProcess, osl_Process_EXITCODE, &info ); + + if ( eError != osl_Process_E_None ) + return 1; + + if ( info.Fields & osl_Process_EXITCODE ) + { + nExitCode = info.Code; + cout << "Office exit code: " << nExitCode << '\n'; + } + + osl_freeProcessHandle( aProcess ); + + return 0; +} Added: openoffice/devtools/sdk-examples/trunk/cpp/ProcessTest/src/test.odt URL: http://svn.apache.org/viewvc/openoffice/devtools/sdk-examples/trunk/cpp/ProcessTest/src/test.odt?rev=1447746&view=auto ============================================================================== Files openoffice/devtools/sdk-examples/trunk/cpp/ProcessTest/src/test.odt (added) and openoffice/devtools/sdk-examples/trunk/cpp/ProcessTest/src/test.odt Tue Feb 19 15:00:46 2013 differ