Bundle.h revision 54b6cfa9a9e5b861a9930af873580d6dc20f773c
1//
2// Copyright 2006 The Android Open Source Project
3//
4// State bundle.  Used to pass around stuff like command-line args.
5//
6#ifndef __BUNDLE_H
7#define __BUNDLE_H
8
9#include <stdlib.h>
10#include <utils.h>      // android
11#include <utils/String8.h>
12#include <utils/Vector.h>
13
14/*
15 * Things we can do.
16 */
17typedef enum Command {
18    kCommandUnknown = 0,
19    kCommandVersion,
20    kCommandList,
21    kCommandDump,
22    kCommandAdd,
23    kCommandRemove,
24    kCommandPackage,
25} Command;
26
27/*
28 * Bundle of goodies, including everything specified on the command line.
29 */
30class Bundle {
31public:
32    Bundle(void)
33        : mCmd(kCommandUnknown), mVerbose(false), mAndroidList(false),
34          mForce(false), mMakePackageDirs(false),
35          mUpdate(false), mExtending(false),
36          mRequireLocalization(false), mPseudolocalize(false),
37          mCompressionMethod(0), mOutputAPKFile(NULL),
38          mAssetSourceDir(NULL), mResourceSourceDir(NULL),
39          mAndroidManifestFile(NULL), mPublicOutputFile(NULL),
40          mRClassDir(NULL), mResourceIntermediatesDir(NULL),
41          mArgc(0), mArgv(NULL)
42        {}
43    ~Bundle(void) {}
44
45    /*
46     * Set the command value.  Returns "false" if it was previously set.
47     */
48    Command getCommand(void) const { return mCmd; }
49    void setCommand(Command cmd) { mCmd = cmd; }
50
51    /*
52     * Command modifiers.  Not all modifiers are appropriate for all
53     * commands.
54     */
55    bool getVerbose(void) const { return mVerbose; }
56    void setVerbose(bool val) { mVerbose = val; }
57    bool getAndroidList(void) const { return mAndroidList; }
58    void setAndroidList(bool val) { mAndroidList = val; }
59    bool getForce(void) const { return mForce; }
60    void setForce(bool val) { mForce = val; }
61    bool getMakePackageDirs(void) const { return mMakePackageDirs; }
62    void setMakePackageDirs(bool val) { mMakePackageDirs = val; }
63    bool getUpdate(void) const { return mUpdate; }
64    void setUpdate(bool val) { mUpdate = val; }
65    bool getExtending(void) const { return mExtending; }
66    void setExtending(bool val) { mExtending = val; }
67    bool getRequireLocalization(void) const { return mRequireLocalization; }
68    void setRequireLocalization(bool val) { mRequireLocalization = val; }
69    bool getPseudolocalize(void) const { return mPseudolocalize; }
70    void setPseudolocalize(bool val) { mPseudolocalize = val; }
71    int getCompressionMethod(void) const { return mCompressionMethod; }
72    void setCompressionMethod(int val) { mCompressionMethod = val; }
73    const char* getOutputAPKFile() const { return mOutputAPKFile; }
74    void setOutputAPKFile(const char* val) { mOutputAPKFile = val; }
75
76    /*
77     * Input options.
78     */
79    const char* getAssetSourceDir() const { return mAssetSourceDir; }
80    void setAssetSourceDir(const char* dir) { mAssetSourceDir = dir; }
81    const char* getResourceSourceDir() const { return mResourceSourceDir; }
82    void setResourceSourceDir(const char* dir) { mResourceSourceDir = dir; }
83    const char* getAndroidManifestFile() const { return mAndroidManifestFile; }
84    void setAndroidManifestFile(const char* file) { mAndroidManifestFile = file; }
85    const char* getPublicOutputFile() const { return mPublicOutputFile; }
86    void setPublicOutputFile(const char* file) { mPublicOutputFile = file; }
87    const char* getRClassDir() const { return mRClassDir; }
88    void setRClassDir(const char* dir) { mRClassDir = dir; }
89    const char* getConfigurations() const { return mConfigurations.size() > 0 ? mConfigurations.string() : NULL; }
90    void addConfigurations(const char* val) { if (mConfigurations.size() > 0) { mConfigurations.append(","); mConfigurations.append(val); } else { mConfigurations = val; } }
91    const char* getResourceIntermediatesDir() const { return mResourceIntermediatesDir; }
92    void setResourceIntermediatesDir(const char* dir) { mResourceIntermediatesDir = dir; }
93    const android::Vector<const char*>& getPackageIncludes() const { return mPackageIncludes; }
94    void addPackageInclude(const char* file) { mPackageIncludes.add(file); }
95    const android::Vector<const char*>& getJarFiles() const { return mJarFiles; }
96    void addJarFile(const char* file) { mJarFiles.add(file); }
97
98    /*
99     * Set and get the file specification.
100     *
101     * Note this does NOT make a copy of argv.
102     */
103    void setFileSpec(char* const argv[], int argc) {
104        mArgc = argc;
105        mArgv = argv;
106    }
107    int getFileSpecCount(void) const { return mArgc; }
108    const char* getFileSpecEntry(int idx) const { return mArgv[idx]; }
109    void eatArgs(int n) {
110        if (n > mArgc) n = mArgc;
111        mArgv += n;
112        mArgc -= n;
113    }
114
115#if 0
116    /*
117     * Package count.  Nothing to do with anything else here; this is
118     * just a convenient place to stuff it so we don't have to pass it
119     * around everywhere.
120     */
121    int getPackageCount(void) const { return mPackageCount; }
122    void setPackageCount(int val) { mPackageCount = val; }
123#endif
124
125private:
126    /* commands & modifiers */
127    Command     mCmd;
128    bool        mVerbose;
129    bool        mAndroidList;
130    bool        mForce;
131    bool        mMakePackageDirs;
132    bool        mUpdate;
133    bool        mExtending;
134    bool        mRequireLocalization;
135    bool        mPseudolocalize;
136    int         mCompressionMethod;
137    const char* mOutputAPKFile;
138    const char* mAssetSourceDir;
139    const char* mResourceSourceDir;
140    const char* mAndroidManifestFile;
141    const char* mPublicOutputFile;
142    const char* mRClassDir;
143    const char* mResourceIntermediatesDir;
144    android::String8 mConfigurations;
145    android::Vector<const char*> mPackageIncludes;
146    android::Vector<const char*> mJarFiles;
147
148    /* file specification */
149    int         mArgc;
150    char* const* mArgv;
151
152#if 0
153    /* misc stuff */
154    int         mPackageCount;
155#endif
156};
157
158#endif // __BUNDLE_H
159