int main(int argc, char* const argv[])
{
    if (!LOG_NDEBUG) {
      String8 argv_String;
      for (int i = 0; i < argc; ++i) {
        argv_String.append("\"");
        argv_String.append(argv[i]);
        argv_String.append("\" ");
      }
      ALOGV("app_process main with argv: %s", argv_String.string());
    }

    AppRuntime runtime(argv[0], computeArgBlockSize(argc, argv));
    // Process command line arguments
    // ignore argv[0]
    argc--;
    argv++;

    // Everything up to '--' or first non '-' arg goes to the vm.
    //
    // The first argument after the VM args is the "parent dir", which
    // is currently unused.
    //
    // After the parent dir, we expect one or more the following internal
    // arguments :
    //
    // --zygote : Start in zygote mode
    // --start-system-server : Start the system server.
    // --application : Start in application (stand alone, non zygote) mode.
    // --nice-name : The nice name for this process.
    //
    // For non zygote starts, these arguments will be followed by
    // the main class name. All remaining arguments are passed to
    // the main method of this class.
    //
    // For zygote starts, all remaining arguments are passed to the zygote.
    // main function.
    //
    // Note that we must copy argument string values since we will rewrite the
    // entire argument block when we apply the nice name to argv0.
    //
    // As an exception to the above rule, anything in "spaced commands"
    // goes to the vm even though it has a space in it.
    const char* spaced_commands[] = { "-cp", "-classpath" };
    // Allow "spaced commands" to be succeeded by exactly 1 argument (regardless of -s).
    bool known_command = false;

    int i;
    for (i = 0; i < argc; i++) {
        if (known_command == true) {
          runtime.addOption(strdup(argv[i]));
          // The static analyzer gets upset that we don't ever free the above
          // string. Since the allocation is from main, leaking it doesn't seem
          // problematic. NOLINTNEXTLINE
          ALOGV("app_process main add known option '%s'", argv[i]);
          known_command = false;
          continue;
        }

        for (int j = 0;
             j < static_cast<int>(sizeof(spaced_commands) / sizeof(spaced_commands[0]));
             ++j) {
          if (strcmp(argv[i], spaced_commands[j]) == 0) {
            known_command = true;
            ALOGV("app_process main found known command '%s'", argv[i]);
          }
        }

        if (argv[i][0] != '-') {
            break;
        }
        if (argv[i][1] == '-' && argv[i][2] == 0) {
            ++i; // Skip --.
            break;
        }

        runtime.addOption(strdup(argv[i]));
        // The static analyzer gets upset that we don't ever free the above
        // string. Since the allocation is from main, leaking it doesn't seem
        // problematic. NOLINTNEXTLINE
        ALOGV("app_process main add option '%s'", argv[i]);
    }

    // Parse runtime arguments.  Stop at first unrecognized option.
    bool zygote = false;
    bool startSystemServer = false;
    bool application = false;
    String8 niceName;
    String8 className;

    ++i;  // Skip unused "parent dir" argument.
    while (i < argc) {
        const char* arg = argv[i++];
        if (strcmp(arg, "--zygote") == 0) {
            zygote = true;
            niceName = ZYGOTE_NICE_NAME;
        } else if (strcmp(arg, "--start-system-server") == 0) {
            startSystemServer = true;
        } else if (strcmp(arg, "--application") == 0) {
            application = true;
        } else if (strncmp(arg, "--nice-name=", 12) == 0) {
            niceName.setTo(arg + 12);
        } else if (strncmp(arg, "--", 2) != 0) {
            className.setTo(arg);
            break;
        } else {
            --i;
            break;
        }
    }

    Vector<String8> args;
    if (!className.isEmpty()) {
        // We're not in zygote mode, the only argument we need to pass
        // to RuntimeInit is the application argument.
        //
        // The Remainder of args get passed to startup class main(). Make
        // copies of them before we overwrite them with the process name.
        args.add(application ? String8("application") : String8("tool"));
        runtime.setClassNameAndArgs(className, argc - i, argv + i);

        if (!LOG_NDEBUG) {
          String8 restOfArgs;
          char* const* argv_new = argv + i;
          int argc_new = argc - i;
          for (int k = 0; k < argc_new; ++k) {
            restOfArgs.append("\"");
            restOfArgs.append(argv_new[k]);
            restOfArgs.append("\" ");
          }
          ALOGV("Class name = %s, args = %s", className.string(), restOfArgs.string());
        }
    } else {
        // We're in zygote mode.
        maybeCreateDalvikCache();

        if (startSystemServer) {
            args.add(String8("start-system-server"));
        }

        char prop[PROP_VALUE_MAX];
        if (property_get(ABI_LIST_PROPERTY, prop, NULL) == 0) {
            LOG_ALWAYS_FATAL("app_process: Unable to determine ABI list from property %s.",
                ABI_LIST_PROPERTY);
            return 11;
        }

        String8 abiFlag("--abi-list=");
        abiFlag.append(prop);
        args.add(abiFlag);

        // In zygote mode, pass all remaining arguments to the zygote
        // main() method.
        for (; i < argc; ++i) {
            args.add(String8(argv[i]));
        }
    }

    if (!niceName.isEmpty()) {
        runtime.setArgv0(niceName.string(), true /* setProcName */);
    }

    if (zygote) {
        runtime.start("com.android.internal.os.ZygoteInit", args, zygote);
    } else if (className) {
        runtime.start("com.android.internal.os.RuntimeInit", args, zygote);
    } else {
        fprintf(stderr, "Error: no class name or --zygote supplied.\n");
        app_usage();
        LOG_ALWAYS_FATAL("app_process: no class name or --zygote supplied.");
    }
}
void fillVector(Vector<char> &vec, string str) {
	for (int i = 0; i < str.length(); i++) {
		vec.add(str[i]);
	}
}
int main(int argc, char* const argv[])
{
    if (prctl(PR_SET_NO_NEW_PRIVS, 1, 0, 0, 0) < 0) {
        // Older kernels don't understand PR_SET_NO_NEW_PRIVS and return
        // EINVAL. Don't die on such kernels.
        if (errno != EINVAL) {
            LOG_ALWAYS_FATAL("PR_SET_NO_NEW_PRIVS failed: %s", strerror(errno));
            return 12;
        }
    }

    AppRuntime runtime(argv[0], computeArgBlockSize(argc, argv));
    // Process command line arguments
    // ignore argv[0]
    argc--;
    argv++;

    // Everything up to '--' or first non '-' arg goes to the vm.
    //
    // The first argument after the VM args is the "parent dir", which
    // is currently unused.
    //
    // After the parent dir, we expect one or more the following internal
    // arguments :
    //
    // --zygote : Start in zygote mode
    // --start-system-server : Start the system server.
    // --application : Start in application (stand alone, non zygote) mode.
    // --nice-name : The nice name for this process.
    //
    // For non zygote starts, these arguments will be followed by
    // the main class name. All remaining arguments are passed to
    // the main method of this class.
    //
    // For zygote starts, all remaining arguments are passed to the zygote.
    // main function.
    //
    // Note that we must copy argument string values since we will rewrite the
    // entire argument block when we apply the nice name to argv0.

    int i;
    for (i = 0; i < argc; i++) {
        if (argv[i][0] != '-') {
            break;
        }
        if (argv[i][1] == '-' && argv[i][2] == 0) {
            ++i; // Skip --.
            break;
        }
        runtime.addOption(strdup(argv[i]));
    }

    // Parse runtime arguments.  Stop at first unrecognized option.
    bool zygote = false;
    bool startSystemServer = false;
    bool application = false;
    String8 niceName;
    String8 className;

    ++i;  // Skip unused "parent dir" argument.
    while (i < argc) {
        const char* arg = argv[i++];
        if (strcmp(arg, "--zygote") == 0) {
            zygote = true;
            niceName = ZYGOTE_NICE_NAME;
        } else if (strcmp(arg, "--start-system-server") == 0) {
            startSystemServer = true;
        } else if (strcmp(arg, "--application") == 0) {
            application = true;
        } else if (strncmp(arg, "--nice-name=", 12) == 0) {
            niceName.setTo(arg + 12);
        } else if (strncmp(arg, "--", 2) != 0) {
            className.setTo(arg);
            break;
        } else {
            --i;
            break;
        }
    }

    Vector<String8> args;
    if (!className.isEmpty()) {
        // We're not in zygote mode, the only argument we need to pass
        // to RuntimeInit is the application argument.
        //
        // The Remainder of args get passed to startup class main(). Make
        // copies of them before we overwrite them with the process name.
        args.add(application ? String8("application") : String8("tool"));
        runtime.setClassNameAndArgs(className, argc - i, argv + i);
    } else {
        // We're in zygote mode.
        maybeCreateDalvikCache();

        if (startSystemServer) {
            args.add(String8("start-system-server"));
        }

        char prop[PROP_VALUE_MAX];
        if (property_get(ABI_LIST_PROPERTY, prop, NULL) == 0) {
            LOG_ALWAYS_FATAL("app_process: Unable to determine ABI list from property %s.",
                ABI_LIST_PROPERTY);
            return 11;
        }

        String8 abiFlag("--abi-list=");
        abiFlag.append(prop);
        args.add(abiFlag);

        // In zygote mode, pass all remaining arguments to the zygote
        // main() method.
        for (; i < argc; ++i) {
            args.add(String8(argv[i]));
        }
    }

    if (!niceName.isEmpty()) {
        runtime.setArgv0(niceName.string());
        set_process_name(niceName.string());
    }

    if (zygote) {
        runtime.start("com.android.internal.os.ZygoteInit", args, zygote);
    } else if (className) {
        runtime.start("com.android.internal.os.RuntimeInit", args, zygote);
    } else {
        fprintf(stderr, "Error: no class name or --zygote supplied.\n");
        app_usage();
        LOG_ALWAYS_FATAL("app_process: no class name or --zygote supplied.");
        return 10;
    }
}
Example #4
0
	status_t CameraArea::parseAreas(const char *area,
			size_t areaLength,
			Vector< sp<CameraArea> > &areas)
	{
		status_t ret = NO_ERROR;
		char *ctx;
		char *pArea = NULL;
		char *pStart = NULL;
		char *pEnd = NULL;
		const char *startToken = "(";
		const char endToken = ')';
		const char sep = ',';
		ssize_t top, left, bottom, right, weight;
		char *tmpBuffer = NULL;
		sp<CameraArea> currentArea;

		LOG_FUNCTION_NAME

			if ( ( NULL == area ) ||
					( 0 >= areaLength ) )
			{
				return -EINVAL;
			}

		tmpBuffer = ( char * ) malloc(areaLength);
		if ( NULL == tmpBuffer )
		{
			return -ENOMEM;
		}

		memcpy(tmpBuffer, area, areaLength);

		pArea = strtok_r(tmpBuffer, startToken, &ctx);

		do
		{

			pStart = pArea;
			if ( NULL == pStart )
			{
				LOGINFO("Parsing of the left area coordinate failed!");
				ret = -EINVAL;
				break;
			}
			else
			{
				left = static_cast<ssize_t>(strtol(pStart, &pEnd, 10));
			}

			if ( sep != *pEnd )
			{
				LOGINFO("Parsing of the top area coordinate failed!");
				ret = -EINVAL;
				break;
			}
			else
			{
				top = static_cast<ssize_t>(strtol(pEnd+1, &pEnd, 10));
			}

			if ( sep != *pEnd )
			{
				LOGINFO("Parsing of the right area coordinate failed!");
				ret = -EINVAL;
				break;
			}
			else
			{
				right = static_cast<ssize_t>(strtol(pEnd+1, &pEnd, 10));
			}

			if ( sep != *pEnd )
			{
				LOGINFO("Parsing of the bottom area coordinate failed!");
				ret = -EINVAL;
				break;
			}
			else
			{
				bottom = static_cast<ssize_t>(strtol(pEnd+1, &pEnd, 10));
			}

			if ( sep != *pEnd )
			{
				LOGINFO("Parsing of the weight area coordinate failed!");
				ret = -EINVAL;
				break;
			}
			else
			{
				weight = static_cast<ssize_t>(strtol(pEnd+1, &pEnd, 10));
			}

			if ( endToken != *pEnd )
			{
				LOGINFO("Malformed area!");
				ret = -EINVAL;
				break;
			}

			ret = checkArea(top, left, bottom, right, weight);
			if ( NO_ERROR != ret ) {
				break;
			}

			currentArea = new CameraArea(top, left, bottom, right, weight);
			LOGINFO("Area parsed [%dx%d, %dx%d] %d",
					( int ) top,
					( int ) left,
					( int ) bottom,
					( int ) right,
					( int ) weight);
			if ( NULL != currentArea.get() )
			{
				areas.add(currentArea);
			}
			else
			{
				ret = -ENOMEM;
				break;
			}

			pArea = strtok_r(NULL, startToken, &ctx);

		}
		while ( NULL != pArea );

		if ( NULL != tmpBuffer )
		{
			free(tmpBuffer);
		}

		LOG_FUNCTION_NAME_EXIT

			return ret;
	}
Example #5
0
static void testTree()
{
	printf("Fill array with test data (%d items)...", TEST_ITEMS);
	Vector<int, TEST_ITEMS> *v = new Vector<int, TEST_ITEMS>();
	int n = 0;
	int i;
	for (i = 0; i < TEST_ITEMS; i++) {
		n = n * 45578 - 17651;
		// Fill it with quasi-random values in range 0...TEST_ITEMS-1
		v->add(((i+n) % TEST_ITEMS + TEST_ITEMS)/2);
	}
	printf(" DONE\n");
	MallocAllocator temp;

	start();
	BePlusTree<int, int, MallocAllocator, DefaultKeyValue<int>,
		DefaultComparator<int>, 30, 30> tree30(NULL);
	for (i = 0; i < TEST_ITEMS; i++)
		tree30.add((*v)[i]);
	for (i = 0; i < TEST_ITEMS; i++) {
		if (tree30.locate((*v)[i]))
			tree30.fastRemove();
	}
	report(30, 30);

	start();
	BePlusTree<int, int, MallocAllocator, DefaultKeyValue<int>,
		DefaultComparator<int>, 50, 50> tree50(NULL);
	for (i = 0; i < TEST_ITEMS; i++)
		tree50.add((*v)[i]);
	for (i = 0; i < TEST_ITEMS; i++) {
		if (tree50.locate((*v)[i]))
			tree50.fastRemove();
	}
	report(50, 50);

	start();
	BePlusTree<int, int, MallocAllocator, DefaultKeyValue<int>,
		DefaultComparator<int>, 75, 75> tree75(NULL);
	for (i = 0; i < TEST_ITEMS; i++)
		tree75.add((*v)[i]);
	for (i = 0; i < TEST_ITEMS; i++) {
		if (tree75.locate((*v)[i]))
			tree75.fastRemove();
	}
	report(75, 75);

	start();
	BePlusTree<int, int, MallocAllocator, DefaultKeyValue<int>,
		DefaultComparator<int>, 100, 100> tree100(NULL);
	for (i = 0; i < TEST_ITEMS; i++)
		tree100.add((*v)[i]);
	for (i = 0; i < TEST_ITEMS; i++) {
		if (tree100.locate((*v)[i]))
			tree100.fastRemove();
	}
	report(100, 100);

	start();
	BePlusTree<int, int, MallocAllocator, DefaultKeyValue<int>,
		DefaultComparator<int>, 100, 250> tree100_250(NULL);
	for (i = 0; i < TEST_ITEMS; i++)
		tree100_250.add((*v)[i]);
	for (i = 0; i < TEST_ITEMS; i++) {
		if (tree100_250.locate((*v)[i]))
			tree100_250.fastRemove();
	}
	report(100, 250);

	start();
	BePlusTree<int, int, MallocAllocator, DefaultKeyValue<int>,
		DefaultComparator<int>, 200, 200> tree200(NULL);
	for (i = 0; i < TEST_ITEMS; i++)
		tree200.add((*v)[i]);
	for (i = 0; i < TEST_ITEMS; i++) {
		if (tree200.locate((*v)[i]))
			tree200.fastRemove();
	}
	report(250, 250);

	std::set<int> stlTree;
	start();
	for (i = 0; i < TEST_ITEMS; i++)
		stlTree.insert((*v)[i]);
	for (i = 0; i < TEST_ITEMS; i++)
		stlTree.erase((*v)[i]);
	clock_t d = clock();
	printf("Just a reference: add+remove %d elements from STL tree took %d milliseconds. \n",
		TEST_ITEMS,	(int)(d-t)*1000/CLOCKS_PER_SEC);
}
void GrouperTest::expectHasGroupWithSplits(const char* a) {
    Vector<const char*> expected;
    expected.add(a);
    expectHasGroupWithSplits(expected);
}
void GrouperTest::addSplit(Vector<SplitDescription>& splits, const char* str) {
    splits.add();
    EXPECT_TRUE(SplitDescription::parse(String8(str), &splits.editTop()));
}
Example #8
0
void ImageDesignManager::updateCustomization(CreatureObject* imageDesigner, const String& customizationName, float value, CreatureObject* creo) {
	if (creo == NULL)
		return;

	if (value < 0 || value > 1)
		return;

	String speciesGender = getSpeciesGenderString(creo);

	ManagedReference<CreatureObject*> creatureObject = creo;

	CustomizationData* customData = getCustomizationData(speciesGender, customizationName);

	if (customData == NULL) {
		//System::out << "Unable to get CustomizationData for " + speciesGender + "_" + customizationName << endl;
		return;
	}

	String variables = customData->getVariables();
	String type = customData->getType();

	String skillMod = customData->getImageDesignSkillMod();

	if (imageDesigner->getSkillMod(skillMod) < customData->getSkillModValue())
		return;

	if (customData->getIsScale()) {
		float minScale = customData->getMinScale();
		float maxScale = customData->getMaxScale();

		float height = minScale + value * (maxScale - minScale);

		creatureObject->setHeight(MAX(MIN(height, maxScale), minScale));

		return;
	}

	Vector<String> fullVariables;
	StringTokenizer tokenizer(variables);
	tokenizer.setDelimeter(",");

	while (tokenizer.hasMoreTokens()) {
		String var;
		tokenizer.getStringToken(var);

		fullVariables.add(var);
	}

	String appearanceFilename = creo->getObjectTemplate()->getAppearanceFilename();

	VectorMap<String, Reference<CustomizationVariable*> > variableLimits;

	AssetCustomizationManagerTemplate::instance()->getCustomizationVariables(appearanceFilename.hashCode(), variableLimits, false);

	for (int i = 0; i < fullVariables.size(); ++i) {
		String var = fullVariables.get(i);

		for (int j = 0; j < variableLimits.size(); ++j) {
			String fullVariableNameLimit = variableLimits.elementAt(j).getKey();

			if (fullVariableNameLimit.contains(var)) {
				BasicRangedIntCustomizationVariable* ranged = dynamic_cast<BasicRangedIntCustomizationVariable*>(variableLimits.elementAt(j).getValue().get());

				if (ranged == NULL) {
					error("variable " + fullVariableNameLimit + " is not ranged");

					continue;
				}

				int min = ranged->getMinValueInclusive();
				int max = ranged->getMaxValueExclusive();

				int count = max - min;

				int setVal;

				float currentValue = value;

				if (fullVariables.size() > 1) {
					// examples for var count = 2
					// ex: received value 0 is for i == 0 -> 1.0, i == 1 -> 0.0
					// ex: received value 0.5 is for i == 0 -> 0.0, i == 1 -> 0.0
					// ex: received value 1 is for i == 0 -> 0.0, i == 1 -> 1.0

					// pre: i Û [0, 1] && value Û [0, 1]
					// post f Û [0, 1]
					currentValue = MAX(0, ((value - 0.5) * 2) * (-1 + (i * 2)));
				}

				if (customData->getReverse()) {
					setVal = float(max - 1) - currentValue * (float(count) - 1);
				} else {
					setVal = float(min) + currentValue * (float(count) - 1);
				}

				creatureObject->setCustomizationVariable(fullVariableNameLimit, setVal, true);

				//info("setting " + fullVariableNameLimit + " to " + String::valueOf(setVal), true);
			}
		}
	}

}