本文整理汇总了C++中require_noerr函数的典型用法代码示例。如果您正苦于以下问题:C++ require_noerr函数的具体用法?C++ require_noerr怎么用?C++ require_noerr使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了require_noerr函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: MICOStartBonjourService
OSStatus MICOStartBonjourService( WiFi_Interface interface, mico_Context_t * const inContext )
{
char *temp_txt= NULL;
char *temp_txt2;
OSStatus err;
net_para_st para;
bonjour_init_t init;
temp_txt = malloc(500);
require_action(temp_txt, exit, err = kNoMemoryErr);
memset(&init, 0x0, sizeof(bonjour_init_t));
micoWlanGetIPStatus(¶, Station);
init.service_name = BONJOUR_SERVICE;
/* name#xxxxxx.local. */
snprintf( temp_txt, 100, "%s#%c%c%c%c%c%c.local.", inContext->flashContentInRam.micoSystemConfig.name,
inContext->micoStatus.mac[9], inContext->micoStatus.mac[10], \
inContext->micoStatus.mac[12], inContext->micoStatus.mac[13], \
inContext->micoStatus.mac[15], inContext->micoStatus.mac[16] );
init.host_name = (char*)__strdup(temp_txt);
/* name#xxxxxx. */
snprintf( temp_txt, 100, "%s#%c%c%c%c%c%c", inContext->flashContentInRam.micoSystemConfig.name,
inContext->micoStatus.mac[9], inContext->micoStatus.mac[10], \
inContext->micoStatus.mac[12], inContext->micoStatus.mac[13], \
inContext->micoStatus.mac[15], inContext->micoStatus.mac[16] );
init.instance_name = (char*)__strdup(temp_txt);
init.service_port = inContext->flashContentInRam.appConfig.bonjourServicePort;
init.interface = interface;
temp_txt2 = __strdup_trans_dot(inContext->micoStatus.mac);
sprintf(temp_txt, "MAC=%s.", temp_txt2);
free(temp_txt2);
temp_txt2 = __strdup_trans_dot(FIRMWARE_REVISION);
sprintf(temp_txt, "%sFirmware Rev=%s.", temp_txt, temp_txt2);
free(temp_txt2);
temp_txt2 = __strdup_trans_dot(HARDWARE_REVISION);
sprintf(temp_txt, "%sHardware Rev=%s.", temp_txt, temp_txt2);
free(temp_txt2);
temp_txt2 = __strdup_trans_dot(MicoGetVer());
sprintf(temp_txt, "%sMICO OS Rev=%s.", temp_txt, temp_txt2);
free(temp_txt2);
temp_txt2 = __strdup_trans_dot(MODEL);
sprintf(temp_txt, "%sModel=%s.", temp_txt, temp_txt2);
free(temp_txt2);
temp_txt2 = __strdup_trans_dot(PROTOCOL);
sprintf(temp_txt, "%sProtocol=%s.", temp_txt, temp_txt2);
free(temp_txt2);
temp_txt2 = __strdup_trans_dot(MANUFACTURER);
sprintf(temp_txt, "%sManufacturer=%s.", temp_txt, temp_txt2);
free(temp_txt2);
sprintf(temp_txt, "%sSeed=%u.", temp_txt, inContext->flashContentInRam.micoSystemConfig.seed);
init.txt_record = (char*)__strdup(temp_txt);
bonjour_service_init(init);
free(init.host_name);
free(init.instance_name);
free(init.txt_record);
err = MICOAddNotification( mico_notify_WIFI_STATUS_CHANGED, (void *)BonjourNotify_WifiStatusHandler );
require_noerr( err, exit );
err = MICOAddNotification( mico_notify_SYS_WILL_POWER_OFF, (void *)BonjourNotify_SYSWillPoerOffHandler );
require_noerr( err, exit );
start_bonjour_service();
_bonjourStarted = true;
exit:
if(temp_txt) free(temp_txt);
return err;
}
示例2: init_platform_bootloader
void init_platform_bootloader( void )
{
CRC8_Context crc;
OSStatus err = kNoErr;
mico_logic_partition_t *rf_partition = MicoFlashGetInfo( MICO_PARTITION_RF_FIRMWARE );
MicoGpioInitialize( (mico_gpio_t)MICO_SYS_LED, OUTPUT_PUSH_PULL );
MicoGpioOutputLow( (mico_gpio_t)MICO_SYS_LED );
MicoGpioInitialize( (mico_gpio_t)MICO_RF_LED, OUTPUT_OPEN_DRAIN_NO_PULL );
MicoGpioOutputHigh( (mico_gpio_t)MICO_RF_LED );
MicoGpioInitialize((mico_gpio_t)BOOT_SEL, INPUT_PULL_UP);
MicoGpioInitialize((mico_gpio_t)MFG_SEL, INPUT_PULL_UP);
#ifdef USE_MiCOKit_EXT
dc_motor_init( );
dc_motor_set( 0 );
rgb_led_init();
rgb_led_open(0, 0, 0);
#endif
/* Specific operations used in EMW3165 production */
#define NEED_RF_DRIVER_COPY_BASE ((uint32_t)0x08008000)
#define TEMP_RF_DRIVER_BASE ((uint32_t)0x08040000)
#define TEMP_RF_DRIVER_END ((uint32_t)0x0807FFFF)
const uint8_t isDriverNeedCopy = *(uint8_t *)(NEED_RF_DRIVER_COPY_BASE);
const uint32_t totalLength = rf_partition->partition_length;
const uint8_t crcResult = *(uint8_t *)(TEMP_RF_DRIVER_END);
uint8_t targetCrcResult = 0;
uint32_t copyLength;
uint32_t destStartAddress_tmp = rf_partition->partition_start_addr;
uint32_t sourceStartAddress_tmp = TEMP_RF_DRIVER_BASE;
uint32_t i;
if ( isDriverNeedCopy != 0x0 )
return;
platform_log( "Bootloader start to copy RF driver..." );
/* Copy RF driver to SPI flash */
err = platform_flash_init( &platform_flash_peripherals[ MICO_FLASH_SPI ] );
require_noerr(err, exit);
err = platform_flash_init( &platform_flash_peripherals[ MICO_FLASH_EMBEDDED ] );
require_noerr(err, exit);
err = platform_flash_erase( &platform_flash_peripherals[ MICO_FLASH_SPI ],
rf_partition->partition_start_addr, rf_partition->partition_start_addr + rf_partition->partition_length - 1 );
require_noerr(err, exit);
platform_log( "Time: %d", mico_get_time_no_os() );
for(i = 0; i <= totalLength/SizePerRW; i++){
if( i == totalLength/SizePerRW ){
if(totalLength%SizePerRW)
copyLength = totalLength%SizePerRW;
else
break;
}else{
copyLength = SizePerRW;
}
printf(".");
err = platform_flash_read( &platform_flash_peripherals[ MICO_FLASH_EMBEDDED ], &sourceStartAddress_tmp, data , copyLength );
require_noerr( err, exit );
err = platform_flash_write( &platform_flash_peripherals[ MICO_FLASH_SPI ], &destStartAddress_tmp, data, copyLength );
require_noerr(err, exit);
}
printf("\r\n");
/* Check CRC-8 check-sum */
platform_log( "Bootloader start to verify RF driver..." );
sourceStartAddress_tmp = TEMP_RF_DRIVER_BASE;
destStartAddress_tmp = rf_partition->partition_start_addr;
CRC8_Init( &crc );
for(i = 0; i <= totalLength/SizePerRW; i++){
if( i == totalLength/SizePerRW ){
if(totalLength%SizePerRW)
copyLength = totalLength%SizePerRW;
else
break;
}else{
copyLength = SizePerRW;
}
printf(".");
err = platform_flash_read( &platform_flash_peripherals[ MICO_FLASH_SPI ], &destStartAddress_tmp, data, copyLength );
require_noerr( err, exit );
CRC8_Update( &crc, data, copyLength);
}
CRC8_Final( &crc, &targetCrcResult );
printf("\r\n");
//require_string( crcResult == targetCrcResult, exit, "Check-sum error" );
if( crcResult != targetCrcResult ){
platform_log("Check-sum error");
while(1);
}
/* Clear RF driver from temperary storage */
platform_log("Bootloader start to clear RF driver temporary storage...");
//.........这里部分代码省略.........
示例3: validateTSAResponseAndAddTimeStamp
static OSStatus validateTSAResponseAndAddTimeStamp(SecCmsSignerInfoRef signerinfo, CSSM_DATA_PTR tsaResponse,
uint64_t expectedNonce)
{
OSStatus status = SECFailure;
SecAsn1CoderRef coder = NULL;
SecAsn1TimeStampRespDER respDER = {{{0}},};
SecAsn1TSAPKIStatusInfo *tsastatus = NULL;
int respstatus = -1;
int failinfo = -1;
require_action(tsaResponse && tsaResponse->Data && tsaResponse->Length, xit, status = errSecTimestampMissing);
require_noerr(SecAsn1CoderCreate(&coder), xit);
require_noerr(SecTSAResponseCopyDEREncoding(coder, tsaResponse, &respDER), xit);
#ifndef NDEBUG
tsaWriteFileX("/tmp/tsa-timeStampToken.der", respDER.timeStampTokenDER.Data, respDER.timeStampTokenDER.Length);
#endif
tsastatus = (SecAsn1TSAPKIStatusInfo *)&respDER.status;
require_action(tsastatus->status.Data, xit, status = errSecTimestampBadDataFormat);
respstatus = (int)tsaDER_ToInt(&tsastatus->status);
#ifndef NDEBUG
char buf[80]={0,};
if (tsastatus->failInfo.Data) // e.g. FI_BadRequest
failinfo = (int)tsaDER_ToInt(&tsastatus->failInfo);
if (tsastatus->statusString.Data && tsastatus->statusString.Length)
{
OSStatus strrx = decodeDERUTF8String(&tsastatus->statusString, buf, sizeof(buf));
dprintf("decodeDERUTF8String status: %d\n", (int)strrx);
}
dprintf("validateTSAResponse: status: %d, failinfo: %d, %s\n", respstatus, failinfo, buf);
#endif
switch (respstatus)
{
case PKIS_Granted:
case PKIS_GrantedWithMods: // Success
status = noErr;
break;
case PKIS_Rejection:
status = errSecTimestampRejection;
break;
case PKIS_Waiting:
status = errSecTimestampWaiting;
break;
case PKIS_RevocationWarning:
status = errSecTimestampRevocationWarning;
break;
case PKIS_RevocationNotification:
status = errSecTimestampRevocationNotification;
break;
default:
status = errSecTimestampSystemFailure;
break;
}
require_noerr(status, xit);
// If we succeeded, then we must have a TimeStampToken
require_action(respDER.timeStampTokenDER.Data && respDER.timeStampTokenDER.Length, xit, status = errSecTimestampBadDataFormat);
dprintf("timestamp full expected nonce: %lld\n", expectedNonce);
/*
The bytes in respDER are a full CMS message, which we need to check now for validity.
The code for this is essentially the same code taht is done during a timestamp
verify, except that we also need to check the nonce.
*/
require_noerr(status = decodeTimeStampToken(signerinfo, &respDER.timeStampTokenDER, NULL, expectedNonce), xit);
status = SecCmsSignerInfoAddTimeStamp(signerinfo, &respDER.timeStampTokenDER);
xit:
if (coder)
SecAsn1CoderRelease(coder);
return status;
}
示例4: kxld_vtable_patch
//.........这里部分代码省略.........
* match it, then the child was built against a newer version of the
* libraries, so it is binary-incompatible.
*/
require_action(!kxld_sym_name_is_padslot(parent_entry->patched.name),
finish, rval=KERN_FAILURE;
kxld_log(kKxldLogPatching, kKxldLogErr,
kKxldLogParentOutOfDate,
kxld_demangle(super_vtable->name, &demangled_name1,
&demangled_length1),
kxld_demangle(vtable->name, &demangled_name2,
&demangled_length2)));
#if KXLD_USER_OR_STRICT_PATCHING
/* 5) If we are doing strict patching, we prevent kexts from declaring
* virtual functions and not implementing them. We can tell if a
* virtual function is declared but not implemented because we resolve
* symbols before patching; an unimplemented function will still be
* undefined at this point. We then look at whether the symbol has
* the same class prefix as the vtable. If it does, the symbol was
* declared as part of the class and not inherited, which means we
* should not patch it.
*/
if (kxld_object_target_supports_strict_patching(object) &&
!kxld_sym_is_defined(child_entry->unpatched.sym))
{
char class_name[KXLD_MAX_NAME_LEN];
char function_prefix[KXLD_MAX_NAME_LEN];
u_long function_prefix_len = 0;
rval = kxld_sym_get_class_name_from_vtable_name(vtable->name,
class_name, sizeof(class_name));
require_noerr(rval, finish);
function_prefix_len =
kxld_sym_get_function_prefix_from_class_name(class_name,
function_prefix, sizeof(function_prefix));
require(function_prefix_len, finish);
if (!strncmp(child_entry->unpatched.sym->name,
function_prefix, function_prefix_len))
{
failure = TRUE;
kxld_log(kKxldLogPatching, kKxldLogErr,
"The %s is unpatchable because its class declares the "
"method '%s' without providing an implementation.",
kxld_demangle(vtable->name,
&demangled_name1, &demangled_length1),
kxld_demangle(child_entry->unpatched.sym->name,
&demangled_name2, &demangled_length2));
continue;
}
}
#endif /* KXLD_USER_OR_STRICT_PATCHING */
/* 6) The child symbol is unresolved and different from its parent, so
* we need to patch it up. We do this by modifying the relocation
* entry of the vtable entry to point to the symbol of the parent
* vtable entry. If that symbol does not exist (i.e. we got the data
* from a link state object's vtable representation), then we create a
* new symbol in the symbol table and point the relocation entry to
* that.
*/
sym = kxld_symtab_get_locally_defined_symbol_by_name(symtab,
示例5: HTTPHeaderParse
OSStatus HTTPHeaderParse( HTTPHeader_t *ioHeader )
{
OSStatus err;
const char * src;
const char * end;
const char * ptr;
char c;
const char * value;
size_t valueSize;
int x;
require_action( ioHeader->len < sizeof( ioHeader->buf ), exit, err = kParamErr );
// Reset fields up-front to good defaults to simplify handling of unused fields later.
ioHeader->methodPtr = "";
ioHeader->methodLen = 0;
ioHeader->urlPtr = "";
ioHeader->urlLen = 0;
memset( &ioHeader->url, 0, sizeof( ioHeader->url ) );
ioHeader->protocolPtr = "";
ioHeader->protocolLen = 0;
ioHeader->statusCode = -1;
ioHeader->reasonPhrasePtr = "";
ioHeader->reasonPhraseLen = 0;
ioHeader->channelID = 0;
ioHeader->contentLength = 0;
ioHeader->persistent = false;
// Check for a 4-byte interleaved binary data header (see RFC 2326 section 10.12). It has the following format:
//
// '$' <1:channelID> <2:dataSize in network byte order> ... followed by dataSize bytes of binary data.
src = ioHeader->buf;
if( ( ioHeader->len == 4 ) && ( src[ 0 ] == '$' ) )
{
const uint8_t * usrc;
usrc = (const uint8_t *) src;
ioHeader->channelID = usrc[ 1 ];
ioHeader->contentLength = ( usrc[ 2 ] << 8 ) | usrc[ 3 ];
ioHeader->methodPtr = src;
ioHeader->methodLen = 1;
err = kNoErr;
goto exit;
}
// Parse the start line. This will also determine if it's a request or response.
// Requests are in the format <method> <url> <protocol>/<majorVersion>.<minorVersion>, for example:
//
// GET /abc/xyz.html HTTP/1.1
// GET http://www.host.com/abc/xyz.html HTTP/1.1
// GET http://user:[email protected]/abc/xyz.html HTTP/1.1
//
// Responses are in the format <protocol>/<majorVersion>.<minorVersion> <statusCode> <reasonPhrase>, for example:
//
// HTTP/1.1 404 Not Found
ptr = src;
end = src + ioHeader->len;
for( c = 0; ( ptr < end ) && ( ( c = *ptr ) != ' ' ) && ( c != '/' ); ++ptr ) {}
require_action( ptr < end, exit, err = kMalformedErr );
if( c == ' ' ) // Requests have a space after the method. Responses have '/' after the protocol.
{
ioHeader->methodPtr = src;
ioHeader->methodLen = (size_t)( ptr - src );
++ptr;
// Parse the URL.
ioHeader->urlPtr = ptr;
while( ( ptr < end ) && ( *ptr != ' ' ) ) ++ptr;
ioHeader->urlLen = (size_t)( ptr - ioHeader->urlPtr );
require_action( ptr < end, exit, err = kMalformedErr );
++ptr;
err = URLParseComponents( ioHeader->urlPtr, ioHeader->urlPtr + ioHeader->urlLen, &ioHeader->url, NULL );
require_noerr( err, exit );
// Parse the protocol and version.
ioHeader->protocolPtr = ptr;
while( ( ptr < end ) && ( ( c = *ptr ) != '\r' ) && ( c != '\n' ) ) ++ptr;
ioHeader->protocolLen = (size_t)( ptr - ioHeader->protocolPtr );
require_action( ptr < end, exit, err = kMalformedErr );
++ptr;
}
else // Response
{
// Parse the protocol version.
ioHeader->protocolPtr = src;
for( ++ptr; ( ptr < end ) && ( *ptr != ' ' ); ++ptr ) {}
ioHeader->protocolLen = (size_t)( ptr - ioHeader->protocolPtr );
require_action( ptr < end, exit, err = kMalformedErr );
++ptr;
// Parse the status code.
x = 0;
for( c = 0; ( ptr < end ) && ( ( c = *ptr ) >= '0' ) && ( c <= '9' ); ++ptr ) x = ( x * 10 ) + ( c - '0' );
ioHeader->statusCode = x;
if( c == ' ' ) ++ptr;
//.........这里部分代码省略.........
示例6: AssignOpaqueID
int AssignOpaqueID(void *inData, opaque_id *outID)
{
int error;
u_int32_t entryToUse;
require_action(outID != NULL, bad_parameter, error = EINVAL);
*outID = kInvalidOpaqueID;
error = pthread_mutex_lock(&gOpaqueEntryMutex);
require_noerr(error, pthread_mutex_lock);
/*
* If there aren't any items in the table, or if the number of free items is
* lower than we want, then grow the table.
*/
if ( (gIndexOfFreeOpaqueEntryHead == 0) || ((gOpaqueEntriesAllocated - gOpaqueEntriesUsed) < kOpaqueIDMinimumFree) )
{
u_int32_t newCount;
newCount = MIN(gOpaqueEntriesAllocated + 2048, kOpaqueIDMaximumCount);
if ( gOpaqueEntriesAllocated < newCount )
{
OpaqueEntryArrayPtr nuids;
nuids = (OpaqueEntryArrayPtr)realloc(gOpaqueEntryArray, sizeof(struct OpaqueEntry) * newCount);
if ( nuids != NULL )
{
u_int32_t i;
gOpaqueEntryArray = nuids;
/* Add all the 'new' OpaqueEntry to the free list. */
for ( i = 0; i < newCount - gOpaqueEntriesAllocated; ++i )
{
/* set both count and index to 0 */
gOpaqueEntryArray[gOpaqueEntriesAllocated + i].id = 0;
AddToFreeList(gOpaqueEntriesAllocated + i);
}
gOpaqueEntriesAllocated = newCount;
}
}
}
/* get index of an OpaqueEntry to use */
entryToUse = RemoveFromFreeList();
/* release the lock */
pthread_mutex_unlock(&gOpaqueEntryMutex);
/* did we get an OpaqueEntry? */
require_action((entryToUse != 0) && (entryToUse < gOpaqueEntriesAllocated), no_opaqueID, error = EINVAL);
/* the new id is created with the previous counter + 1, and the index */
gOpaqueEntryArray[entryToUse].id = CreateOpaqueID(GetOpaqueIDCounterPart(gOpaqueEntryArray[entryToUse].id) + 1, entryToUse);
gOpaqueEntryArray[entryToUse].data = inData;
*outID = gOpaqueEntryArray[entryToUse].id;
++gOpaqueEntriesUsed;
no_opaqueID:
pthread_mutex_lock:
bad_parameter:
return ( error );
}
示例7: init_by_entries
/*******************************************************************************
* Initializes a vtable object by reading the symbol values out of the vtable
* entries and performing reverse symbol lookups on those values.
*******************************************************************************/
static kern_return_t
init_by_entries(KXLDVTable *vtable, const KXLDRelocator *relocator,
const KXLDDict *defined_cxx_symbols)
{
kern_return_t rval = KERN_FAILURE;
KXLDVTableEntry *tmpentry = NULL;
KXLDSym *sym = NULL;
kxld_addr_t entry_value = 0;
u_long entry_offset;
u_int vtable_entry_size = 0;
u_int vtable_header_size = 0;
u_int nentries = 0;
u_int i = 0;
check(vtable);
check(relocator);
(void) get_vtable_base_sizes(relocator->is_32_bit,
&vtable_entry_size, &vtable_header_size);
/* Count the number of entries (the vtable is null-terminated) */
entry_offset = vtable_header_size;
while (1) {
entry_value = kxld_relocator_get_pointer_at_addr(relocator,
vtable->vtable, entry_offset);
if (!entry_value) break;
entry_offset += vtable_entry_size;
++nentries;
}
/* Allocate the symbol index */
rval = kxld_array_init(&vtable->entries, sizeof(KXLDVTableEntry), nentries);
require_noerr(rval, finish);
/* Look up the symbols for each entry */
for (i = 0, entry_offset = vtable_header_size;
i < vtable->entries.nitems;
++i, entry_offset += vtable_entry_size)
{
entry_value = kxld_relocator_get_pointer_at_addr(relocator,
vtable->vtable, entry_offset);
/* If we can't find the symbol, it means that the virtual function was
* defined inline. There's not much I can do about this; it just means
* I can't patch this function.
*/
tmpentry = kxld_array_get_item(&vtable->entries, i);
sym = kxld_dict_find(defined_cxx_symbols, &entry_value);
if (sym) {
tmpentry->patched.name = sym->name;
tmpentry->patched.addr = sym->link_addr;
} else {
tmpentry->patched.name = NULL;
tmpentry->patched.addr = 0;
}
}
rval = KERN_SUCCESS;
finish:
return rval;
}
示例8: easylink_thread
void easylink_thread(void *inContext)
{
OSStatus err = kNoErr;
mico_Context_t *Context = inContext;
fd_set readfds;
struct timeval_t t;
int reConnCount = 0;
easylink_log_trace();
require_action(Context->micoStatus.easylink_sem, threadexit, err = kParamErr);
if(Context->flashContentInRam.micoSystemConfig.easyLinkEnable != false){
OpenEasylink2_withdata(EasyLink_TimeOut);
easylink_log("Start easylink @ %d", mico_get_time());
mico_rtos_get_semaphore(&Context->micoStatus.easylink_sem, MICO_WAIT_FOREVER);
if(EasylinkFailed == false)
_easylinkConnectWiFi(Context);
else{
_easylinkStartSoftAp(Context);
mico_rtos_delete_thread(NULL);
return;
}
}else{
mico_rtos_lock_mutex(&Context->flashContentInRam_mutex);
Context->flashContentInRam.micoSystemConfig.easyLinkEnable = true;
MICOUpdateConfiguration(Context);
mico_rtos_unlock_mutex(&Context->flashContentInRam_mutex);
_easylinkConnectWiFi_fast(Context);
}
err = mico_rtos_get_semaphore(&Context->micoStatus.easylink_sem, ConnectFTC_Timeout);
require_noerr(err, reboot);
httpHeader = malloc( sizeof( HTTPHeader_t ) );
require_action( httpHeader, threadexit, err = kNoMemoryErr );
HTTPHeaderClear( httpHeader );
t.tv_sec = 100;
t.tv_usec = 0;
while(1){
if(Context->micoStatus.easylinkClient_fd == -1){
err = _connectFTCServer(inContext, &Context->micoStatus.easylinkClient_fd);
require_noerr(err, Reconn);
}else{
FD_ZERO(&readfds);
FD_SET(Context->micoStatus.easylinkClient_fd, &readfds);
err = select(1, &readfds, NULL, NULL, &t);
require(err > 0, Reconn);
if(FD_ISSET(Context->micoStatus.easylinkClient_fd, &readfds)){
err = SocketReadHTTPHeader( Context->micoStatus.easylinkClient_fd, httpHeader );
switch ( err )
{
case kNoErr:
// Read the rest of the HTTP body if necessary
err = SocketReadHTTPBody( Context->micoStatus.easylinkClient_fd, httpHeader );
require_noerr(err, Reconn);
PrintHTTPHeader(httpHeader);
// Call the HTTPServer owner back with the acquired HTTP header
err = _FTCRespondInComingMessage( Context->micoStatus.easylinkClient_fd, httpHeader, Context );
require_noerr( err, Reconn );
// Reuse HTTPHeader
HTTPHeaderClear( httpHeader );
break;
case EWOULDBLOCK:
// NO-OP, keep reading
break;
case kNoSpaceErr:
easylink_log("ERROR: Cannot fit HTTPHeader.");
goto Reconn;
break;
case kConnectionErr:
// NOTE: kConnectionErr from SocketReadHTTPHeader means it's closed
easylink_log("ERROR: Connection closed.");
goto threadexit;
//goto Reconn;
break;
default:
easylink_log("ERROR: HTTP Header parse internal error: %d", err);
goto Reconn;
}
}
}
continue;
Reconn:
HTTPHeaderClear( httpHeader );
close(Context->micoStatus.easylinkClient_fd);
Context->micoStatus.easylinkClient_fd = -1;
require(reConnCount < 6, threadexit);
reConnCount++;
sleep(5);
//.........这里部分代码省略.........
示例9: require_action
STDMETHODIMP ExplorerBar::GetBandInfo( DWORD inBandID, DWORD inViewMode, DESKBANDINFO *outInfo )
{
HRESULT err;
require_action( outInfo, exit, err = E_INVALIDARG );
mBandID = inBandID;
mViewMode = inViewMode;
if( outInfo->dwMask & DBIM_MINSIZE )
{
outInfo->ptMinSize.x = 100;
outInfo->ptMinSize.y = 100;
}
if( outInfo->dwMask & DBIM_MAXSIZE )
{
// Unlimited max size.
outInfo->ptMaxSize.x = -1;
outInfo->ptMaxSize.y = -1;
}
if( outInfo->dwMask & DBIM_INTEGRAL )
{
outInfo->ptIntegral.x = 1;
outInfo->ptIntegral.y = 1;
}
if( outInfo->dwMask & DBIM_ACTUAL )
{
outInfo->ptActual.x = 0;
outInfo->ptActual.y = 0;
}
if( outInfo->dwMask & DBIM_TITLE )
{
CString s;
BOOL ok;
ok = s.LoadString( IDS_NAME );
require_action( ok, exit, err = kNoResourcesErr );
#ifdef UNICODE
lstrcpyn( outInfo->wszTitle, s, sizeof_array( outInfo->wszTitle ) );
#else
DWORD nChars;
nChars = MultiByteToWideChar( CP_ACP, 0, s, -1, outInfo->wszTitle, sizeof_array( outInfo->wszTitle ) );
err = translate_errno( nChars > 0, (OSStatus) GetLastError(), kUnknownErr );
require_noerr( err, exit );
#endif
}
if( outInfo->dwMask & DBIM_MODEFLAGS )
{
outInfo->dwModeFlags = DBIMF_NORMAL | DBIMF_VARIABLEHEIGHT;
}
// Force the default background color.
outInfo->dwMask &= ~DBIM_BKCOLOR;
err = S_OK;
exit:
return( err );
}
示例10: securetransport
static OSStatus securetransport(ssl_test_handle * ssl)
{
OSStatus ortn;
SSLContextRef ctx = ssl->st;
SecTrustRef trust = NULL;
bool got_server_auth = false, got_client_cert_req = false;
ortn = SSLHandshake(ctx);
require_action_quiet(ortn==errSSLWouldBlock, out, printf("SSLHandshake failed with err %ld\n", (long)ortn));
size_t sent, received;
const char *r=request;
size_t l=sizeof(request);
do {
ortn = SSLWrite(ctx, r, l, &sent);
if(ortn == errSSLWouldBlock) {
r+=sent;
l-=sent;
}
if (ortn == errSSLServerAuthCompleted)
{
require_string(!got_server_auth, out, "second server auth");
require_string(!got_client_cert_req, out, "got client cert req before server auth");
got_server_auth = true;
require_string(!trust, out, "Got errSSLServerAuthCompleted twice?");
/* verify peer cert chain */
require_noerr(SSLCopyPeerTrust(ctx, &trust), out);
SecTrustResultType trust_result = 0;
/* this won't verify without setting up a trusted anchor */
require_noerr(SecTrustEvaluate(trust, &trust_result), out);
}
} while(ortn == errSSLWouldBlock || ortn == errSSLServerAuthCompleted);
//fprintf(stderr, "\nHTTP Request Sent\n");
require_noerr_action_quiet(ortn, out, printf("SSLWrite failed with err %ld\n", (long)ortn));
require_string(got_server_auth, out, "never got server auth");
do {
ortn = SSLRead(ctx, reply, sizeof(reply)-1, &received);
//fprintf(stderr, "r"); usleep(1000);
} while(ortn == errSSLWouldBlock);
//fprintf(stderr, "\n");
require_noerr_action_quiet(ortn, out, printf("SSLRead failed with err %ld\n", (long)ortn));
reply[received]=0;
//fprintf(stderr, "HTTP reply:\n");
//fprintf(stderr, "%s\n",reply);
out:
SSLClose(ctx);
SSLDisposeContext(ctx);
if (trust) CFRelease(trust);
return ortn;
}
示例11: micokit_ext_mfg_test
void micokit_ext_mfg_test(mico_Context_t *inContext)
{
OSStatus err = kUnknownErr;
char str[64] = {'\0'};
char mac[6];
int rgb_led_hue = 0;
uint8_t dht11_ret = 0;
uint8_t dht11_temp_data = 0;
uint8_t dht11_hum_data = 0;
int light_ret = 0;
uint16_t light_sensor_data = 0;
int infrared_ret = 0;
uint16_t infrared_reflective_data = 0;
int32_t bme280_temp = 0;
uint32_t bme280_hum = 0;
uint32_t bme280_press = 0;
UNUSED_PARAMETER(inContext);
mico_rtos_init_semaphore(&mfg_test_state_change_sem, 1);
err = MICOAddNotification( mico_notify_WIFI_SCAN_COMPLETED, (void *)mico_notify_WifiScanCompleteHandler );
require_noerr( err, exit );
while(1){
switch(mfg_test_module_number){
case 0: // mfg mode start
{
sprintf(str, "%s\r\nStart:\r\n%s\r\n%s", "TEST MODE", " next: Key2", " prev: Key1");
mf_printf(str);
while(kNoErr != mico_rtos_get_semaphore(&mfg_test_state_change_sem, MICO_WAIT_FOREVER));
break;
}
case 1: // OLED
{
while(kNoErr != mico_rtos_get_semaphore(&mfg_test_state_change_sem, 0))
{
sprintf(str, "%s OLED\r\n", OLED_MFG_TEST_PREFIX);
mf_printf(str);
mico_thread_msleep(300);
mf_printf(mfg_test_oled_test_string);
mico_thread_msleep(300);
}
OLED_Clear();
break;
}
case 2: // RGB_LED
{
sprintf(str, "%s RGB LED\r\nBlink: \r\n R=>G=>B", OLED_MFG_TEST_PREFIX);
mf_printf(str);
while(kNoErr != mico_rtos_get_semaphore(&mfg_test_state_change_sem, 0))
{
hsb2rgb_led_open(rgb_led_hue, 100, 50);
rgb_led_hue += 120;
if(rgb_led_hue >= 360){
rgb_led_hue = 0;
}
mico_thread_msleep(300);
}
hsb2rgb_led_open(0, 0, 0);
break;
}
case 3: // infrared sensor
{
while(kNoErr != mico_rtos_get_semaphore(&mfg_test_state_change_sem, 0))
{
infrared_ret = infrared_reflective_read(&infrared_reflective_data);
if(0 == infrared_ret){
sprintf(str, "%s Infrared\r\nInfrared: %d", OLED_MFG_TEST_PREFIX,
infrared_reflective_data);
mf_printf(str);
}
mico_thread_msleep(300);
}
break;
}
case 4: // DC Motor
{
sprintf(str, "%s DC Motor\r\nRun:\r\n on : 500ms\r\n off: 500ms", OLED_MFG_TEST_PREFIX);
mf_printf(str);
while(kNoErr != mico_rtos_get_semaphore(&mfg_test_state_change_sem, 0))
{
dc_motor_set(1);
mico_thread_msleep(500);
dc_motor_set(0);
mico_thread_msleep(500);
}
dc_motor_set(0);
break;
}
case 5: // BME280
{
while(kNoErr != mico_rtos_get_semaphore(&mfg_test_state_change_sem, 0))
//.........这里部分代码省略.........
示例12: require_action
void CSecondPage::OnTvnSelchangedBrowseList(NMHDR *pNMHDR, LRESULT *pResult)
{
LPNMTREEVIEW pNMTreeView = reinterpret_cast<LPNMTREEVIEW>(pNMHDR);
CPrinterSetupWizardSheet * psheet;
Printer * printer;
int err = 0;
psheet = reinterpret_cast<CPrinterSetupWizardSheet*>(GetParent());
require_action( psheet, exit, err = kUnknownErr );
// The strange code here is to workaround a bug in the CTreeCtrl, whereupon the item
// we selected isn't passed through correctly to this callback routine.
if ( !m_gotChoice )
{
printer = psheet->GetSelectedPrinter();
// If we really haven't selected a printer, then re-select NULL and exit
if ( !printer )
{
m_browseList.SelectItem( NULL );
goto exit;
}
// If we already have selected a printer, fake like we've clicked on it, but only
// if the CTreeCtrl hasn't already selected it
else if ( printer->item != m_browseList.GetSelectedItem() )
{
m_gotChoice = true;
m_browseList.SelectItem( printer->item );
goto exit;
}
}
HTREEITEM item = m_browseList.GetSelectedItem();
require_quiet( item, exit );
printer = reinterpret_cast<Printer*>(m_browseList.GetItemData( item ) );
require_quiet( printer, exit );
//
// this call will trigger a resolve. When the resolve is complete,
// our OnResolve will be called.
//
err = psheet->StartResolve( printer );
require_noerr( err, exit );
//
// And clear out the printer information box
//
SetPrinterInformationState( FALSE );
m_descriptionField.SetWindowText(L"");
m_locationField.SetWindowText(L"");
exit:
if (err != 0)
{
CString text;
CString caption;
text.LoadString(IDS_ERROR_SELECTING_PRINTER_TEXT);
caption.LoadString(IDS_ERROR_SELECTING_PRINTER_CAPTION);
MessageBox(text, caption, MB_OK|MB_ICONEXCLAMATION);
}
*pResult = 0;
}
示例13: localTcpClient_thread
void localTcpClient_thread(void *inFd)
{
OSStatus err;
int clientFd = *(int *)inFd;
uint8_t *inDataBuffer = NULL;
int len;
int len_temp;
fd_set readfds;
fd_set writeSet;
struct timeval_t t;
int eventFd = -1;
mico_queue_t queue;
socket_msg_t *msg;
int sent_len, errno;
inDataBuffer = malloc(wlanBufferLen);
require_action(inDataBuffer, exit, err = kNoMemoryErr);
err = socket_queue_create(context, &queue);
require_noerr( err, exit );
eventFd = mico_create_event_fd(queue);
if (eventFd < 0) {
server_log("create event fd error");
goto exit_with_queue;
}
t.tv_sec = 4;
t.tv_usec = 0;
while(1){
FD_ZERO(&readfds);
FD_SET(clientFd, &readfds);
FD_SET(eventFd, &readfds);
select(24, &readfds, NULL, NULL, &t);
/* send UART data */
if (FD_ISSET( eventFd, &readfds )) { // have data and can write
FD_ZERO(&writeSet );
FD_SET(clientFd, &writeSet );
t.tv_usec = 100*1000; // max wait 100ms.
select(1, NULL, &writeSet, NULL, &t);
if((FD_ISSET( clientFd, &writeSet )) &&
(kNoErr == mico_rtos_pop_from_queue( &queue, &msg, 0))) {
sent_len = write(clientFd, msg->data, msg->len);
if (sent_len <= 0) {
len = sizeof(errno);
getsockopt(clientFd, SOL_SOCKET, SO_ERROR, &errno, &len);
socket_msg_free(msg);
server_log("write error, fd: %d, errno %d", clientFd, errno );
if (errno != ENOMEM) {
goto exit_with_queue;
}
} else {
socket_msg_free(msg);
}
}
}
/*Read data from tcp clients and process these data using HA protocol */
if (FD_ISSET(clientFd, &readfds)) {
len = recv(clientFd, inDataBuffer, wlanBufferLen, 0);
len_temp=len;
tcp_date_num+=len;
require_action_quiet(len>0, exit_with_queue, err = kConnectionErr);
// sppWlanCommandProcess(inDataBuffer, &len, clientFd, context);
// MicoUartSend(MFG_TEST, inDataBuffer, len_temp);//wcz wcz_add
}
}
exit_with_queue:
len = sizeof(errno);
getsockopt(clientFd, SOL_SOCKET, SO_ERROR, &errno, &len);
server_log("Exit: Client exit with err = %d, socket errno %d", err, errno);
if (eventFd >= 0) {
mico_delete_event_fd(eventFd);
}
socket_queue_delete(context, &queue);
exit:
SocketClose(&clientFd);
if(inDataBuffer) free(inDataBuffer);
mico_rtos_delete_thread(NULL);
return;
}
示例14: USBToHostWord
OSStatus USBMIDIDeviceManager::UseDeviceAndInterface(USBDevice * usbDevice,
USBInterface * usbInterface)
{
// Match the device that was just located with what is in the current state
MIDIDeviceRef midiDevice = NULL;
IOUSBDeviceInterface **devIntf = usbDevice->GetPluginInterface();
const IOUSBDeviceDescriptor *devDesc = usbDevice->GetDeviceDescriptor();
bool deviceInSetup = false;
UInt32 vendorProduct = ((UInt32)USBToHostWord(devDesc->idVendor) << 16) |
USBToHostWord(devDesc->idProduct);
CFStringRef serialNumber = usbDevice->GetString(devDesc->iSerialNumber);
OSStatus err;
UInt32 locationID;
require_noerr(err = (*devIntf)->GetLocationID(devIntf, &locationID), errexit);
{
// See if it's already in the setup
MIDIDeviceListRef curDevices = MIDIGetDriverDeviceList(mDriver->Self());
int nDevices = MIDIDeviceListGetNumberOfDevices(curDevices), firstPass, lastPass;
if (serialNumber == NULL) {
firstPass = 2;
lastPass = 3;
} else {
firstPass = 1;
lastPass = 1;
}
for (int pass = firstPass; pass <= lastPass && !deviceInSetup; ++pass) {
// pass 1: match by serial number if present (skipped if not)
// pass 2: match by locationID
// pass 3: match by order found
for (int iDevice = 0; iDevice < nDevices; ++iDevice) {
SInt32 prevLocation, prevVendorProduct, isOffline;
midiDevice = MIDIDeviceListGetDevice(curDevices, iDevice);
err = MIDIObjectGetIntegerProperty(midiDevice, kUSBVendorProductProperty,
&prevVendorProduct);
if (!err && UInt32(prevVendorProduct) == vendorProduct) {
switch (pass) {
case 1:
{
CFStringRef prevSerial;
err = MIDIObjectGetStringProperty(midiDevice, kSerialNumberProperty,
&prevSerial);
if (!err) {
if (CFEqual(prevSerial, serialNumber))
deviceInSetup = true;
CFRelease(prevSerial);
}
}
break;
case 2:
err = MIDIObjectGetIntegerProperty(midiDevice, kUSBLocationProperty,
&prevLocation);
if (!err && UInt32(prevLocation) == locationID)
deviceInSetup = true;
break;
case 3:
err = MIDIObjectGetIntegerProperty(midiDevice, kMIDIPropertyOffline,
&isOffline);
if (!err && isOffline)
deviceInSetup = true;
break;
}
}
if (deviceInSetup) break;
}
}
MIDIDeviceListDispose(curDevices);
}
if (!deviceInSetup) {
#if VERBOSE
printf("creating new device\n");
#endif
midiDevice = mDriver->CreateDevice(usbDevice, usbInterface);
require_noerr(err = MIDISetupAddDevice(midiDevice), errexit);
} else {
#if VERBOSE
printf("old device found\n");
#endif
mDriver->PreExistingDeviceFound(midiDevice, usbDevice, usbInterface);
}
// set device properties unconditionally
MIDIObjectSetIntegerProperty(midiDevice, kUSBVendorProductProperty, vendorProduct);
MIDIObjectSetIntegerProperty(midiDevice, kUSBLocationProperty, locationID);
if (serialNumber != NULL)
MIDIObjectSetStringProperty(midiDevice, kSerialNumberProperty, serialNumber);
// Create a USBMIDIDevice (or subclass), starting it for I/O
{
USBMIDIDevice *ioDev = mDriver->CreateUSBMIDIDevice(usbDevice, usbInterface, midiDevice);
if (ioDev == NULL) goto errexit;
if (!ioDev->Initialize())
delete ioDev;
else {
if (mUSBMIDIDeviceList.size() == 0)
mUSBMIDIDeviceList.reserve(4);
mUSBMIDIDeviceList.push_back(ioDev);
MIDIObjectSetIntegerProperty(midiDevice, kMIDIPropertyOffline, false);
//.........这里部分代码省略.........
示例15: MakeWindowTransparent
OSStatus MakeWindowTransparent(WindowRef aWindowRef)
{
OSStatus status = paramErr;
require(aWindowRef != NULL, paramErr);
// is the window compositing or not?
WindowAttributes attributes;
status = GetWindowAttributes(aWindowRef, &attributes);
require_noerr(status, GetWindowAttributes);
/* if (attributes & kWindowCompositingAttribute)
{
// it is compositing so we intercept the kEventWindowGetRegion event to be able to specify an empty opaque region
EventTypeSpec wCompositingEvents = { kEventClassWindow, kEventWindowGetRegion };
status = InstallWindowEventHandler(aWindowRef, TransparentWindowHandler, 1, &wCompositingEvents, aWindowRef, NULL);
require_noerr(status, InstallWindowEventHandler);
HIViewRef contentView;
status = HIViewFindByID(HIViewGetRoot(aWindowRef), kHIViewWindowContentID, &contentView);
require_noerr(status, HIViewFindByID);
// and we intercept the kEventControlDraw event of our content view so that we can make it transparent
EventTypeSpec cCompositingEvents = { kEventClassControl, kEventControlDraw };
status = InstallControlEventHandler(contentView, TransparentWindowHandler, 1, &cCompositingEvents, contentView, NULL);
require_noerr(status, InstallControlEventHandler);
}
else*/
{
// it is non-compositing so we intercept the kEventWindowGetRegion event to be able to specify an empty opaque region
// and we intercept the kEventWindowDrawContent event of our window so that we can make it transparent
EventTypeSpec wNonCompositingEvents[] =
{
{ kEventClassWindow, kEventWindowGetRegion },
{ kEventClassWindow, kEventWindowDrawContent }
};
status = InstallWindowEventHandler(aWindowRef, TransparentWindowHandler, GetEventTypeCount(wNonCompositingEvents), wNonCompositingEvents, aWindowRef, NULL);
require_noerr(status, InstallWindowEventHandler);
}
// telling the HIToolbox that our window is not opaque so that we will be asked for the opaque region
UInt32 features;
status = GetWindowFeatures(aWindowRef, &features);
require_noerr(status, GetWindowFeatures);
if ( ( features & kWindowIsOpaque ) != 0 )
{
status = HIWindowChangeFeatures(aWindowRef, 0, kWindowIsOpaque);
require_noerr(status, HIWindowChangeFeatures);
}
// force opaque shape to be recalculated
status = ReshapeCustomWindow(aWindowRef);
require_noerr(status, ReshapeCustomWindow);
// ensure that HIToolbox doesn't use standard shadow style, which defeats custom opaque shape
status = SetWindowAlpha(aWindowRef, 0.999);
require_noerr(status, SetWindowAlpha);
SetWindowAlpha:
ReshapeCustomWindow:
HIWindowChangeFeatures:
GetWindowFeatures:
InstallControlEventHandler:
HIViewFindByID:
InstallWindowEventHandler:
GetWindowAttributes:
paramErr:
return status;
}