src/jdk.jpackage/windows/native/msiwrapper/Executor.h
author herrick
Wed, 28 Aug 2019 11:30:40 -0400
branchJDK-8200758-branch
changeset 57909 c7de06ed4b54
parent 57413 45c74e654794
permissions -rw-r--r--
8229979: jpackage cleanup src files, help text, and javadoc Reviewed-by: asemenyuk, kcr
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
57909
c7de06ed4b54 8229979: jpackage cleanup src files, help text, and javadoc
herrick
parents: 57413
diff changeset
     1
/*
c7de06ed4b54 8229979: jpackage cleanup src files, help text, and javadoc
herrick
parents: 57413
diff changeset
     2
 * Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
c7de06ed4b54 8229979: jpackage cleanup src files, help text, and javadoc
herrick
parents: 57413
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
c7de06ed4b54 8229979: jpackage cleanup src files, help text, and javadoc
herrick
parents: 57413
diff changeset
     4
 *
c7de06ed4b54 8229979: jpackage cleanup src files, help text, and javadoc
herrick
parents: 57413
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
c7de06ed4b54 8229979: jpackage cleanup src files, help text, and javadoc
herrick
parents: 57413
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
c7de06ed4b54 8229979: jpackage cleanup src files, help text, and javadoc
herrick
parents: 57413
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
c7de06ed4b54 8229979: jpackage cleanup src files, help text, and javadoc
herrick
parents: 57413
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
c7de06ed4b54 8229979: jpackage cleanup src files, help text, and javadoc
herrick
parents: 57413
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
c7de06ed4b54 8229979: jpackage cleanup src files, help text, and javadoc
herrick
parents: 57413
diff changeset
    10
 *
c7de06ed4b54 8229979: jpackage cleanup src files, help text, and javadoc
herrick
parents: 57413
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
c7de06ed4b54 8229979: jpackage cleanup src files, help text, and javadoc
herrick
parents: 57413
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
c7de06ed4b54 8229979: jpackage cleanup src files, help text, and javadoc
herrick
parents: 57413
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
c7de06ed4b54 8229979: jpackage cleanup src files, help text, and javadoc
herrick
parents: 57413
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
c7de06ed4b54 8229979: jpackage cleanup src files, help text, and javadoc
herrick
parents: 57413
diff changeset
    15
 * accompanied this code).
c7de06ed4b54 8229979: jpackage cleanup src files, help text, and javadoc
herrick
parents: 57413
diff changeset
    16
 *
c7de06ed4b54 8229979: jpackage cleanup src files, help text, and javadoc
herrick
parents: 57413
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
c7de06ed4b54 8229979: jpackage cleanup src files, help text, and javadoc
herrick
parents: 57413
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
c7de06ed4b54 8229979: jpackage cleanup src files, help text, and javadoc
herrick
parents: 57413
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
c7de06ed4b54 8229979: jpackage cleanup src files, help text, and javadoc
herrick
parents: 57413
diff changeset
    20
 *
c7de06ed4b54 8229979: jpackage cleanup src files, help text, and javadoc
herrick
parents: 57413
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
c7de06ed4b54 8229979: jpackage cleanup src files, help text, and javadoc
herrick
parents: 57413
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
c7de06ed4b54 8229979: jpackage cleanup src files, help text, and javadoc
herrick
parents: 57413
diff changeset
    23
 * questions.
c7de06ed4b54 8229979: jpackage cleanup src files, help text, and javadoc
herrick
parents: 57413
diff changeset
    24
 */
c7de06ed4b54 8229979: jpackage cleanup src files, help text, and javadoc
herrick
parents: 57413
diff changeset
    25
c7de06ed4b54 8229979: jpackage cleanup src files, help text, and javadoc
herrick
parents: 57413
diff changeset
    26
#ifndef EXECUTOR_H
c7de06ed4b54 8229979: jpackage cleanup src files, help text, and javadoc
herrick
parents: 57413
diff changeset
    27
#define EXECUTOR_H
c7de06ed4b54 8229979: jpackage cleanup src files, help text, and javadoc
herrick
parents: 57413
diff changeset
    28
c7de06ed4b54 8229979: jpackage cleanup src files, help text, and javadoc
herrick
parents: 57413
diff changeset
    29
#include "tstrings.h"
c7de06ed4b54 8229979: jpackage cleanup src files, help text, and javadoc
herrick
parents: 57413
diff changeset
    30
#include "UniqueHandle.h"
c7de06ed4b54 8229979: jpackage cleanup src files, help text, and javadoc
herrick
parents: 57413
diff changeset
    31
c7de06ed4b54 8229979: jpackage cleanup src files, help text, and javadoc
herrick
parents: 57413
diff changeset
    32
c7de06ed4b54 8229979: jpackage cleanup src files, help text, and javadoc
herrick
parents: 57413
diff changeset
    33
class Executor {
c7de06ed4b54 8229979: jpackage cleanup src files, help text, and javadoc
herrick
parents: 57413
diff changeset
    34
public:
c7de06ed4b54 8229979: jpackage cleanup src files, help text, and javadoc
herrick
parents: 57413
diff changeset
    35
    explicit Executor(const std::wstring& appPath=std::wstring()) {
c7de06ed4b54 8229979: jpackage cleanup src files, help text, and javadoc
herrick
parents: 57413
diff changeset
    36
        app(appPath).visible(false);
c7de06ed4b54 8229979: jpackage cleanup src files, help text, and javadoc
herrick
parents: 57413
diff changeset
    37
    }
c7de06ed4b54 8229979: jpackage cleanup src files, help text, and javadoc
herrick
parents: 57413
diff changeset
    38
c7de06ed4b54 8229979: jpackage cleanup src files, help text, and javadoc
herrick
parents: 57413
diff changeset
    39
    /**
c7de06ed4b54 8229979: jpackage cleanup src files, help text, and javadoc
herrick
parents: 57413
diff changeset
    40
     * Returns command line configured with arg() calls so far.
c7de06ed4b54 8229979: jpackage cleanup src files, help text, and javadoc
herrick
parents: 57413
diff changeset
    41
     */
c7de06ed4b54 8229979: jpackage cleanup src files, help text, and javadoc
herrick
parents: 57413
diff changeset
    42
    std::wstring args() const;
c7de06ed4b54 8229979: jpackage cleanup src files, help text, and javadoc
herrick
parents: 57413
diff changeset
    43
c7de06ed4b54 8229979: jpackage cleanup src files, help text, and javadoc
herrick
parents: 57413
diff changeset
    44
    /**
c7de06ed4b54 8229979: jpackage cleanup src files, help text, and javadoc
herrick
parents: 57413
diff changeset
    45
     * Set path to application to execute.
c7de06ed4b54 8229979: jpackage cleanup src files, help text, and javadoc
herrick
parents: 57413
diff changeset
    46
     */
c7de06ed4b54 8229979: jpackage cleanup src files, help text, and javadoc
herrick
parents: 57413
diff changeset
    47
    Executor& app(const std::wstring& v) {
c7de06ed4b54 8229979: jpackage cleanup src files, help text, and javadoc
herrick
parents: 57413
diff changeset
    48
        appPath = v;
c7de06ed4b54 8229979: jpackage cleanup src files, help text, and javadoc
herrick
parents: 57413
diff changeset
    49
        return *this;
c7de06ed4b54 8229979: jpackage cleanup src files, help text, and javadoc
herrick
parents: 57413
diff changeset
    50
    }
c7de06ed4b54 8229979: jpackage cleanup src files, help text, and javadoc
herrick
parents: 57413
diff changeset
    51
c7de06ed4b54 8229979: jpackage cleanup src files, help text, and javadoc
herrick
parents: 57413
diff changeset
    52
    /**
c7de06ed4b54 8229979: jpackage cleanup src files, help text, and javadoc
herrick
parents: 57413
diff changeset
    53
     * Adds another command line argument.
c7de06ed4b54 8229979: jpackage cleanup src files, help text, and javadoc
herrick
parents: 57413
diff changeset
    54
     */
c7de06ed4b54 8229979: jpackage cleanup src files, help text, and javadoc
herrick
parents: 57413
diff changeset
    55
    Executor& arg(const std::wstring& v) {
c7de06ed4b54 8229979: jpackage cleanup src files, help text, and javadoc
herrick
parents: 57413
diff changeset
    56
        argsArray.push_back(v);
c7de06ed4b54 8229979: jpackage cleanup src files, help text, and javadoc
herrick
parents: 57413
diff changeset
    57
        return *this;
c7de06ed4b54 8229979: jpackage cleanup src files, help text, and javadoc
herrick
parents: 57413
diff changeset
    58
    }
c7de06ed4b54 8229979: jpackage cleanup src files, help text, and javadoc
herrick
parents: 57413
diff changeset
    59
c7de06ed4b54 8229979: jpackage cleanup src files, help text, and javadoc
herrick
parents: 57413
diff changeset
    60
    /**
c7de06ed4b54 8229979: jpackage cleanup src files, help text, and javadoc
herrick
parents: 57413
diff changeset
    61
     * Controls if application window should be visible.
c7de06ed4b54 8229979: jpackage cleanup src files, help text, and javadoc
herrick
parents: 57413
diff changeset
    62
     */
c7de06ed4b54 8229979: jpackage cleanup src files, help text, and javadoc
herrick
parents: 57413
diff changeset
    63
    Executor& visible(bool v) {
c7de06ed4b54 8229979: jpackage cleanup src files, help text, and javadoc
herrick
parents: 57413
diff changeset
    64
        theVisible = v;
c7de06ed4b54 8229979: jpackage cleanup src files, help text, and javadoc
herrick
parents: 57413
diff changeset
    65
        return *this;
c7de06ed4b54 8229979: jpackage cleanup src files, help text, and javadoc
herrick
parents: 57413
diff changeset
    66
    }
c7de06ed4b54 8229979: jpackage cleanup src files, help text, and javadoc
herrick
parents: 57413
diff changeset
    67
c7de06ed4b54 8229979: jpackage cleanup src files, help text, and javadoc
herrick
parents: 57413
diff changeset
    68
    /**
c7de06ed4b54 8229979: jpackage cleanup src files, help text, and javadoc
herrick
parents: 57413
diff changeset
    69
     * Starts application process and blocks waiting when the started
c7de06ed4b54 8229979: jpackage cleanup src files, help text, and javadoc
herrick
parents: 57413
diff changeset
    70
     * process terminates.
c7de06ed4b54 8229979: jpackage cleanup src files, help text, and javadoc
herrick
parents: 57413
diff changeset
    71
     * Returns process exit code.
c7de06ed4b54 8229979: jpackage cleanup src files, help text, and javadoc
herrick
parents: 57413
diff changeset
    72
     * Throws exception if process start failed.
c7de06ed4b54 8229979: jpackage cleanup src files, help text, and javadoc
herrick
parents: 57413
diff changeset
    73
     */
c7de06ed4b54 8229979: jpackage cleanup src files, help text, and javadoc
herrick
parents: 57413
diff changeset
    74
    int execAndWaitForExit() const;
c7de06ed4b54 8229979: jpackage cleanup src files, help text, and javadoc
herrick
parents: 57413
diff changeset
    75
c7de06ed4b54 8229979: jpackage cleanup src files, help text, and javadoc
herrick
parents: 57413
diff changeset
    76
private:
c7de06ed4b54 8229979: jpackage cleanup src files, help text, and javadoc
herrick
parents: 57413
diff changeset
    77
    UniqueHandle startProcess() const;
c7de06ed4b54 8229979: jpackage cleanup src files, help text, and javadoc
herrick
parents: 57413
diff changeset
    78
c7de06ed4b54 8229979: jpackage cleanup src files, help text, and javadoc
herrick
parents: 57413
diff changeset
    79
    bool theVisible;
c7de06ed4b54 8229979: jpackage cleanup src files, help text, and javadoc
herrick
parents: 57413
diff changeset
    80
    tstring_array argsArray;
c7de06ed4b54 8229979: jpackage cleanup src files, help text, and javadoc
herrick
parents: 57413
diff changeset
    81
    std::wstring appPath;
c7de06ed4b54 8229979: jpackage cleanup src files, help text, and javadoc
herrick
parents: 57413
diff changeset
    82
};
c7de06ed4b54 8229979: jpackage cleanup src files, help text, and javadoc
herrick
parents: 57413
diff changeset
    83
c7de06ed4b54 8229979: jpackage cleanup src files, help text, and javadoc
herrick
parents: 57413
diff changeset
    84
#endif // #ifndef EXECUTOR_H