Ejemplo n.º 1
0
/**
 * Used for Android only.
 * Stores the registration ID in a store for later use.
 * @param token The registration_ID.
 */
void MainScreen::storeRegistrationID(MAUtil::String* token)
{
	mToken = token;

	// Store doesn't exist.
	MAHandle myStore = maOpenStore("MyPushStore", MAS_CREATE_IF_NECESSARY);

	// Create store and write Registration ID
	MAHandle myData = maCreatePlaceholder();
	if(maCreateData(myData, token->length()) == RES_OK)
	{
		 maWriteData(myData, token->c_str(), 0, token->length());
		 // Write the data resource to the store.
		 int result = maWriteStore(myStore, myData);

		 if ( result < 0 )
		 {
			 printf("Cannot write to store the token!!");
		 }
		 maCloseStore(myStore, 0);
	}

	// Finally, send it over TCP to the server.
//	mConnection->sendData(token);
}
Ejemplo n.º 2
0
Controller::~Controller() {
  // remember the selected font scale and path
  char path[FILENAME_MAX + 1];
  getcwd(path, FILENAME_MAX);
  int pathLength = strlen(path) + 1;
  int dataLength = (sizeof(int) * 3) + pathLength;
  MAHandle data = maCreatePlaceholder();

  if (maCreateData(data, dataLength) == RES_OK) {
    int storeVersion = STORE_VERSION;
    int offset = 0;

    // write the version number
    maWriteData(data, &storeVersion, offset, sizeof(int));
    offset += sizeof(int);

    // write the fontScale
    maWriteData(data, &_fontScale, offset, sizeof(int));
    offset += sizeof(int);
    
    // write the current path
    maWriteData(data, &pathLength, offset, sizeof(int));
    maWriteData(data, path, offset + sizeof(int), pathLength);

    MAHandle store = maOpenStore(PACKAGE, MAS_CREATE_IF_NECESSARY);
    maWriteStore(store, data);
    maCloseStore(store, 0);
  }
  maDestroyPlaceholder(data);

  delete _output;
  delete [] _programSrc;
}
Ejemplo n.º 3
0
// save status to a store, so the loader can read it.
// if this store is not saved, the loader will assume something went
// catastrophically wrong with the test.
static void exit_status_save(int status, void* dummy) {
	printf("exit_status_save\n");
	// we don't check for errors here, because there can be no reasonable error handling at this stage.
	// better then, to let the runtime's panic system deal with it.
	MAHandle data = maCreatePlaceholder();
	maCreateData(data, sizeof(int));
	maWriteData(data, &status, 0, sizeof(int));
	MAHandle store = maOpenStore("exit_status", MAS_CREATE_IF_NECESSARY);
	maWriteStore(store, data);
	maCloseStore(store, 0);
}
Ejemplo n.º 4
0
	//TestCase
	virtual void start() {
		printf("Testing stores.\n");
		//open, cin
		MAHandle store = maOpenStore("test.store", MAS_CREATE_IF_NECESSARY);
		TI(store);

		//write
		TI(maWriteStore(store, CLIENT_DATA));

		//close
		maCloseStore(store, 0);

		//open
		store = maOpenStore("test.store", 0);
		TI(store);

		//read
		MAHandle data = maCreatePlaceholder();
		maReadStore(store, data);

		//compare
		char storeBuf[DATA_SIZE], clientBuf[DATA_SIZE];
		maReadData(data, storeBuf, 0, DATA_SIZE);
		maReadData(CLIENT_DATA, clientBuf, 0, DATA_SIZE);
		if(memcmp(storeBuf, clientBuf, DATA_SIZE) != 0) {
			assert(name, false);
			suite->runNextCase();
			return;
		}

		//close, delete
		maCloseStore(store, true);
		maDestroyObject(data);

		//open, should fail
		store = maOpenStore("test.store", 0);
		if(store >= 0) {
			maCloseStore(store, true);
			assert(name, false);
			suite->runNextCase();
			return;
		}

		printf("Store test succeded!\n");

		//succeed
		assert(name, true);
		suite->runNextCase();
	}