Beispiel #1
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();
	}
Beispiel #2
0
/**
 * Used for Android only.
 * Check if the store exists.
 * If it does not exist, call the registration method,
 * create the store for later writing to it after the
 * connection to the server is established.
 */
void MainScreen::checkStore() {
	MAHandle myStore = maOpenStore("MyPushStore", 0);

	if (myStore == STERR_NONEXISTENT)
	{
		mSendRegistrationNeeded = true;

		// Request registration ID.
		int registerCode = Notification::NotificationManager::getInstance()->registerPushNotification(
				Notification::PUSH_NOTIFICATION_TYPE_BADGE
						| Notification::PUSH_NOTIFICATION_TYPE_ALERT
						| Notification::PUSH_NOTIFICATION_TYPE_SOUND,
				C2DM_USER_ACCOUNT);
		if ( MA_NOTIFICATION_RES_UNSUPPORTED == registerCode )
			maPanic(0, "This device does not support push notifications");

		// Close store without deleting it.
		maCloseStore(myStore, 0);
	}
	else
	{
		mSendRegistrationNeeded = false;
		// Close store without deleting it.
		maCloseStore(myStore, 0);
	}
}
Beispiel #3
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);
}
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;
}
Beispiel #5
0
static BOOL storeExists(const char *filename) {
	char sfilename[1024];
	MAHandle store;
	filterStoreName(sfilename, 1024, filename);
	store = maOpenStore(sfilename, 0);
//	lprintfln("store: %d, '%s'", store, sfilename);
	if(store>0) maCloseStore(store, 0);
	//return store!=STERR_NONEXISTENT;
	return store>0;
}
bool Controller::construct() {
  MAExtent screenSize = maGetScrSize();
  _output = new AnsiWidget(this, EXTENT_X(screenSize), EXTENT_Y(screenSize));
  _output->construct();
  _initialFontSize = _output->getFontSize();

  _runMode = init_state;
  opt_ide = IDE_NONE;
  opt_graphics = true;
  opt_pref_bpp = 0;
  opt_nosave = true;
  opt_interactive = true;
  opt_verbose = false;
  opt_quiet = true;
  opt_command[0] = 0;
  opt_usevmt = 0;
  os_graphics = 1;

  // restore the selected font scale and path
  MAHandle data = maCreatePlaceholder();
  MAHandle store = maOpenStore(PACKAGE, 0);

  if (store != STERR_NONEXISTENT) {
    if (maReadStore(store, data) == RES_OK) {
      int offset = 0;
      int storeVersion;
      int pathLength;
      char path[FILENAME_MAX + 1];
      
      maReadData(data, &storeVersion, offset, sizeof(int));
      offset += sizeof(int);

      if (storeVersion == STORE_VERSION) {
        maReadData(data, &_fontScale, offset, sizeof(int));
        offset += sizeof(int);        

        if (_fontScale != 100) {
          int fontSize = (_initialFontSize * _fontScale / 100);
          _output->setFontSize(fontSize);
        }
        
        maReadData(data, &pathLength, offset, sizeof(int));
        maReadData(data, &path, offset+ sizeof(int), pathLength);
        if (pathLength > 1) {
          chdir(path);
        }
      }
    }
    maCloseStore(store, 0);
  }
  maDestroyPlaceholder(data);

  return true;
}
Beispiel #7
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);
}
Beispiel #8
0
static MA_FILE* openReadWrite(const char *filename, int modeFlags) {
	MA_FILE *file;
	char sfilename[1024];
	MAHandle store;
	MAHandle data=0;
	int size = BUFFER_SIZE;
	int realLength = 0;

	filterStoreName(sfilename, 1024, filename);
	store = maOpenStore(sfilename, MAS_CREATE_IF_NECESSARY);
	if(!store) return NULL;

	file = (MA_FILE*) malloc(sizeof(MA_FILE));
	if(modeFlags&(MODE_READ|MODE_WRITE)) 
		file->type = TYPE_READWRITE;
	else 
		file->type = TYPE_WRITEONLY;
	file->modeFlags = modeFlags;
	
	if(modeFlags&(MODE_READ|MODE_APPEND)) {
		data = maCreatePlaceholder();
		maReadStore(store, data);
		realLength = size = maGetDataSize(data);
	}

	file->buffer = (unsigned char*) malloc(size);
	if(!file->buffer) {
		free(file->buffer);
		free(file);
		return NULL;
	}

	file->bufferStart = 0;
	file->bufferSize = size;
	file->volEntry = (VolumeEntry*) malloc(sizeof(VolumeEntry));
	file->filePtr = 0;
	file->volEntry->dataOffset = 0;
	file->volEntry->dataLength = realLength;
	file->resultFlags = 0;

	if(modeFlags&(MODE_READ|MODE_APPEND)) {
		maReadData(data, file->buffer, 0, size);
		maDestroyObject(data);
		if(modeFlags&MODE_APPEND) {
			file->filePtr = size;
		}
	}

	file->store = store;
	file->volEntry->type=VOL_TYPE_FILE;

	return file;
}
void ImageCache::process(bool afterFin)
{
	//Check to see if the cache can process this request at this time
	if(mIsBusy) return;
	//Check to see if there are any outstanding requests
	if(mRequests.size() == 0)
	return;
	//Set the mIsBusy flag, so we don't try to do too much at once
	mIsBusy = true;
	//Get the next image request from the queue

    mNextRequest = mRequests[0];
    if(mHttp.isOpen()){
    	mHttp.close();
    }

    if (mNextRequest->getType() == 5) {
		MAHandle store = maOpenStore((FILE_PREFIX+mNextRequest->getSaveName()).c_str(), 0);
		if(store != STERR_NONEXISTENT) {
			MAHandle cacheimage = maCreatePlaceholder();
			maReadStore(store, cacheimage);
			maCloseStore(store, 0);

			if (maGetDataSize(cacheimage) > 0) {
				Util::returnImage(mNextRequest->getImage(), cacheimage, 64);
			}
			maDestroyObject(cacheimage);
			cacheimage = -1;
		}
		store = -1;
		finishedDownloading();
    } else {
		mHttp = HttpConnection(this);
		int res = mHttp.create(mNextRequest->getUrl().c_str(), HTTP_GET);
		if(res < 0) {
			finishedDownloading();
		} else {
			mHttp.finish();
		}
    }
}