Ejemplo n.º 1
0
	/**
	 * Return a FileSystem object.
	 */
	void PhoneGapFile::actionRequestFileSystem(JSONMessage& message)
	{
		String callbackID = message.getParam("PhoneGapCallBackId");

		// We support only persistent storage.
		int type = message.getArgsFieldInt("type");
		if (LOCALFILESYSTEM_PERSISTENT != type)
		{
			callFileError(callbackID, FILEERROR_NO_MODIFICATION_ALLOWED_ERR);
			return;
		}

		// Size parameter must be zero.
		int size = message.getArgsFieldInt("size");
		if (0 != size)
		{
			callFileError(callbackID, FILEERROR_NO_MODIFICATION_ALLOWED_ERR);
			return;
		}

		// TODO: Replace hard-coded path with platform aware path handling.
		String rootEntry = emitDirectoryEntry("sdcard", "/sdcard");
		String fileSystemInfo = emitFileSystemInfo("persistent", rootEntry);
		callSuccess(
			callbackID,
			fileSystemInfo,
			"window.localFileSystem._castFS");
	}
Ejemplo n.º 2
0
	void PhoneGapFile::actionTruncate(JSONMessage& message)
	{
		String callbackID = message.getParam("PhoneGapCallBackId");

		String fullPath = message.getArgsField("fileName");

		int size = message.getArgsFieldInt("size");

		int result = FileTruncate(fullPath, size);
		if (result < 0)
		{
			callFileError(callbackID, FILEERROR_NOT_FOUND_ERR);
			return;
		}

		// Send back the result, the new length of the file.
		char lengthBuf[32];
		sprintf(lengthBuf, "%i", result);
		callSuccess(callbackID, lengthBuf);
	}
Ejemplo n.º 3
0
	void PhoneGapFile::actionWrite(JSONMessage& message)
	{
		String callbackID = message.getParam("PhoneGapCallBackId");

		String fullPath = message.getArgsField("fileName");
		String data = message.getArgsField("data");
		int position = message.getArgsFieldInt("position");

		int result = FileWrite(fullPath, data, position);
		if (result < 0)
		{
			callFileError(callbackID, FILEERROR_NO_MODIFICATION_ALLOWED_ERR);
			return;
		}

		// Send back the new file size.
		char sizeBuf[32];
		sprintf(sizeBuf, "%i", FileGetSize(fullPath));
		callSuccess(
			callbackID,
			sizeBuf);
	}
Ejemplo n.º 4
0
	/**
	 * Implementation of PhoneGap and other APIs exposed in JavaScript.
	 * This function is used to detect different messages and call the
	 * respective function in MoSync.
	 *
	 * @return true if message was handled, false if not.
	 */
	bool PhoneGapMessageHandler::handlePhoneGapMessage(JSONMessage& message)
	{
		// Send device information to PhoneGap
		if ((message.getParam("service") == "Device") &&
				(message.getParam("action") == "Get"))
		{
			sendDeviceProperties(message.getParam("PhoneGapCallBackId"));
		}
		// Process the vibration message
		else if ((message.getParam("service") == "Notification") &&
				(message.getParam("action") == "vibrate"))
		{
			int duration = message.getArgsFieldInt("duration");
			maVibrate(duration);
		}
		//Process the beep message
		else if ((message.getParam("service") == "Notification") &&
				(message.getParam("action") == "beep"))
		{
			int repeatCount = message.getParamInt("args");
			for (int i = 0; i < repeatCount; i++)
			{
				if (mBeepSound > 0)
				{
					maSoundPlay(mBeepSound, 0, maGetDataSize(mBeepSound));
				}
			}
		}
		else if ((message.getParam("service") == "Connection") &&
				(message.getParam("action") == "getConnectionInfo"))
		{
			sendConnectionType(message.getParam("PhoneGapCallBackId"));
		}
		else if ((message.getParam("service") == "Accelerometer")
			|| (message.getParam("service") == "GeoLocation")
			|| (message.getParam("service") == "Compass"))
		{
			mPhoneGapSensors.handleMessage(message);
		}
		else if (message.getParam("service") == "SensorManager")
		{
			mPhoneGapSensorManager.handleMessage(message);
		}
		else if (message.getParam("service") == "File")
		{
			mPhoneGapFile.handleMessage(message);
		}
		else if (message.getParam("service") == "PushNotification")
		{
			mPushNotificationManager.handleMessage(message);
		}
		else if (message.getParam("service") == "Capture")
		{
			mPhoneGapCapture.handleMessage(message);
		}
		else
		{
			// Message was not handled.
			return false;
		}

		// Message was handled.
		return true;
	}
Ejemplo n.º 5
0
	/**
	 * Implementation of PhoneGap and other APIs exposed in JavaScript.
	 * This function is used to detect different messages and call the
	 * respective function in MoSync.
	 *
	 * @return true if message was handled, false if not.
	 */
	bool PhoneGapMessageHandler::handlePhoneGapMessage(JSONMessage& message)
	{
		// MoSync servcies implemented on top of the PhoneGap protocol
		// for convenience. We can move this to its own message handler
		// at a later point.
		if ((message.getParam("service") == "mosync") &&
			(message.getParam("action") == "mosync.notification.messageBox"))
		{
			String titleText = message.getParam("title");
			String messageText = message.getParam("message");
			maMessageBox(titleText.c_str(), messageText.c_str());
		}
		// Send device information to PhoneGap
		else if ((message.getParam("service") == "Device") &&
				(message.getParam("action") == "getDeviceInfo"))
		{
			sendDeviceProperties(message.getParam("PhoneGapCallBackId"));
		}
		// Process the vibration message
		else if ((message.getParam("service") == "Notification") &&
				(message.getParam("action") == "vibrate"))
		{
			int duration = message.getArgsFieldInt(0);
			maVibrate(duration);
		}
		//Process the beep message
		else if ((message.getParam("service") == "Notification") &&
				(message.getParam("action") == "beep"))
		{
			int repeatCount = message.getArgsFieldInt(0);
			for (int i = 0; i < repeatCount; i++)
			{
				if (mBeepSound > 0)
				{
					maSoundPlay(mBeepSound, 0, maGetDataSize(mBeepSound));
				}
			}
		}
		else if ((message.getParam("service") == "NetworkStatus") &&
				(message.getParam("action") == "getConnectionInfo"))
		{
			sendConnectionType(message.getParam("PhoneGapCallBackId"));
		}
		else if ((message.getParam("service") == "Accelerometer")
			|| (message.getParam("service") == "GeoLocation")
			|| (message.getParam("service") == "Compass"))
		{
			mPhoneGapSensors->handleMessage(message);
		}
		else if (message.getParam("service") == "SensorManager")
		{
			mSensorManager->handleMessage(message);
		}
		else if (message.getParam("service") == "File")
		{
			mPhoneGapFile->handleFileMessage(message);
		}
		else if (message.getParam("service") == "FileTransfer")
		{
			mPhoneGapFile->handleFileTransferMessage(message);
		}
		else if (message.getParam("service") == "PushNotification")
		{
			mPushNotificationManager->handleMessage(message);
		}
		else if (message.getParam("service") == "Capture")
		{
			mPhoneGapCapture->handleMessage(message);
		}
//		else if (message.getParam("service") == "Camera")
//		{
//			mPhoneGapCamera->handleMessage(message);
//		}
		else
		{
			// Message was not handled.
			return false;
		}

		// Message was handled.
		return true;
	}
Ejemplo n.º 6
0
	/**
	 * Implementation of capture API:s exposed to JavaScript.
	 * @return true if message was handled, false if not.
	 */
	void PhoneGapCapture::handleMessage(JSONMessage& message)
	{
		if(message.getParam("action") == "captureVideo")
		{
			int duration = message.getArgsFieldInt("duration");
			if(duration > 0)
			{
				char durationString[16];
				maCaptureSetProperty(MA_CAPTURE_MAX_DURATION, itoa(duration,durationString,10));
			}

			mCaptureCallBack = message.getParam("PhoneGapCallBackId");

			int result = maCaptureAction(MA_CAPTURE_ACTION_RECORD_VIDEO);

			if(result == MA_CAPTURE_RES_CAMERA_NOT_AVAILABLE)
			{
				//Camera was busy by another app
				mMessageHandler->callError(
					mCaptureCallBack,
					PHONEGAP_CALLBACK_STATUS_ERROR,
					"{\"code\":\"CAPTURE_APPLICATION_BUSY\"}",
					false);
			}
			else if(result == MA_CAPTURE_RES_VIDEO_NOT_SUPPORTED)
			{
				//No camera
				mMessageHandler->callError(
					mCaptureCallBack,
					PHONEGAP_CALLBACK_STATUS_ERROR,
					"{\"code\":\"CAPTURE_NOT_SUPPORTED\"}",
					false);
			}
		}
		else if(message.getParam("action") == "captureImage")
		{
			mCaptureCallBack = message.getParam("PhoneGapCallBackId");

			int result = maCaptureAction(MA_CAPTURE_ACTION_TAKE_PICTURE);

			if(result == MA_CAPTURE_RES_CAMERA_NOT_AVAILABLE)
			{
				//Camera was busy by another app
				mMessageHandler->callError(
					mCaptureCallBack,
					PHONEGAP_CALLBACK_STATUS_ERROR,
					"{\"code\":\"CAPTURE_APPLICATION_BUSY\"}",
					false);
			}
			if(result == MA_CAPTURE_RES_PICTURE_NOT_SUPPORTED)
			{
				//No camera
				mMessageHandler->callError(
					mCaptureCallBack,
					PHONEGAP_CALLBACK_STATUS_ERROR,
					"{\"code\":\"CAPTURE_NOT_SUPPORTED\"}",
					false);
			}
		}
		else if(message.getParam("action") == "captureAudio")
		{
			//MoSync does not support audio capture
			mMessageHandler->callError(
				mCaptureCallBack,
				PHONEGAP_CALLBACK_STATUS_ERROR,
				"{\"code\":\"CAPTURE_NOT_SUPPORTED\"}",
				false);
		}
	}