示例#1
0
文件: main.cpp 项目: AliSayed/MoSync
int main(int argc, char** argv) {
	if(argc < 3 || argc > 5) {
		const char* exename = FileNameFromPath(argv[0]);
		printf(
			"Usage: %s <file> <address> [port] [maxPacketSize]\n"
			"\n"
			"Sends <file> to Bluetooth <address>:[port] using OBEX PUT\n"
			"with a maximum packet size decided by the target device,\n"
			"optionally limited by [maxPacketSize].\n"
			"\n"
			"If [port] is not specified, Service Search is used to find it.\n"
			"\n"
			"Example: %s MoSync.jar 010203040506 9\n",
			exename, exename);
		DEBUG_GETCH;
		return -__COUNTER__;
	}

	MABtAddr address;
	str2ba(argv[2], &address);

	int port = -1;
	if(argc > 3) {
		port = atoi(argv[3]);
		if(port < 1 || port > 30) {
			printf("Bad port number: %i\n", port);
			return -__COUNTER__;
		}
	}

	int maxPacketSize = 0xffff;
	if(argc > 4) {
		maxPacketSize = atoi(argv[4]);
		if(maxPacketSize < 1 || maxPacketSize > 0xffff) {
			printf("Bad maxPacketSize: %i\n", maxPacketSize);
			return -__COUNTER__;
		}
	}

	Bluetooth::MABtInit();
	int res = sendFile(argv[1], &address, port, maxPacketSize);
	Bluetooth::MABtClose();

	if(res != 1) {
		printf("Result: %i\n", res);
		return res;
	} else {
		printf("File sent successfully.\n");
		return 0;
	}
	DEBUG_GETCH;
}
示例#2
0
	void DuiMemeryLooker::_recordAlloc(void* ptr, size_t sz, const char* file, size_t ln, const char* func)
	{
		if (file && func)
		{
			LockHelper lock(m_pcs);
			{
				const char* msg = ("Double allocation with same address - this probably means you have a mismatched allocation / deallocation style.");
				DuiAssertX(mAllocations.find(ptr) == mAllocations.end(), msg);

				//if (file && func)
				mAllocations[ptr] = Alloc(sz, ln, FileNameFromPath(file).c_str(), func);
				//else
					//mAllocations[ptr] = Alloc(sz, ln);
				mTotalAllocations += sz;
				mAllocated += sz;
			}
		}
	}
示例#3
0
文件: maassert.c 项目: Felard/MoSync
void bfeHandler(int value, const char* filename, int line) {
	char buf[1024];
	sprintf(buf, "BFE %s:%i", FileNameFromPath(filename), line);
	maPanic(value, buf);
}
示例#4
0
	/**
	 * Event handler for capture events
	 * @param event the event struct.
	 */
	void PhoneGapCapture::customEvent(const MAEvent &event)
	{
		char pathBuffer[1024];
		char messageBuffer[1024];

		if (event.type == EVENT_TYPE_CAPTURE)
		{
			MACaptureEventData eventData = event.captureData;

			switch (eventData.type)
			{
				case MA_CAPTURE_EVENT_TYPE_VIDEO:
					// Videos are already stored, we need the filepath
					maCaptureGetVideoPath(
						eventData.handle,
						pathBuffer,
						sizeof(pathBuffer));
					sprintf(
						messageBuffer,
						"{\"message\":[{\"fullPath\":\"%s\",\"name\":\"%s\"}]}",
						pathBuffer,
						FileNameFromPath(pathBuffer));
					mMessageHandler->callSuccess(
						mCaptureCallBack,
						PHONEGAP_CALLBACK_STATUS_OK,
						messageBuffer,
						false);
					maCaptureDestroyData(eventData.handle);
					break;

				case MA_CAPTURE_EVENT_TYPE_IMAGE:
				{
					char deviceOS[64];
					String extension;
					char localPath[1024];

					maGetSystemProperty(
						"mosync.device.OS",
						deviceOS,
						sizeof(deviceOS));

					// File format is different on different platforms.
					// TODO: What about WP?
					if (strcmp(deviceOS, "iPhone OS") == 0)
					{
						extension = "png";
					}
					else if(strcmp(deviceOS, "Android") == 0)
					{
						extension = "jpg";
					}
					else
					{
						// TODO: What to use as default?
						extension = "image";
					}

					// Images need to be stored. We use maLocalTime to
					// get a unique number for the filename.
					maGetSystemProperty(
						"mosync.path.local",
						localPath,
						sizeof(localPath));
					sprintf(
						pathBuffer,
						"%simg%d.%s",
						localPath,
						maLocalTime(),
						extension.c_str());
					int result = maCaptureWriteImage(
						eventData.handle,
						pathBuffer,
						sizeof(pathBuffer));
					sprintf(
						messageBuffer,
						"{\"message\":[{\"fullPath\":\"%s\",\"name\":\"%s\"}]}",
						pathBuffer,
						FileNameFromPath(pathBuffer));

					if (result == MA_CAPTURE_RES_OK)
					{
						mMessageHandler->callSuccess(
							mCaptureCallBack,
							PHONEGAP_CALLBACK_STATUS_OK,
							messageBuffer,
							false);
					}
					else
					{
						mMessageHandler->callError(
							mCaptureCallBack,
							PHONEGAP_CALLBACK_STATUS_ERROR,
							"{\"code\":\"CAPTURE_INTERNAL_ERR\"}",
							false);
					}

					// Free capture data.
					maCaptureDestroyData(eventData.handle);

					break;
				}

				case MA_CAPTURE_EVENT_TYPE_CANCEL:
					mMessageHandler->callError(
						mCaptureCallBack,
						PHONEGAP_CALLBACK_STATUS_ERROR,
						"{\"code\":\"CAPTURE_NO_MEDIA_FILES\"}",
						false);
					break;
			} // switch
		}
	}