int restore_erase(string *args, struct shell_state *sh)
{
	mach_error_t retval;
	
	if( args[1] == "" || args[2] == "")
	{
		ifNotQuiet cout << "mount: please provide both arguments." << endl;
		set_rfr(1);
		return SHELL_CONTINUE;
	}
	
	D("allocating CFMutableDictionary");
	CFMutableDictionaryRef req = CFDictionaryCreateMutable(	kCFAllocatorDefault, 0,
								&kCFTypeDictionaryKeyCallBacks,
								&kCFTypeDictionaryValueCallBacks);
	
	D("setting values");
	CFDictionarySetValue(req, CFSTR("Operation"), CFSTR("Erase"));
	CFDictionarySetValue(req, CFSTR("DeviceName"),
		CFStringCreateWithCString(NULL, args[1].c_str(), kCFStringEncodingASCII) );
	CFDictionarySetValue(req, CFSTR("VolumeName"),
		CFStringCreateWithCString(NULL, args[2].c_str(), kCFStringEncodingASCII) );
	
	D("sending dictionary");
	retval = performOperation(sh->restore_dev, req);
	
	ifVerbose cout	<< "erase: erasing device '" << args[1] << "' at volume '" << args[2] << "': " << retval << endl;
	
	// set return function retval so we can break a script if this doesn't work for some reason
	set_rfr(retval);
		
	return SHELL_CONTINUE;
}
int restore_filesystemcheck(string *args, struct shell_state *sh)
{
	mach_error_t retval;
	
	if( args[1] == "" )
	{
		ifNotQuiet cout << "filesystemcheck: please provide a path to a disk to check." << endl;
		set_rfr(1);
		return SHELL_CONTINUE;
	}
	
	D("allocating CFMutableDictionary");
	CFMutableDictionaryRef req = CFDictionaryCreateMutable(	kCFAllocatorDefault, 0,
								&kCFTypeDictionaryKeyCallBacks,
								&kCFTypeDictionaryValueCallBacks);
	
	D("setting values");
	CFDictionarySetValue(req, CFSTR("Operation"), CFSTR("FilesystemCheck"));
	CFDictionarySetValue(req, CFSTR("DeviceName"),
		CFStringCreateWithCString(NULL, args[1].c_str(), kCFStringEncodingASCII) );
	
	D("sending dictionary");
	retval = performOperation(sh->restore_dev, req);
	
	ifVerbose cout	<< "FileSystemCheck: checking device '" << args[1] << "': " << retval << endl;
	
	//Here we should check for 'unknown device' error code to assume that anything else means
	//that fsck could not repair the disk, which we should alert the user to.
	
	// set return function retval so we can break a script if this doesn't work for some reason
	set_rfr(retval);
	
	return SHELL_CONTINUE;
}
CalculatorWidget::CalculatorWidget(WContainerWidget* parent) : WContainerWidget(parent), mOperation("+"), mLHS(0), mRHS(0), mResult(0)
{
    mDisplay = new CalculatorDisplay(this);
    addWidget(mDisplay);

    initNumberButtons();
    
    mDecimal = new WPushButton(".", this);
    mDecimal->clicked().connect(std::bind([&] () {
        mDisplay->push('.');
    }));

    addWidget(mDecimal);
    initOperationButtons();

    mEquals = new WPushButton("=", this);
    mEquals->clicked().connect(std::bind([&] () {
        double val = mDisplay->getValue();
        mDisplay->clear();
        setEquation(val);
        mDisplay->setText(std::to_string(performOperation()));
    }));

    addWidget(mEquals);

    mClear = new WPushButton("Clear", this);
    mClear->clicked().connect(std::bind([&] () {
        mLHS = mRHS = 0.0;
        mResult = 0;
        mDisplay->clear();
    }));

    addWidget(mClear);
}
void InFixToPostFixCalculator::solveExpression()
{
	float operand1 = 0;
	float operand2 = 0;
	float answer = 0;
	string element = "";
	float operandElement = 0;
	for (unsigned int index = 0; index < postFixExpression.size(); index++)
	{
		string element = postFixExpression[index];
		if (getPriority(element[0]) == 0)
		{
			operandElement = atof(element.c_str());
			streamStack.push(operandElement);
		}
		else if (getPriority(element[0]) > 0)
		{
			operand2 = streamStack.pop();
			operand1 = streamStack.pop();
			answer = performOperation(operand1, operand2, element[0]);
			streamStack.push(answer);
		}
	}
	expressionAnswer = streamStack.pop();
}
int restore_mount(string *args, struct shell_state *sh)
{
	mach_error_t retval;
	
	if( args[1] == "" || args[2] == "")
	{
		ifNotQuiet cout << "mount: please provide both arguments." << endl;
		set_rfr(1);
		return SHELL_CONTINUE;
	}
	
	D("allocating CFMutableDictionary");
	CFMutableDictionaryRef req = CFDictionaryCreateMutable(	kCFAllocatorDefault, 0,
								&kCFTypeDictionaryKeyCallBacks,
								&kCFTypeDictionaryValueCallBacks);
	
	D("setting values");
	CFDictionarySetValue(req, CFSTR("Operation"), CFSTR("Mount"));
	CFDictionarySetValue(req, CFSTR("DeviceName"),
		CFStringCreateWithCString(NULL, args[1].c_str(), kCFStringEncodingASCII));
	CFDictionarySetValue(req, CFSTR("MountPoint"),
		CFStringCreateWithCString(NULL, args[2].c_str(), kCFStringEncodingASCII));
	
	D("sending dictionary");
	retval = performOperation(sh->restore_dev, req);
	
	ifVerbose cout	<< "mount: mounting '" << args[1] << "' at '" << args[2] << endl;
	
	// build a list of known error codes
	ifNotQuiet
	{
		switch (retval)
		{
			case 0:
				ifVerbose cout << "mount: Successful." << endl;
				break;
			case 6:
				cout << "mount: iPhone returned '6' - invalid argument." << endl;
				break;
			default:
				cout << "mount: iPhone returned '" << retval << "' - unknown error code." << endl;
				break;
		}
	}
	
	// set return function retval so we can break a script if this doesn't work for some reason
	set_rfr(retval);
	
	return SHELL_CONTINUE;
}
Beispiel #6
0
const Values *Column::evaluate(AST *ast, const Cursor *cur) const
{

	/* check input AST */
	if (ast == NULL) {
		return NULL;
	}

	/* evaluate AST */
	switch (ast->type) {
		case fbitdump::Column::AST::valueType:{
			Values *retVal = new Values;
			int part=0;
			const stringSet &tmpSet = this->getColumns(ast);

			for (stringSet::const_iterator it = tmpSet.begin(); it != tmpSet.end(); it++) {
				/* get value from table */
				if (!cur->getColumn(*it, *retVal, part)) {
					delete retVal;
					return NULL;
				}
				part++;
			}

			return retVal;
			break;}
		case fbitdump::Column::AST::operationType:{
			const Values *left, *right, *retVal = NULL;

			left = evaluate(ast->left, cur);
			right = evaluate(ast->right, cur);

			if (left != NULL && right != NULL) {
				retVal = performOperation(left, right, ast->operation);
			}
			/* clean up */
			delete left;
			delete right;

			return retVal;
			break;}
		default:
			std::cerr << "Unknown AST type" << std::endl;
			break;
	}

	return NULL;
}
int restore_force(string *args, struct shell_state *sh)
{
	mach_error_t retval;
	
	if( args[1] == "" )
	{
		ifNotQuiet cout << "force: please provide a command." << endl;
		set_rfr(1);
		return SHELL_CONTINUE;
	}
	
	D("allocating CFMutableDictionary");
	CFMutableDictionaryRef req = CFDictionaryCreateMutable(	kCFAllocatorDefault, 0,
								&kCFTypeDictionaryKeyCallBacks,
								&kCFTypeDictionaryValueCallBacks);
							
	D("setting values");
	CFDictionarySetValue(req, CFSTR("Operation"),
		CFStringCreateWithCString(NULL, args[1].c_str(), kCFStringEncodingASCII) );
	
	D("sending dictionary");
	retval = performOperation(sh->restore_dev, req);

	ifVerbose cout	<< "force: sending operation: '" << args[1] << "'" << endl;
	
	ifNotQuiet
	{
		switch(retval)
		{
			case 0:
				ifVerbose cout << "force: Successful." << endl;
				break;
			case 8:
				cout << "force: Unknown command." << endl;
				break;
			default:
				cout << "force: Unknown error code '" << retval << "'.  Please report." << endl;
				break;
		}
	}
	
	// set return function retval so we can break a script if this doesn't work for some reason
	set_rfr(retval);
	
	return SHELL_CONTINUE;
}
int updateParameter(Parameter* self) {
    if(self->src2  != NULL) 
    {        
        if((self->src2->time > self->src1->time) && (self->src2->time - self->src1->time > LCD_SOURCE_CHOICE_TIMEOUT)) {         
            self->value = self->src2->value; 
            self->time  = self->src2->time;            
        } else {
            self->value = self->src1->value; 
            self->time  = self->src1->time;
        }    
    } else {       
        self->value = self->src1->value; 
        self->time  = self->src1->time;  
    }
    
    performOperation(self);
    
    return ERR_NONE;
}
int restore_partition(string *args, struct shell_state *sh)
{
	mach_error_t retval;
	
	D("allocating CFMutableDictionary");
	CFMutableDictionaryRef req = CFDictionaryCreateMutable(	kCFAllocatorDefault, 0,
								&kCFTypeDictionaryKeyCallBacks,
								&kCFTypeDictionaryValueCallBacks);
	
	D("setting values");
	CFDictionarySetValue(req, CFSTR("Operation"), CFSTR("Partition"));
	
	D("sending dictionary");
	retval = performOperation(sh->restore_dev, req);
	
	ifVerbose cout	<< "partition: returned error code: "
			<< retval << endl;
	
	// set return function retval so we can break a script if this doesn't work for some reason
	set_rfr(retval);
	
	return SHELL_CONTINUE;
}
Beispiel #10
0
int main(int argc, char* argv[]){

	
	if (argc < minArgs){
		if (argc == 2 && isSpecialCommand(argv[1]))
		{
			repo_op_t op;
			op.command = argv[1];
			op.nArgcs = 0;

			repo::RepoController *controller = instantiateController();

			int32_t errcode = performOperation(controller, nullptr, op);
			
			delete controller;
			return errcode;
		}

		printHelp();
		return REPOERR_INVALID_ARG;
	}

	std::string address = argv[1];
	int port = atoi(argv[2]);
	std::string username = argv[3];
	std::string password = argv[4];

	repo_op_t op;
	op.command = argv[5];
	if (argc > minArgs)
		op.args = &argv[minArgs];
	op.nArgcs = argc - minArgs;

	//Check before connecting to the database
	int32_t cmdnArgs = knownValid(op.command);
	if (cmdnArgs <= op.nArgcs)
	{

		repo::RepoController *controller = instantiateController();

		std::string errMsg;
		repo::RepoToken* token = controller->authenticateToAdminDatabaseMongo(errMsg, address, port, username, password);
		if (token)
		{
			repoLog("successfully connected to the database!");
			int32_t errcode = performOperation(controller, token, op);

			delete controller;
			delete token;
			return errcode;
		}
		else{
			repoLogError("Failed to authenticate to the database: " + errMsg);
			return REPOERR_AUTH_FAILED;
		}
			

		
	}
	else
	{
		std::cout << "Not enough arguments for command: " << op.command << std::endl;
		printHelp();
		return REPOERR_INVALID_ARG;
	}


	std::cout << "Unknown command: " << op.command << std::endl;
	printHelp();
	return REPOERR_UNKNOWN_CMD;
	
}