Пример #1
0
int DOKAN_CALLBACK OnReadFile(
	LPCWSTR  FileName,
	LPVOID   Buffer,
	DWORD    NumberOfBytesToRead,
	LPDWORD  NumberOfBytesRead,
	LONGLONG Offset,
	PDOKAN_FILE_INFO DokanFileInfo ) {
	LOG( L"[OnReadFile] FileName = %s, Offset = %lld, NumberOfBytesToRead = %d\n",
		  FileName, Offset, NumberOfBytesToRead );
	JNIEnv* env = get_env();
	//jvm->AttachCurrentThread((void **)&env, NULL);

	int result = -ERROR_GEN_FAILURE;
	try {
		jstring jfileName = ToJavaString( env, FileName );
		jobject jdokanFileInfo = ToDokanFileInfoJavaObject( env, DokanFileInfo );

		DWORD readed = env->CallIntMethod( gOperations, onReadFileID,
													  jfileName,
													  env->NewDirectByteBuffer( Buffer, NumberOfBytesToRead ),
													  Offset,
													  jdokanFileInfo );
		if ( NumberOfBytesRead )
			*NumberOfBytesRead = readed;
		result = GetOperationResult( env );
		if ( result != 0 ) {
			LOGA( "[OnReadFile] result = %d\n", result );
		}
	} catch ( const char* msg ) {
		LOGA( "[OnReadFile] %s\n", msg );
	}

	release_env( env );
	return result;
}
Пример #2
0
static void print_device_info()
{
    unsigned char id[4] = {0};
    uint8_t ctrl_a, ctrl_b;
    uint8_t i;
    int8_t rc;

    for (i = 0; i < DEV_ID_LEN; ++i) {
        rc = twi_read(COMPASS_ADDR, REG_ID_A + i, &id[i]);
        if (rc != NRK_OK)
            ABORT("failed to read ID\r\n");
    }

    rc = twi_read(COMPASS_ADDR, REG_CTRL_A, &ctrl_a);
    if (rc != NRK_OK)
        ABORT("failed to read ctrl a reg\r\n");

    rc = twi_read(COMPASS_ADDR, REG_CTRL_B, &ctrl_b);
    if (rc != NRK_OK)
        ABORT("failed to read ctrl b reg\r\n");

    LOG("device info: ");
    LOGA(" id: "); LOGP("%s ", id);
    LOGA(" crl a: "); LOGP("0x%x ", ctrl_a);
    LOGA(" ctrl b: "); LOGP("0x%x ", ctrl_b);
    LOGA("\r\n");
}
Пример #3
0
void handle_discover_response(pkt_t *pkt)
{
    node_id_t origin = pkt->payload[PKT_RESPONSE_ORIGIN_OFFSET];
    uint8_t seq = pkt->payload[PKT_RESPONSE_SEQ_OFFSET];
    nrk_time_t delay;
    uint8_t attempt;

    if (!IS_VALID_NODE_ID(origin)) {
        LOG("WARN: invalid origin in response: ");
        LOGP("%d\r\n", origin);
        return;
    }

    LOG("response: orig "); LOGP("%u", origin);
    LOGA(" seq "); LOGP("%u", seq);
    LOGA(" src "); LOGP("%u", pkt->src);
    LOGA(": ");

    nrk_time_get(&last_activity);

    if (origin == this_node_id) {
        LOGA("reached origin\r\n");

        add_path_to_graph(pkt);
        print_graph(&network);
    } else { /* we're not the destination: forward to gateway */
        attempt = 0;
        do {
            forward_response(pkt, attempt);
            choose_delay(&delay, &discover_req_delay);
            nrk_wait(delay);
        } while (++attempt < discover_send_attempts);
    }
}
Пример #4
0
static void set_state(discover_state_t new_state)
{
    LOG("state: ");
    LOGF(ENUM_TO_STR(discover_state, state_names));
    LOGA(" -> ");
    LOGF(ENUM_TO_STR(new_state, state_names));
    LOGA("\r\n");

    discover_state = new_state;
    periods_in_state = 0;
}
Пример #5
0
static void forward_response(pkt_t *pkt, uint8_t attempt)
{
    int8_t rc;

    LOGA("fwd to next hop ");
    LOGP("%d ", route_to_origin);
    LOGA(" attempt "); LOGP("%u\r\n", attempt);

    pkt->dest = route_to_origin;
    rc = send_pkt(pkt, TX_FLAG_NONE, NULL);
    if (rc != NRK_OK)
        LOG("WARN: failed to send discover req\r\n");
}
Пример #6
0
int8_t probe(uint8_t depth)
{
    outstanding_seq++; 
    nrk_time_get(&last_activity);

    LOG("starting: orig "); LOGP("%d", this_node_id);
    LOGA(" seq "); LOGP("%d", outstanding_seq);
    LOGA(" depth "); LOGP("%d\r\n", depth);

    init_graph(&network);
    print_graph(&network);
    discovered_seq = outstanding_seq; // origin starts discovered
    return broadcast_request(this_node_id, outstanding_seq, depth, 0 /* attempt */);
}
Пример #7
0
void m2_init() {
	LOG("M2: init");
	
	// TIME <-> EDIT_TIME
	// TIME <- EDIT_TIME -> TIME
	show_time_mw.up = &edit_time_mw;
	edit_time_mw.prev = &show_time_mw;
	edit_time_mw.next = &show_time_mw;
	
	// TIME <-> TIMER
	// TIMER <-> EDIT_ON_TIME 
	// TIMER <-> EDIT_OFF_TIME
	show_time_mw.down = &set_timer_mw;
	set_timer_mw.prev = &show_time_mw;
	set_timer_mw.next = &show_time_mw;	
	
	set_timer_mw.up = &edit_on_time_mw;
	edit_on_time_mw.prev = &set_timer_mw;
	edit_on_time_mw.next = &set_timer_mw;	
	
	set_timer_mw.down = &edit_off_time_mw;
	edit_off_time_mw.prev = &show_time_mw;
	edit_off_time_mw.next = &show_time_mw;
	
	curMW = &show_time_mw;
			
	dataHolder.init();
			
	LOGA("M2: init, curMW=%s", (curMW->mode->name));
}
Пример #8
0
void TestUtls(std::function<int(void)> fun, std::string name)
{
    LOG_STREAM(LOG4Z_MAIN_LOGGER_ID, LOG_LEVEL_ALARM, nullptr, 0, "");
    LOGA("begin test ----[" << name << "]----"); 
    double now = getFloatNowTime();
    int ret = fun();
    if (ret == 0)
    {
        LOGA("end test ----[" << name << "](0)----" << " used second=" << getFloatNowTime() - now);
    }
    else
    {
        LOGE("end test ----[" << name << "](" << ret << ")----" << " used second=" << getFloatNowTime() - now );
        exit(ret);
    }
}
Пример #9
0
void loopback_udp(uint8 ch, uint16 port)
{
    int ret;
    uint32 destip = 0;
    uint16 destport;

    ret = UDPRecv(ch, data_buf, TX_RX_MAX_BUF_SIZE, (uint8*)&destip, &destport);

    if(ret > 0) {				// Received
        ret = UDPSend(ch, data_buf, ret, (uint8*)&destip ,destport);

        if(ret == ERROR_TIME_OUT) {
            ERR("Timeout");
            UDPClose(ch);
            DBG("UDP Socket Close");
        }

    } else if(ret == ERROR_NOT_UDP_SOCKET) {	// Not UDP Socket, It's TCP Socket
        DBG("TCP Socket Close");
        TCPClose(ch);
    } else if(ret == ERROR_CLOSED) {		// Socket Closed
        LOGA("UDP Loop-Back Started - ch(%d)",(uint16)ch);
        UDPOpen(ch, port);
    }
}
Пример #10
0
//You should implement either FindFires or FindFilesWithPattern
int DOKAN_CALLBACK OnFindFilesWithPattern(
	LPCWSTR			PathName,
	LPCWSTR			SearchPattern,
	PFillFindData	pFillFindData,		// call this function with PWIN32_FIND_DATAW
	PDOKAN_FILE_INFO DokanFileInfo ) {
	LOG( L"[OnFindFilesWithPattern] PathName = %s\n", PathName );
	JNIEnv* env = get_env();
	//jvm->AttachCurrentThread((void **)&env, NULL);

	int result = -ERROR_GEN_FAILURE;
	try {
		jstring jpathName = ToJavaString( env, PathName );
		jstring jsearchPattern = ToJavaString( env, SearchPattern );
		jobject jdokanFileInfo = ToDokanFileInfoJavaObject( env, DokanFileInfo );

		jobjectArray ary = ( jobjectArray )env->CallObjectMethod( gOperations,
								 onFindFilesWithPatternID,
								 jpathName, jsearchPattern, jdokanFileInfo );
		result = GetOperationResult( env );

		if ( result == 0 && ary != NULL && pFillFindData != NULL ) {
			for ( int i = 0; i < env->GetArrayLength( ary ); i++ ) {
				WIN32_FIND_DATAW win32FindData;
				ToWin32FindData( env, env->GetObjectArrayElement( ary, i ), &win32FindData );
				pFillFindData( &win32FindData, DokanFileInfo );
			}
		}
	} catch ( const char* msg ) {
		LOGA( "[OnFindFilesWithPattern] %s\n", msg );
	}

	release_env( env );
	return result;
}
Пример #11
0
int DOKAN_CALLBACK OnOpenDirectory(
	LPCWSTR				FileName,
	PDOKAN_FILE_INFO DokanFileInfo ) {
	LOG( L"[OnOpenDirectory] FileName = %s\n", FileName );
	JNIEnv* env = get_env();
	//jvm->AttachCurrentThread((void **)&env, NULL);

	int result = -ERROR_GEN_FAILURE;
	try {
		jstring jfileName = ToJavaString( env, FileName );
		jobject jdokanFileInfo = ToDokanFileInfoJavaObject( env, DokanFileInfo );

		jlong handle = env->CallLongMethod( gOperations, onOpenDirectoryID,
														jfileName, jdokanFileInfo );
		result = GetOperationResult( env );

		if ( result == 0 ) {
			DokanFileInfo->Context = handle;
		}
	} catch ( const char* msg ) {
		LOGA( "[OnOpenDirectory] %s\n", msg );
	}

	release_env( env );
	return result;
}
Пример #12
0
int DOKAN_CALLBACK OnMoveFile(
	LPCWSTR ExistingFileName,
	LPCWSTR NewFileName,
	BOOL	ReplaceExisiting,
	PDOKAN_FILE_INFO DokanFileInfo ) {
	LOG( L"[OnMoveFile] ExistingFileName = %s\n", ExistingFileName );
	JNIEnv* env = get_env();
	//jvm->AttachCurrentThread((void **)&env, NULL);

	int result = -ERROR_GEN_FAILURE;
	try {
		jstring jExistingFileName = ToJavaString( env, ExistingFileName );
		jstring jNewFileName = ToJavaString( env, NewFileName );
		jobject jdokanFileInfo = ToDokanFileInfoJavaObject( env, DokanFileInfo );

		env->CallVoidMethod( gOperations, onMoveFileID,
									jExistingFileName, jNewFileName, ReplaceExisiting, jdokanFileInfo );
		result = GetOperationResult( env );
	} catch ( const char* msg ) {
		LOGA( "[OnMoveFile] %s\n", msg );
	}

	release_env( env );
	return result;
}
/** Debug a cell of a MultiColumnListItem
  *
  * This function must be called each time a cell is drawn. According to 
  * the debug settings, this class will debug or not.
  *
  * \param vQr          The QuadRenderer used to draw
  * \param vMcl         The MultiColumnList
  * \param vCell        The cell
  * \param vDrawingRect The rectangle where the cell is dran
  *
  */
void RainbruRPG::OgreGui::MultiColumnListDebugSettings::
debugCell(QuadRenderer* vQr, MultiColumnList* vMcl, MultiColumnListCell* vCell,
	  const Ogre::Rectangle& vDrawingRect){
  mCurrentCell++;
  LOGA(vMcl, _("MultiColumnList pointer is NULL. Program should crash."));

  std::string WidgetName = vMcl->getDebugName();
  if (mEnabled){
    if (mWidgetName.empty() || mWidgetName == WidgetName){
      if (mItemNum == -1 || mItemNum == mCurrentItem){
	if (mColumnNum == -1 || mColumnNum == mCurrentCell){
	  mUsefull=true;
	  std::string debugString = makeDebugString(vMcl, vCell, vDrawingRect);
	  if (mFlags.scissorRect_log){
	    debugString += makeScissorDebugString( vQr );
	  }
	  LOGI(debugString.c_str());

	  if (mFlags.drawingRect_draw){
	    vQr->drawFilledRectangle(vDrawingRect, mCellDrawingRectangleColor);
	  }
	  drawScissorRectangle( vQr );
	}
      }
    }
  }
}
Пример #14
0
int DOKAN_CALLBACK OnCreateFile(
	LPCWSTR		FileName,
	DWORD		DesiredAccess,
	DWORD		ShareMode,
	DWORD		CreationDisposition,
	DWORD		FlagsAndAttributes,
	//HANDLE,       // TemplateFile
	PDOKAN_FILE_INFO DokanFileInfo ) {
	LOG( L"[OnCreateFile] FileName = %s\n", FileName );
	JNIEnv* env = get_env();
	//jvm->AttachCurrentThread((void **)&env, NULL);

	int result = -ERROR_GEN_FAILURE;
	try {
		jstring jfileName = ToJavaString( env, FileName );
		jobject jdokanFileInfo = ToDokanFileInfoJavaObject( env, DokanFileInfo );

		jlong handle = env->CallLongMethod( gOperations, onCreateFileID,
														jfileName, DesiredAccess, ShareMode, CreationDisposition,
														FlagsAndAttributes, jdokanFileInfo );
		result = GetOperationResult( env );

		if ( result == 0 ) {
			DokanFileInfo->Context = handle;
		}
		LOG( L"[OnCreateFile] result = %d, handle = %d\n", result, handle );
	} catch ( const char* msg ) {
		LOGA( "[OnCreateFile] %s\n", msg );
	}

	release_env( env );
	return result;
}
Пример #15
0
int DOKAN_CALLBACK OnGetFileSecurity(
	LPCWSTR FileName,
	PSECURITY_INFORMATION RequestedSecurityInformation,
	PSECURITY_DESCRIPTOR SecurityDescriptorBuffer,
	ULONG BufferLength,
	PULONG BufferLengthNeeded,
	PDOKAN_FILE_INFO DokanFileInfo ) {
	LOG( L"[GetFileSecurity]\n" );
	JNIEnv* env = get_env();

	int result = -ERROR_GEN_FAILURE;
	try {
		//jobject jdokanFileInfo = ToDokanFileInfoJavaObject( env, DokanFileInfo );
		LOG( L"GetFileSecurity FileName: %s \n", FileName );
		LOG( L"GetFileSecurity RequestedSecurityInformation: %d\n", RequestedSecurityInformation );
		LOG( L"GetFileSecurity SecurityDescriptorBuffer: %d\n", SecurityDescriptorBuffer );
		LOG( L"GetFileSecurity BufferLength: %d\n", BufferLength );
		LOG( L"GetFileSecurity BufferLengthNeeded: %d\n", BufferLengthNeeded );
	} catch ( const char* msg ) {
		LOGA( "[GetFileSecurity] %s\n", msg );
	}

	release_env( env );
	return result;
}
Пример #16
0
static int8_t twi_tx(uint8_t *buf, uint8_t len)
{
    uint8_t i;
    uint8_t waits = 0;
    const uint8_t max_waits =
        TIME_TO_MS(twi_tx_timeout) / TIME_TO_MS(twi_tx_poll_interval);

    LOG("TWI write: ");
    for (i = 0; i < len; ++i)
        LOGP("0x%x ", msg_buf[i]);
    LOGA("\r\n");

    TWI_Start_Transceiver_With_Data(msg_buf, len);

    /* NOTE: can't use nrk_time_get because before nrk_start() */
    while (TWI_Transceiver_Busy() && waits++ < max_waits)
        nrk_spin_wait_us(twi_tx_poll_interval.nano_secs / 1000);

    if (waits >= max_waits) {
        LOG("WARN: TWI write timed out\r\n");
        return NRK_ERROR;
    }

    if (!TWI_statusReg.lastTransOK)
    {
        LOG("WARN: TWI write failed\r\n");
        handle_error(TWI_Get_State_Info());
        return NRK_ERROR;
    }

    return NRK_OK;
}
Пример #17
0
/** Draw the givenh MultiColumnList
  *
  * \param qr  The QuadRenderer used to draw
  * \param mcl The MultiColumnList to draw
  *
  */
void RainbruRPG::OgreGui::wdMultiColumnList::
draw(QuadRenderer* qr, MultiColumnList* mcl){

  mCurrentMcl = mcl;

  // Test initialization and init if needed
  // Call preDrawingComputation cause it is first drawing
  if (!wasInit){
    init(mcl);
    preDrawingComputation( mcl );
  }

  LOGA(mWidgetParent, "MultiColumnList parent poiner is NULL");

  // Get event driven values (cannot be got with preDrawingComputation)
  int movingColumn=mcl->getMovedColumnIndex();

  // Draws multicolumnlist
  drawBorder(qr);
  drawAllHeaders(qr, mcl, movingColumn);
  drawAllItems(qr, mcl, movingColumn);

  // Set the scissor rectangle as the parent window corners
  // It is used because, as the next widgets drawn are the ScrollBars
  // (please see MultiColumnList::draw() implementation), they will
  // be cut off be the parent scissor setting (the Window corners)
  qr->setUseParentScissor(false);
  qr->setScissorRectangle(mWidgetParent->getCorners());
  qr->setUseParentScissor(true);  

  mDebugSettings->reset();

}
Пример #18
0
static int8_t proc_rcmd(node_id_t requester,
                        uint8_t *req_buf, uint8_t req_len,
                        uint8_t *reply_buf, uint8_t reply_size,
                        uint8_t *reply_len)
{
    cmd_handler_t handler;
    uint8_t argc;

    LOG("rcv rcmd req from "); LOGP("%u", requester); LOGA(": ");
    LOGP("%s\r\n", req_buf); /* TODO: check that it is null terminated */

    argc = parse_args((char *)req_buf, argv, MAX_ARGS);
    if (argc == 0) {
        LOG("WARN: failed to parse cmd\r\n");
        return NRK_ERROR;
    }

    handler = lookup_cmd_handler(argv[0]);
    if (!handler) {
        LOG("WARN: unknown cmd\r\n");
        return NRK_ERROR;
    }

    return handler(argc, argv);
}
Пример #19
0
int DOKAN_CALLBACK OnSetFileTime(
	LPCWSTR		FileName,
	CONST FILETIME* CreationTime,
	CONST FILETIME* LastAccessTime,
	CONST FILETIME* LastWriteTime,
	PDOKAN_FILE_INFO DokanFileInfo ) {
	LOG( L"[OnSetFileTime] FileName = %s\n", FileName );
	JNIEnv* env = get_env();
	//jvm->AttachCurrentThread((void **)&env, NULL);

	int result = -ERROR_GEN_FAILURE;
	try {
		jstring jfileName = ToJavaString( env, FileName );
		jobject jdokanFileInfo = ToDokanFileInfoJavaObject( env, DokanFileInfo );

		env->CallVoidMethod( gOperations, onSetFileTimeID,
									jfileName, FileTime2LongLong( CreationTime ),
									FileTime2LongLong( LastAccessTime ), FileTime2LongLong( LastWriteTime ),
									jdokanFileInfo );
		result = GetOperationResult( env );
	} catch ( const char* msg ) {
		LOGA( "[OnSetFileTime] %s\n", msg );
	}

	release_env( env );
	return result;
}
Пример #20
0
/** Constructor
  *
  * \param dim    The dimensions in pixels
  * \param vParent The parent window
  * \param sid    The skin 
  *
  */
RainbruRPG::OgreGui::MultiColumnList::
MultiColumnList(Vector4 dim, BetaGUI::Window* vParent, 
		RainbruRPG::OgreGui::OgreGuiSkinID sid):
  Widget(dim, (Widget*)vParent, sid),
  mHeaderHeight(20),
  mAbsCorners(),
  selectedColumn(NULL),
  mouseOveredItem(NULL),
  selectedItem(NULL),
  mLastColumnRight(0),
  mCurrentSortPolicy(MCS_NONE),
  mMovingColumn(-1),
  mToolTip(NULL),
  mMouseXDev(0),
  mResizedColumnIndex(-1),
  mResiedColumnRightPos(0),
  mVScrollBar(NULL),
  mHScrollBar(NULL),
  mGui(NULL),
  mPopupMenu(NULL),
  mParentWindow(NULL),
  mDebugName("NotYetSet")
{
  mParentWindow = vParent;
  mSkin = SkinManager::getSingleton().getSkin(this);
  mGui = &GUI::getSingleton();
  LOGA( mGui, _("GUI pointer is NULL, program should crash (segfault)."));

  mToolTip=new ToolTip(Vector4(0, 0, 200, 50), 
		       "Long time click to move column. Right button for "
		       "contextual menu.",
		       vParent, sid);

  mDrawingDev = new DrawingDevSettings("MultiColumnList", 0, 0);
  mXDrawingDev = new DrawingDevSettings("MultiColumnList", 0, 0);
  mPopupMenu = new PopupMenu(Vector4(0, 0, 200, 50),_("Columns menu"),vParent);
  mPopupMenu->hide();

  setName("MultiColumnList");

  Vector4 sbDim( dim.z-16, MCL_VSB_YPOS, 14, dim.w-(MCL_VSB_YPOS + 18) );
  mVScrollBar=new VScrollBar(sbDim, parent);//, OSI_BETAGUI);
  //  this->addWidget(mVScrollBar);

  Vector4 sbDim2( 2, dim.w-16, dim.z-20, 14 );
  mHScrollBar=new HScrollBar(sbDim2, parent);
  //  this->addWidget(mHScrollBar);

  // Signals connection
  mHScrollBar->sigValueChanged.connect( sigc::mem_fun(this,
     &RainbruRPG::OgreGui::MultiColumnList::horizontalScrollBarValueChange));

  mVScrollBar->sigValueChanged.connect( sigc::mem_fun(this,
     &RainbruRPG::OgreGui::MultiColumnList::verticalScrollBarValueChange));


  makeCorners();
}
Пример #21
0
int DOKAN_CALLBACK OnWriteFile(
	LPCWSTR  FileName,
	LPCVOID  Buffer,
	DWORD    NumberOfBytesToWrite,
	LPDWORD  NumberOfBytesWritten,
	LONGLONG Offset,
	PDOKAN_FILE_INFO DokanFileInfo ) {
	LOG( L"[OnWriteFile] FileName = %s, Offset = %lld, NumberOfBytesToWrite = %d\n",
		  FileName, Offset, NumberOfBytesToWrite );
	JNIEnv* env = get_env();
	//jvm->AttachCurrentThread((void **)&env, NULL);

	int result = -ERROR_GEN_FAILURE;
	try {
		jstring jfileName = ToJavaString( env, FileName );
		jobject jdokanFileInfo = ToDokanFileInfoJavaObject( env, DokanFileInfo );

		// Some one please modify here for the faster way !!
		LPVOID tmpBuffer = malloc( NumberOfBytesToWrite );
		if ( tmpBuffer == NULL )
			throw "Cannot allocate memory";
		CopyMemory( tmpBuffer, Buffer, NumberOfBytesToWrite );
		DWORD written = env->CallIntMethod( gOperations, onWriteFileID,
														jfileName,
														env->NewDirectByteBuffer( tmpBuffer, NumberOfBytesToWrite ),
														Offset,
														jdokanFileInfo );
		free( tmpBuffer );

		if ( NumberOfBytesWritten )
			*NumberOfBytesWritten = written;
		result = GetOperationResult( env );
		if ( result != 0 ) {
			LOGA( "[OnWriteFile] ERROR result = %d\n", result );
		} else {
			LOGA( "[OnWriteFile] written = %d\n", written );
		}
	} catch ( const char* msg ) {
		LOGA( "[OnWriteFile] %s\n", msg );
	}

	release_env( env );
	return result;
}
Пример #22
0
	virtual bool cmd(byte cmd) {
		switch (cmd) {
		case 1: { // left
			if (m == 1) { // cancel
				state = savedState; // restore state & exit
				m = 1;
				LOG("STM: cancel");
				return true;
			} else { // prev mode
				m --;
				updateDisp();
				LOGA("STM: prev, m=%d", m);
				return false;
			}
		} break;
		case 2: // down / up
		case 3: {
			if (m == 1) {
				state.on = 1 - state.on; // switch to off
				updateDisp();
				return false;
			} else {
				if (m == 2)
					dataHolder.put(state.timeOn);
				if (m == 3)
					dataHolder.put(state.timeOff);
				return true; // go to edit mode
			}
		} break;
		case 4: { // right			
			if (m == 3) { // save
				m = 1; // reset to next menu call
				LOG("STM: save");
				return true;
			} else { // next mode
				m ++;
				updateDisp();
				LOGA("STM: next, m=%d", m);
				return false;
			}
		} break;
		}
		return true;
	}
Пример #23
0
static void send_response(node_id_t origin, node_id_t src,
                          uint8_t seq, uint8_t attempt)
{
    int8_t rc;

    LOG("response to origin: seq "); LOGP("%u", seq);
    LOGA(" via "); LOGP("%u ", src);
    LOGA(" attempt "); LOGP("%u\r\n", attempt);

    init_pkt(&tx_pkt);
    tx_pkt.type = PKT_TYPE_DISCOVER_RESPONSE;
    tx_pkt.dest = src;
    tx_pkt.payload[PKT_RESPONSE_ORIGIN_OFFSET] = origin;
    tx_pkt.len += PKT_RESPONSE_ORIGIN_LEN;
    tx_pkt.payload[PKT_RESPONSE_SEQ_OFFSET] = seq;
    tx_pkt.len += PKT_RESPONSE_SEQ_LEN;
    rc = send_pkt(&tx_pkt, TX_FLAG_NONE, NULL);
    if (rc != NRK_OK)
        LOG("WARN: failed to send discover req\r\n");
}
Пример #24
0
int main(int argc, char* argv[])
{

#ifndef _WIN32
    //! linux下需要屏蔽的一些信号
    signal( SIGHUP, SIG_IGN );
    signal( SIGALRM, SIG_IGN ); 
    signal( SIGPIPE, SIG_IGN );
    signal( SIGXCPU, SIG_IGN );
    signal( SIGXFSZ, SIG_IGN );
    signal( SIGPROF, SIG_IGN ); 
    signal( SIGVTALRM, SIG_IGN );
    signal( SIGQUIT, SIG_IGN );
    signal( SIGCHLD, SIG_IGN);
    setenv("TZ", "GMT-8", 1);
#else
    //system("chcp 65001");
#endif
    srand((ui32)time(NULL));

    //AoeViewer();
    //vectorViewer();
    ILog4zManager::getPtr()->start();
    SessionManager::getRef().start();

    LOGA("version released by " << __DATE__ << " " << __TIME__);

    arith_prime();
    arith_gray_code();
    arith_sort();
    TestUtls(checkOther, "checkOther");
    TestUtls(checkString, "checkString");
    TestUtls(checkFile, "checkFile");
    TestUtls(checkFloat, "checkFloat");
    TestUtls(checkBalance, "checkBalance");
    TestUtls(checkRandom, "checkRandom");
    TestUtls(checkTime, "checkTime");
    LOGA("check all success.");
    sleepMillisecond(3000);
    return 0;
}
Пример #25
0
	virtual bool cmd(byte cmd) {
		LOGA("ST: cmd=%d", cmd);
		if (cmd == 3) { // up
			// go to edit
			dataHolder.put(timeGet());
		}
		if (cmd == 4) { // right
			if (++ m >= 4) m = 1; // circle: hh:mm | mm:ss | day
			updateDisp();
		}
		return true;
	}
Пример #26
0
int DOKAN_CALLBACK OnGetFileInformation(
	LPCWSTR          FileName,
	LPBY_HANDLE_FILE_INFORMATION ByHandleFileInfo,
	PDOKAN_FILE_INFO DokanFileInfo ) {
	LOG( L"[OnGetFileInformation] FileName = %s\n", FileName );
	JNIEnv* env = get_env();
	//jvm->AttachCurrentThread((void **)&env, NULL);

	int result = -ERROR_GEN_FAILURE;
	try {
		jstring jfileName = ToJavaString( env, FileName );
		jobject jdokanFileInfo = ToDokanFileInfoJavaObject( env, DokanFileInfo );

		jobject jobj = env->CallObjectMethod( gOperations, onGetFileInformationID,
														  jfileName, jdokanFileInfo );
		result = GetOperationResult( env );

		if ( result == 0 ) {
			ToByHandleFileInfo( env, jobj, ByHandleFileInfo );
			LOGA( "[OnGetFileInformation] %d %d %d\n",
					ByHandleFileInfo->dwFileAttributes,
					ByHandleFileInfo->nFileSizeHigh,
					ByHandleFileInfo->nFileSizeLow );
			LOGA( "[OnGetFileInformation] CreationTime: %d %d\n",
					ByHandleFileInfo->ftCreationTime.dwHighDateTime,
					ByHandleFileInfo->ftCreationTime.dwLowDateTime );
			LOGA( "[OnGetFileInformation] LastAccess: %d %d\n",
					ByHandleFileInfo->ftLastAccessTime.dwHighDateTime,
					ByHandleFileInfo->ftLastAccessTime.dwLowDateTime );
			LOGA( "[OnGetFileInformation] LastWrite: %d %d\n",
					ByHandleFileInfo->ftLastWriteTime.dwHighDateTime,
					ByHandleFileInfo->ftLastWriteTime.dwLowDateTime );
		}
	} catch ( const char* msg ) {
		LOGA( "[OnGetFileInformation] %s\n", msg );
	}

	release_env( env );
	return result;
}
Пример #27
0
void handle_discover_request(pkt_t *pkt)
{
    node_id_t origin;
    uint8_t seq, depth;
    nrk_time_t delay;
    uint8_t attempt;
    int8_t rc;

    origin = pkt->payload[PKT_REQUEST_ORIGIN_OFFSET];
    seq = pkt->payload[PKT_REQUEST_SEQ_OFFSET];
    depth = pkt->payload[PKT_REQUEST_DEPTH_OFFSET];

    if (!IS_VALID_NODE_ID(origin)) {
        LOG("WARN: invalid origin node id in response: ");
        LOGP("%d\r\n", origin);
        return;
    }

    LOG("request:");
    LOGA(" src "); LOGP("%u", pkt->src);
    LOGA(" orig "); LOGP("%u", origin);
    LOGA(" seq "); LOGP("%d (%d)", seq, discovered_seq);
    LOGA(" depth "); LOGP("%d\r\n", depth);

    nrk_time_get(&last_activity);

    choose_delay(&delay, &discover_req_delay);
    nrk_wait(delay);

    /* Discover this node: mark and broadcast to neighbors */
    if (discovered_seq != seq) {
        discovered_seq = seq;
        route_to_origin = pkt->src;

        LOG("discovered: orig "); LOGP("%d", origin);
        LOGA(" seq "); LOGP("%d", discovered_seq);
        LOGA(" hop "); LOGP("%d\r\n", route_to_origin);

        if (depth == 0 || pkt->hops < depth) {
            attempt = 0;
            do {
                rc = broadcast_request(origin, seq, depth, attempt);
                if (rc != NRK_OK)
                    LOG("WARN: failed to broadcast req\r\n");
                nrk_wait(delay);
            } while (++attempt < discover_send_attempts);
        } else {
            LOG("max depth reached: "); LOGP("%d\r\n", depth);
        }
    } else {
        LOG("already discovered: seq "); LOGP("%u\r\n", discovered_seq);
    }

    attempt = 0;
    do {
        send_response(origin, pkt->src, seq, attempt);
        nrk_wait(delay);
    } while (++attempt < discover_send_attempts);
}
Пример #28
0
	virtual void apply() {
		LOGA("STM: apply, m=%d", m);
		if (m == 1) {
			savedState = state; // save state	
		}
		else if (dataHolder.hasData) {
			if (m == 2)
				state.timeOn = dataHolder.get().time;
			if (m == 3)
				state.timeOff = dataHolder.get().time;
		}
		updateDisp();
	}
Пример #29
0
void m2_cmd(byte cmd) {
	LOGA("M2: cmd=%d", cmd);
	// process mode action first
	if (curMW->mode->cmd(cmd) == false) {
		LOG("M2: >cmd<");
		return;
	}
	// default actions: go to linked mode
	switch (cmd) {
	case 1: { // prev
		if (curMW->prev != null) {
			LOG("M2: _<");
			disp_locked = true;
			curMW = curMW->prev;
			curMW->mode->apply();
			disp_locked = false;
		}
	} break;
	case 2: { // down
		if (curMW->down != null) {
			LOG("M2: _V");
			disp_locked = true;
			curMW = curMW->down;
			curMW->mode->apply();
			disp_locked = false;
		}
	} break;
	case 3: { // up
		if (curMW->up != null) {
			LOG("M2: _^");
			disp_locked = true;
			curMW = curMW->up;
			curMW->mode->apply();
			disp_locked = false;
		}
	} break;
	case 4: { // next
		if (curMW->next != null) {
			LOG("M2: _>");
			disp_locked = true;
			curMW = curMW->next;
			curMW->mode->apply();
			disp_locked = false;
		}
	} break;
	}
}
Пример #30
0
static int8_t broadcast_request(node_id_t origin, uint8_t seq,
                                uint8_t depth, uint8_t attempt)
{ 
    LOG("broadcast req: seq "); LOGP("%u", seq);
    LOGA(" attempt "); LOGP("%u\r\n", attempt);

    init_pkt(&tx_pkt);
    tx_pkt.type = PKT_TYPE_DISCOVER_REQUEST;
    tx_pkt.dest = BROADCAST_NODE_ID;
    tx_pkt.payload[PKT_REQUEST_ORIGIN_OFFSET] = origin;
    tx_pkt.len += PKT_REQUEST_ORIGIN_LEN;
    tx_pkt.payload[PKT_REQUEST_SEQ_OFFSET] = seq;
    tx_pkt.len += PKT_REQUEST_SEQ_LEN;
    tx_pkt.payload[PKT_REQUEST_DEPTH_OFFSET] = depth;
    tx_pkt.len += PKT_REQUEST_DEPTH_LEN;
    return send_pkt(&tx_pkt, TX_FLAG_NONE, NULL);
}