void ChatInput::SendChatDataToServer(ChatType type, const char* msg, const char* otherName) { NDTransData data(_MSG_TALK); Byte channel = GetChannelFromChatType(type); int time = (int)([[NSDate date] timeIntervalSince1970] / 1000); data << (Byte)0 << channel << time << (Byte)0 << (Byte)2; data.WriteUnicodeString(msg); data.WriteUnicodeString(otherName); SEND_DATA(data); // if (Task::BEGIN_FRESHMAN_TASK) { // Task* taskChat = NDPlayer::defaultHero().GetPlayerTask(Task::TASK_CHAT); // if (taskChat) { // sendTaskFinishMsg(Task::TASK_CHAT); // } // } }
int main(int argc, char* argv[]) { nsresult rv; { nsCOMPtr<nsIServiceManager> servMan; NS_InitXPCOM2(getter_AddRefs(servMan), nsnull, nsnull); nsCOMPtr<nsIComponentRegistrar> registrar = do_QueryInterface(servMan); NS_ASSERTION(registrar, "Null nsIComponentRegistrar"); if (registrar) registrar->AutoRegister(nsnull); nsCOMPtr<nsIThread> thread = do_GetCurrentThread(); nsCOMPtr<nsICategoryManager> catman = do_GetService(NS_CATEGORYMANAGER_CONTRACTID, &rv); if (NS_FAILED(rv)) return rv; nsCString previous; /////////////////////////////////////////// // BEGIN - Stream converter registration // All stream converters must register with the ComponentManager /////////////////////////////////////////// // these stream converters are just for testing. running this harness // from the dist/bin dir will also pickup converters registered // in other modules (necko converters for example). PRUint32 converterListSize = 7; const char *const converterList[] = { "?from=a/foo&to=b/foo", "?from=b/foo&to=c/foo", "?from=b/foo&to=d/foo", "?from=c/foo&to=d/foo", "?from=d/foo&to=e/foo", "?from=d/foo&to=f/foo", "?from=t/foo&to=k/foo", }; TestConverterFactory *convFactory = new TestConverterFactory(kTestConverterCID, "TestConverter", NS_ISTREAMCONVERTER_KEY); nsCOMPtr<nsIFactory> convFactSup(do_QueryInterface(convFactory, &rv)); if (NS_FAILED(rv)) return rv; for (PRUint32 count = 0; count < converterListSize; ++count) { // register the TestConverter with the component manager. One contractid registration // per conversion pair (from - to pair). nsCString contractID(NS_ISTREAMCONVERTER_KEY); contractID.Append(converterList[count]); rv = registrar->RegisterFactory(kTestConverterCID, "TestConverter", contractID.get(), convFactSup); if (NS_FAILED(rv)) return rv; rv = catman->AddCategoryEntry(NS_ISTREAMCONVERTER_KEY, converterList[count], "x", PR_TRUE, PR_TRUE, getter_Copies(previous)); if (NS_FAILED(rv)) return rv; } nsCOMPtr<nsIStreamConverterService> StreamConvService = do_GetService(kStreamConverterServiceCID, &rv); if (NS_FAILED(rv)) return rv; // Define the *from* content type and *to* content-type for conversion. static const char fromStr[] = "a/foo"; static const char toStr[] = "c/foo"; #ifdef ASYNC_TEST // ASYNCHRONOUS conversion // Build up a channel that represents the content we're // starting the transaction with. // // sample multipart mixed content-type string: // "multipart/x-mixed-replacE;boundary=thisrandomstring" #if 0 nsCOMPtr<nsIChannel> channel; nsCOMPtr<nsIURI> dummyURI; rv = NS_NewURI(getter_AddRefs(dummyURI), "http://meaningless"); if (NS_FAILED(rv)) return rv; rv = NS_NewInputStreamChannel(getter_AddRefs(channel), dummyURI, nsnull, // inStr "text/plain", // content-type -1); // XXX fix contentLength if (NS_FAILED(rv)) return rv; nsCOMPtr<nsIRequest> request(do_QueryInterface(channel)); #endif nsCOMPtr<nsIRequest> request; // setup a listener to receive the converted data. This guy is the end // listener in the chain, he wants the fully converted (toType) data. // An example of this listener in mozilla would be the DocLoader. nsIStreamListener *dataReceiver = new EndListener(); NS_ADDREF(dataReceiver); // setup a listener to push the data into. This listener sits inbetween the // unconverted data of fromType, and the final listener in the chain (in this case // the dataReceiver. nsIStreamListener *converterListener = nsnull; rv = StreamConvService->AsyncConvertData(fromStr, toStr, dataReceiver, nsnull, &converterListener); if (NS_FAILED(rv)) return rv; NS_RELEASE(dataReceiver); // at this point we have a stream listener to push data to, and the one // that will receive the converted data. Let's mimic On*() calls and get the conversion // going. Typically these On*() calls would be made inside their respective wrappers On*() // methods. rv = converterListener->OnStartRequest(request, nsnull); if (NS_FAILED(rv)) return rv; rv = SEND_DATA("aaa"); if (NS_FAILED(rv)) return rv; rv = SEND_DATA("aaa"); if (NS_FAILED(rv)) return rv; // Finish the request. rv = converterListener->OnStopRequest(request, nsnull, rv); if (NS_FAILED(rv)) return rv; NS_RELEASE(converterListener); #else // SYNCHRONOUS conversion nsCOMPtr<nsIInputStream> convertedData; rv = StreamConvService->Convert(inputData, fromStr, toStr, nsnull, getter_AddRefs(convertedData)); if (NS_FAILED(rv)) return rv; #endif // Enter the message pump to allow the URL load to proceed. while ( gKeepRunning ) { if (!NS_ProcessNextEvent(thread)) break; } } // this scopes the nsCOMPtrs // no nsCOMPtrs are allowed to be alive when you call NS_ShutdownXPCOM NS_ShutdownXPCOM(nsnull); return rv; }
int main(int argc, char* argv[]) { nsresult rv; { XRE_AddStaticComponent(&kTestModule); nsCOMPtr<nsIServiceManager> servMan; NS_InitXPCOM2(getter_AddRefs(servMan), nullptr, nullptr); nsCOMPtr<nsIThread> thread = do_GetCurrentThread(); nsCOMPtr<nsICategoryManager> catman = do_GetService(NS_CATEGORYMANAGER_CONTRACTID, &rv); if (NS_FAILED(rv)) return -1; nsCString previous; nsCOMPtr<nsIStreamConverterService> StreamConvService = do_GetService(kStreamConverterServiceCID, &rv); if (NS_FAILED(rv)) return -1; // Define the *from* content type and *to* content-type for conversion. static const char fromStr[] = "a/foo"; static const char toStr[] = "c/foo"; #ifdef ASYNC_TEST // ASYNCHRONOUS conversion // Build up a channel that represents the content we're // starting the transaction with. // // sample multipart mixed content-type string: // "multipart/x-mixed-replacE;boundary=thisrandomstring" #if 0 nsCOMPtr<nsIChannel> channel; nsCOMPtr<nsIURI> dummyURI; rv = NS_NewURI(getter_AddRefs(dummyURI), "http://meaningless"); if (NS_FAILED(rv)) return -1; rv = NS_NewInputStreamChannel(getter_AddRefs(channel), dummyURI, nullptr, // inStr "text/plain", // content-type -1); // XXX fix contentLength if (NS_FAILED(rv)) return -1; nsCOMPtr<nsIRequest> request(do_QueryInterface(channel)); #endif nsCOMPtr<nsIRequest> request; // setup a listener to receive the converted data. This guy is the end // listener in the chain, he wants the fully converted (toType) data. // An example of this listener in mozilla would be the DocLoader. nsIStreamListener *dataReceiver = new EndListener(); NS_ADDREF(dataReceiver); // setup a listener to push the data into. This listener sits inbetween the // unconverted data of fromType, and the final listener in the chain (in this case // the dataReceiver. nsIStreamListener *converterListener = nullptr; rv = StreamConvService->AsyncConvertData(fromStr, toStr, dataReceiver, nullptr, &converterListener); if (NS_FAILED(rv)) return -1; NS_RELEASE(dataReceiver); // at this point we have a stream listener to push data to, and the one // that will receive the converted data. Let's mimic On*() calls and get the conversion // going. Typically these On*() calls would be made inside their respective wrappers On*() // methods. rv = converterListener->OnStartRequest(request, nullptr); if (NS_FAILED(rv)) return -1; rv = SEND_DATA("aaa"); if (NS_FAILED(rv)) return -1; rv = SEND_DATA("aaa"); if (NS_FAILED(rv)) return -1; // Finish the request. rv = converterListener->OnStopRequest(request, nullptr, rv); if (NS_FAILED(rv)) return -1; NS_RELEASE(converterListener); #else // SYNCHRONOUS conversion nsCOMPtr<nsIInputStream> convertedData; rv = StreamConvService->Convert(inputData, fromStr, toStr, nullptr, getter_AddRefs(convertedData)); if (NS_FAILED(rv)) return -1; #endif // Enter the message pump to allow the URL load to proceed. while ( gKeepRunning ) { if (!NS_ProcessNextEvent(thread)) break; } } // this scopes the nsCOMPtrs // no nsCOMPtrs are allowed to be alive when you call NS_ShutdownXPCOM NS_ShutdownXPCOM(nullptr); return 0; }
void print_string(CHAR *fmt, ...) { va_list v_list; INT32S ret; if(print_output_type & PRINT_OUTPUT_USB) { #if _OPERATING_SYSTEM != _OS_NONE // Soft Protect for critical section OSSchedLock(); #endif /* redirect print_string to usb_logger_buf, write operation */ va_start(v_list, fmt); ret = vsnprintf(logger_write_ptr, USB_LOGGER_BUF_SIZE, fmt, v_list); if(ret < 0) { return; } //vsprintf(usb_logger_buf, fmt, v_list); va_end(v_list); /* Update write pointer */ if(logger_write_ptr < (usb_logger_buf + USB_LOGGER_BUF_TOTAL_SIZE - USB_LOGGER_BUF_SIZE )) logger_write_ptr += USB_LOGGER_BUF_SIZE; else logger_write_ptr = usb_logger_buf; /* Check if write ptr is equal to read ptr, if yes update read ptr */ if(logger_write_ptr == logger_read_ptr) { if(logger_read_ptr < (usb_logger_buf + USB_LOGGER_BUF_TOTAL_SIZE - USB_LOGGER_BUF_SIZE )) logger_read_ptr += USB_LOGGER_BUF_SIZE; else logger_read_ptr = usb_logger_buf; } //loggerwritecnt = (logger_write_ptr - usb_logger_buf) >> 9; //loggerreadcnt = (logger_read_ptr - usb_logger_buf) >> 9; #if _OPERATING_SYSTEM != _OS_NONE //exit critical section OSSchedUnlock(); #endif } if(print_output_type & PRINT_OUTPUT_UART) { CHAR *pt; va_start(v_list, fmt); ret = vsnprintf(print_buf, PRINT_BUF_SIZE, fmt, v_list); if(ret < 0) { return; } //vsprintf(print_buf, fmt, v_list); va_end(v_list); print_buf[PRINT_BUF_SIZE-1] = 0; pt = print_buf; while (*pt) { SEND_DATA(*pt); pt++; } } }