Esempio n. 1
0
int rtl8139_init(rtl8139 *rtl)
{
	bigtime_t time;
	int err = -1;
	addr_t temp;

	dprintf("rtl8139_init: rtl %p\n", rtl);

	rtl->region = vm_map_physical_memory(vm_get_kernel_aspace_id(), "rtl8139_region", (void **)&rtl->virt_base,
		REGION_ADDR_ANY_ADDRESS, rtl->phys_size, LOCK_KERNEL|LOCK_RW, rtl->phys_base);
	if(rtl->region < 0) {
		dprintf("rtl8139_init: error creating memory mapped region\n");
		err = -1;
		goto err;
	}
	dprintf("rtl8139 mapped at address 0x%lx\n", rtl->virt_base);

	// try to reset the device
 	time = system_time();
	RTL_WRITE_8(rtl, RT_CHIPCMD, RT_CMD_RESET);
	do {
		thread_snooze(10000); // 10ms
		if(system_time() - time > 1000000) {
			err = -1;
			goto err1;
		}
	} while((RTL_READ_8(rtl, RT_CHIPCMD) & RT_CMD_RESET));

	// create a rx and tx buf
	rtl->rxbuf_region = vm_create_anonymous_region(vm_get_kernel_aspace_id(), "rtl8139_rxbuf", (void **)&rtl->rxbuf,
		REGION_ADDR_ANY_ADDRESS, 64*1024 + 16, REGION_WIRING_WIRED_CONTIG, LOCK_KERNEL|LOCK_RW);
	rtl->txbuf_region = vm_create_anonymous_region(vm_get_kernel_aspace_id(), "rtl8139_txbuf", (void **)&rtl->txbuf,
		REGION_ADDR_ANY_ADDRESS, 8*1024, REGION_WIRING_WIRED, LOCK_KERNEL|LOCK_RW);

	// set up the transmission buf and sem
	rtl->tx_sem = sem_create(4, "rtl8139_txsem");
	mutex_init(&rtl->lock, "rtl8139");
	rtl->txbn = 0;
	rtl->last_txbn = 0;
	rtl->rx_sem = sem_create(0, "rtl8139_rxsem");
	rtl->reg_spinlock = 0;

	// set up the interrupt handler
	int_set_io_interrupt_handler(rtl->irq, &rtl8139_int, rtl, "rtl8139");

	// read the mac address
	rtl->mac_addr[0] = RTL_READ_8(rtl, RT_IDR0);
	rtl->mac_addr[1] = RTL_READ_8(rtl, RT_IDR0 + 1);
	rtl->mac_addr[2] = RTL_READ_8(rtl, RT_IDR0 + 2);
	rtl->mac_addr[3] = RTL_READ_8(rtl, RT_IDR0 + 3);
  	rtl->mac_addr[4] = RTL_READ_8(rtl, RT_IDR0 + 4);
  	rtl->mac_addr[5] = RTL_READ_8(rtl, RT_IDR0 + 5);

  	dprintf("rtl8139: mac addr %x:%x:%x:%x:%x:%x\n",
  		rtl->mac_addr[0], rtl->mac_addr[1], rtl->mac_addr[2],
  		rtl->mac_addr[3], rtl->mac_addr[4], rtl->mac_addr[5]);

	// enable writing to the config registers
	RTL_WRITE_8(rtl, RT_CFG9346, 0xc0);

	// reset config 1
	RTL_WRITE_8(rtl, RT_CONFIG1, 0);

	// Enable receive and transmit functions
	RTL_WRITE_8(rtl, RT_CHIPCMD, RT_CMD_RX_ENABLE | RT_CMD_TX_ENABLE);

	// Set Rx FIFO threashold to 256, Rx size to 64k+16, 256 byte DMA burst
	RTL_WRITE_32(rtl, RT_RXCONFIG, 0x00009c00);

	// Set Tx 256 byte DMA burst
	RTL_WRITE_32(rtl, RT_TXCONFIG, 0x03000400);

	// Turn off lan-wake and set the driver-loaded bit
	RTL_WRITE_8(rtl, RT_CONFIG1, (RTL_READ_8(rtl, RT_CONFIG1) & ~0x30) | 0x20);

	// Enable FIFO auto-clear
	RTL_WRITE_8(rtl, RT_CONFIG4, RTL_READ_8(rtl, RT_CONFIG4) | 0x80);

	// go back to normal mode
	RTL_WRITE_8(rtl, RT_CFG9346, 0);

	// Setup RX buffers
	*(int *)rtl->rxbuf = 0;
	vm_get_page_mapping(vm_get_kernel_aspace_id(), rtl->rxbuf, &temp);
	dprintf("rx buffer will be at 0x%lx\n", temp);
	RTL_WRITE_32(rtl, RT_RXBUF, temp);

	// Setup TX buffers
	dprintf("tx buffer (virtual) is at 0x%lx\n", rtl->txbuf);
	*(int *)rtl->txbuf = 0;
	vm_get_page_mapping(vm_get_kernel_aspace_id(), rtl->txbuf, &temp);
	RTL_WRITE_32(rtl, RT_TXADDR0, temp);
	RTL_WRITE_32(rtl, RT_TXADDR1, temp + 2*1024);
	dprintf("first half of txbuf at 0x%lx\n", temp);
	*(int *)(rtl->txbuf + 4*1024) = 0;
	vm_get_page_mapping(vm_get_kernel_aspace_id(), rtl->txbuf + 4*1024, &temp);
	RTL_WRITE_32(rtl, RT_TXADDR2, temp);
	RTL_WRITE_32(rtl, RT_TXADDR3, temp + 2*1024);
	dprintf("second half of txbuf at 0x%lx\n", temp);

/*
	RTL_WRITE_32(rtl, RT_TXSTATUS0, RTL_READ_32(rtl, RT_TXSTATUS0) | 0xfffff000);
	RTL_WRITE_32(rtl, RT_TXSTATUS1, RTL_READ_32(rtl, RT_TXSTATUS1) | 0xfffff000);
	RTL_WRITE_32(rtl, RT_TXSTATUS2, RTL_READ_32(rtl, RT_TXSTATUS2) | 0xfffff000);
	RTL_WRITE_32(rtl, RT_TXSTATUS3, RTL_READ_32(rtl, RT_TXSTATUS3) | 0xfffff000);
*/
	// Reset RXMISSED counter
	RTL_WRITE_32(rtl, RT_RXMISSED, 0);

	// Enable receiving broadcast and physical match packets
//	RTL_WRITE_32(rtl, RT_RXCONFIG, RTL_READ_32(rtl, RT_RXCONFIG) | 0x0000000a);
	RTL_WRITE_32(rtl, RT_RXCONFIG, RTL_READ_32(rtl, RT_RXCONFIG) | 0x0000000f);

	// Filter out all multicast packets
	RTL_WRITE_32(rtl, RT_MAR0, 0);
	RTL_WRITE_32(rtl, RT_MAR0 + 4, 0);

	// Disable all multi-interrupts
	RTL_WRITE_16(rtl, RT_MULTIINTR, 0);

	RTL_WRITE_16(rtl, RT_INTRMASK, MYRT_INTS);
//	RTL_WRITE_16(rtl, RT_INTRMASK, 0x807f);

	// Enable RX/TX once more
	RTL_WRITE_8(rtl, RT_CHIPCMD, RT_CMD_RX_ENABLE | RT_CMD_TX_ENABLE);

	RTL_WRITE_8(rtl, RT_CFG9346, 0);

	return 0;

err1:
	vm_delete_region(vm_get_kernel_aspace_id(), rtl->region);
err:
	return err;
}
Esempio n. 2
0
 bool timed_wait(lock_type& m,xtime const& wait_until,predicate_type pred)
 {
     return timed_wait(m,system_time(wait_until),pred);
 }
Esempio n. 3
0
void
BListView::MouseDown(BPoint point)
{
	if (!IsFocus()) {
		MakeFocus();
		Sync();
		Window()->UpdateIfNeeded();
	}

	BMessage* message = Looper()->CurrentMessage();
	int32 index = IndexOf(point);

	// If the user double (or more) clicked within the current selection,
	// we don't change the selection but invoke the selection.
	// TODO: move this code someplace where it can be shared everywhere
	// instead of every class having to reimplement it, once some sane
	// API for it is decided.
	BPoint delta = point - fTrack->drag_start;
	bigtime_t sysTime;
	Window()->CurrentMessage()->FindInt64("when", &sysTime);
	bigtime_t timeDelta = sysTime - fTrack->last_click_time;
	bigtime_t doubleClickSpeed;
	get_click_speed(&doubleClickSpeed);
	bool doubleClick = false;

	if (timeDelta < doubleClickSpeed
		&& fabs(delta.x) < kDoubleClickTresh
		&& fabs(delta.y) < kDoubleClickTresh
		&& fTrack->item_index == index) {
		doubleClick = true;
	}

	if (doubleClick && index >= fFirstSelected && index <= fLastSelected) {
		fTrack->drag_start.Set(INT32_MAX, INT32_MAX);
		Invoke();
		return;
	}

	int32 modifiers;
	message->FindInt32("modifiers", &modifiers);

	if (!doubleClick) {
		fTrack->drag_start = point;
		fTrack->last_click_time = system_time();
		fTrack->item_index = index;
		fTrack->was_selected = index >= 0 ? ItemAt(index)->IsSelected() : false;
		fTrack->try_drag = true;
	}

	if (index > -1) {
		if (fListType == B_MULTIPLE_SELECTION_LIST) {
			if (modifiers & B_SHIFT_KEY) {
				// select entire block
				// TODO: maybe review if we want it like in Tracker
				// (anchor item)
				Select(min_c(index, fFirstSelected), max_c(index,
					fLastSelected));
			} else {
				if (modifiers & B_COMMAND_KEY) {
					// toggle selection state of clicked item (like in Tracker)
					// toggle selection state of clicked item
					if (ItemAt(index)->IsSelected())
						Deselect(index);
					else
						Select(index, true);
				} else
					Select(index);
			}
		} else {
			// toggle selection state of clicked item
			if ((modifiers & B_COMMAND_KEY) && ItemAt(index)->IsSelected())
				Deselect(index);
			else
				Select(index);
		}
	} else if ((modifiers & B_COMMAND_KEY) == 0)
		DeselectAll();
}
static ssize_t out_write(struct audio_stream_out *stream, const void* buffer,
                         size_t bytes)
{
    struct astream_out *out = (struct astream_out *)stream;
    int ret;
    size_t frames_total = bytes / sizeof(uint32_t); // always stereo 16 bit
    uint32_t *buf = (uint32_t *)buffer;
    size_t frames_written = 0;

    pthread_mutex_lock(&out->buf_lock);
    pthread_mutex_lock(&out->lock);
    if (!out->bt_enabled || out->suspended) {
        LOGV("a2dp write: bluetooth disabled bt_en %d, suspended %d",
             out->bt_enabled, out->suspended);
        ret = -1;
        goto err_bt_disabled;
    }

    if (out->standby) {
        acquire_wake_lock(PARTIAL_WAKE_LOCK, A2DP_WAKE_LOCK_NAME);
        out->standby = false;
        out->last_write_time = system_time();
        out->buf_rd_idx = 0;
        out->buf_wr_idx = 0;
        out->buf_frames_ready = 0;
    }

    ret = _out_init_locked(out, NULL);
    if (ret < 0) {
        goto err_init;
    }

    pthread_mutex_unlock(&out->lock);

    if(isToMono){
        int16_t mono;
        int16_t *stereoData = (int16_t *)buffer;
        uint16_t i;
        for(i = 0; i<bytes/4; i++) {
            // to Mono
            mono = (int16_t)(((int32_t)*(stereoData+2*i) + (int32_t)*(stereoData+2*i+1)) >> 1);
            // to Stereo again
            *(stereoData+2*i) = *(stereoData+2*i+1) = mono;
        }
    }

    while (frames_written < frames_total) {
        size_t frames = _out_frames_available_locked(out);
        if (frames == 0) {
            int ret = pthread_cond_timeout_np(&out->buf_cond,
                                              &out->buf_lock,
                                              BUF_WRITE_AVAILABILITY_TIMEOUT_MS);
            if (ret != 0) {
                pthread_mutex_lock(&out->lock);
                goto err_write;
            }
            frames  = _out_frames_available_locked(out);
        }
        if (frames > frames_total - frames_written) {
            frames = frames_total - frames_written;
        }
        memcpy(out->buf + out->buf_wr_idx, buf + frames_written, frames * sizeof(uint32_t));
        frames_written += frames;
        _out_inc_wr_idx_locked(out, frames);
        pthread_mutex_lock(&out->lock);
        if (out->standby) {
            goto err_write;
        }
        pthread_mutex_unlock(&out->lock);
    }
    pthread_mutex_unlock(&out->buf_lock);

    return bytes;

/* out->lock must be locked and out->buf_lock unlocked when jumping here */
err_write:
err_init:
err_bt_disabled:
    pthread_mutex_unlock(&out->buf_lock);
    LOGV("!!!! write error");
    out_standby_stream_locked(out);
    pthread_mutex_unlock(&out->lock);

    /* XXX: simulate audio output timing in case of error?!?! */
    usleep(out->buffer_duration_us);
    return ret;
}
Esempio n. 5
0
 bool timed_lock(boost::xtime const & absolute_time)
 {
     return timed_lock(system_time(absolute_time));
 }
Esempio n. 6
0
		void Timer::reset () {
			this->_last = system_time();
			this->_total = 0.0;
		}
Esempio n. 7
0
void
BListView::MouseDown(BPoint where)
{
    if (!IsFocus()) {
        MakeFocus();
        Sync();
        Window()->UpdateIfNeeded();
    }

    BMessage* message = Looper()->CurrentMessage();
    int32 index = IndexOf(where);

    int32 buttons = 0;
    if (message != NULL)
        message->FindInt32("buttons", &buttons);

    int32 modifiers = 0;
    if (message != NULL)
        message->FindInt32("modifiers", &modifiers);

    // If the user double (or more) clicked within the current selection,
    // we don't change the selection but invoke the selection.
    // TODO: move this code someplace where it can be shared everywhere
    // instead of every class having to reimplement it, once some sane
    // API for it is decided.
    BPoint delta = where - fTrack->drag_start;
    bigtime_t sysTime;
    Window()->CurrentMessage()->FindInt64("when", &sysTime);
    bigtime_t timeDelta = sysTime - fTrack->last_click_time;
    bigtime_t doubleClickSpeed;
    get_click_speed(&doubleClickSpeed);
    bool doubleClick = false;

    if (timeDelta < doubleClickSpeed
            && fabs(delta.x) < kDoubleClickThreshold
            && fabs(delta.y) < kDoubleClickThreshold
            && fTrack->item_index == index) {
        doubleClick = true;
    }

    if (doubleClick && index >= fFirstSelected && index <= fLastSelected) {
        fTrack->drag_start.Set(INT32_MAX, INT32_MAX);
        Invoke();
        return BView::MouseDown(where);
    }

    if (!doubleClick) {
        fTrack->drag_start = where;
        fTrack->last_click_time = system_time();
        fTrack->item_index = index;
        fTrack->was_selected = index >= 0 ? ItemAt(index)->IsSelected() : false;
        fTrack->try_drag = true;

        MouseDownThread<BListView>::TrackMouse(this,
                                               &BListView::_DoneTracking, &BListView::_Track);
    }

    if (index >= 0) {
        if (fListType == B_MULTIPLE_SELECTION_LIST) {
            if ((modifiers & B_SHIFT_KEY) != 0) {
                // select entire block
                // TODO: maybe review if we want it like in Tracker
                // (anchor item)
                if (index >= fFirstSelected && index < fLastSelected) {
                    // clicked inside of selected items block, deselect all
                    // but from the first selected item to the clicked item
                    DeselectExcept(fFirstSelected, index);
                } else {
                    Select(std::min(index, fFirstSelected), std::max(index,
                            fLastSelected));
                }
            } else {
                if ((modifiers & B_COMMAND_KEY) != 0) {
                    // toggle selection state of clicked item (like in Tracker)
                    // toggle selection state of clicked item
                    if (ItemAt(index)->IsSelected())
                        Deselect(index);
                    else
                        Select(index, true);
                } else
                    Select(index);
            }
        } else {
            // toggle selection state of clicked item
            if ((modifiers & B_COMMAND_KEY) != 0 && ItemAt(index)->IsSelected())
                Deselect(index);
            else
                Select(index);
        }
    } else if ((modifiers & B_COMMAND_KEY) == 0)
        DeselectAll();

    BView::MouseDown(where);
}
Esempio n. 8
0
Uint32 SDL_GetTicks(void)
{
	return((system_time()-start)/1000);
}
Esempio n. 9
0
JNIEXPORT jlong JNICALL Fake_TrueCurrentTimeMillis(JNIEnv* env, jclass jc) {
	return system_time();
}
Esempio n. 10
0
void MediaRoutingView::MessageReceived(
	BMessage* message)
{
	D_METHOD(("MediaRoutingView::MessageReceived()\n"));

	switch (message->what)
	{
		case B_MEDIA_NODE_CREATED:
		{
			D_MESSAGE(("MediaRoutingView::MessageReceived(B_MEDIA_NODE_CREATED)\n"));
			type_code type;
			int32 count;
			if (message->GetInfo("media_node_id", &type, &count) == B_OK)
			{
				for(int32 n = 0; n < count; n++) 
				{
					int32 id;
					if (message->FindInt32("media_node_id", n, &id) == B_OK)
					{
						// [e.moon 8dec99] allow for existing panel
						MediaNodePanel* panel;
						if(_findPanelFor(id, &panel) < B_OK)
							_addPanelFor(id, BPoint(5.0, 5.0));
					}
				}
			}
			break;
		}
		case B_MEDIA_NODE_DELETED:
		{
			D_MESSAGE(("MediaRoutingView::MessageReceived(B_MEDIA_NODE_DELETED)\n"));
			type_code type;
			int32 count;
			if (message->GetInfo("media_node_id", &type, &count) == B_OK)
			{
				for (int32 n = 0; n < count; n++) 
				{
					int32 id;
					if (message->FindInt32("media_node_id", n, &id) == B_OK)
					{
						_removePanelFor(id);
					}
				}
			}			
			break;
		}
		case B_MEDIA_CONNECTION_MADE:
		{
			D_MESSAGE(("MediaRoutingView::MessageReceived(B_MEDIA_CONNECTION_MADE)\n"));
			type_code type;
			int32 count;
			if (message->GetInfo("output", &type, &count) == B_OK)
			{
				for (int32 n = 0; n < count; n++)
				{
					media_output output;
					const void *data;
					ssize_t dataSize;
					if (message->FindData("output", B_RAW_TYPE, n, &data, &dataSize) == B_OK)
					{
						output = *reinterpret_cast<const media_output *>(data);
						Connection connection;
						if (manager->findConnection(output.node.node, output.source, &connection) == B_OK)
						{
							_addWireFor(connection);
						}
					}
				}
			}
			break;
		}
		case B_MEDIA_CONNECTION_BROKEN:
		{
			D_MESSAGE(("MediaRoutingView::MessageReceived(B_MEDIA_CONNECTION_BROKEN)\n"));
			type_code type;
			int32 count;
			if (message->GetInfo("__connection_id", &type, &count) == B_OK)
			{
				for (int32 n = 0; n < count; n++)
				{
					int32 id;
					if (message->FindInt32("__connection_id", n, &id) == B_OK)
					{
						_removeWireFor(id);
					}	
				}
			}
			break;
		}
		case B_MEDIA_FORMAT_CHANGED:
		{
			D_MESSAGE(("MediaRoutingView::MessageReceived(B_MEDIA_FORMAT_CHANGED)\n"));
			
			media_node_id nodeID;
			if(message->FindInt32("__source_node_id", &nodeID) < B_OK)
				break;

			uint32 connectionID;
			if(message->FindInt32("__connection_id", (int32*)&connectionID) < B_OK)
				break;

			media_source* source;
			ssize_t dataSize;
			if(message->FindData("be:source", B_RAW_TYPE, (const void**)&source, &dataSize) < B_OK)
				break;
				
			MediaWire* wire;
			if(_findWireFor(connectionID, &wire) == B_OK) {
				// copy new connection data
				manager->findConnection(nodeID, *source, &wire->connection);
			}
			break;
		}
		case M_CLEANUP_REQUESTED:
		{
			D_MESSAGE(("MediaRoutingView::MessageReceived(M_M_CLEANUP_REQUESTED)\n"));
			cleanUp();
			break;
		}
		case M_SELECT_ALL:
		{
			D_MESSAGE(("MediaRoutingView::MessageReceived(M_SELECT_ALL)\n"));
			selectAll(DiagramItem::M_BOX);
			break;
		}
		case M_DELETE_SELECTION:
		{
			D_MESSAGE(("MediaRoutingView::MessageReceived(M_DELETE_SELECTION)\n"));
			_deleteSelection();
			break;
		}
		case M_NODE_CHANGE_CYCLING:
		{
			D_MESSAGE(("MediaRoutingView::MessageReceived(M_NODE_CYCLING_CHANGED)\n"));
			bool cycle;
			if (message->FindBool("cycle", &cycle) == B_OK)
			{
				_changeCyclingForSelection(cycle);
			}
			break;
		}
		case M_NODE_CHANGE_RUN_MODE:
		{
			D_MESSAGE(("MediaRoutingView::MessageReceived(M_NODE_RUNMODE_CHANGED)\n"));
			int32 mode;
			if (message->FindInt32("run_mode", &mode) == B_OK)
			{
				_changeRunModeForSelection(static_cast<uint32>(mode));
			}
			break;
		}
		case M_LAYOUT_CHANGED:
		{
			D_MESSAGE(("MediaRoutingView::MessageReceived(M_LAYOUT_CHANGED)\n"));
			layout_t layout;
			if (message->FindInt32("layout", (int32*)&layout) == B_OK)
			{
				if (layout != m_layout)
				{
					layoutChanged(layout);
					updateDataRect();
					Invalidate();
				}
			}
			break;
		}
		case M_NODE_START_TIME_SOURCE:
		{
			D_MESSAGE(("MediaRoutingView::MessageReceived(M_NODE_START_TIME_SOURCE)\n"));
			int32 id;
			if(message->FindInt32("nodeID", &id) < B_OK)
				break;
			NodeRef* ref;
			if(manager->getNodeRef(id, &ref) < B_OK)
				break;
			
			bigtime_t when = system_time();
			status_t err = manager->roster->StartTimeSource(ref->node(), when);
			if(err < B_OK) {
				PRINT((
					"! StartTimeSource(%ld): '%s'\n",
					ref->id(), strerror(err)));
			}
			break;
		}
		case M_NODE_STOP_TIME_SOURCE:
		{
			D_MESSAGE(("MediaRoutingView::MessageReceived(M_NODE_STOP_TIME_SOURCE)\n"));
			int32 id;
			if(message->FindInt32("nodeID", &id) < B_OK)
				break;
			NodeRef* ref;
			if(manager->getNodeRef(id, &ref) < B_OK)
				break;
			
			bigtime_t when = system_time();
			status_t err = manager->roster->StopTimeSource(ref->node(), when);
			if(err < B_OK) {
				PRINT((
					"! StopTimeSource(%ld): '%s'\n",
					ref->id(), strerror(err)));
			}
			break;
		}
		case M_NODE_TWEAK_PARAMETERS: {
			D_MESSAGE((" -> M_NODE_TWEAK_PARAMETERS\n"));
			_openParameterWindowsForSelection();
			break;
		}
		case M_NODE_START_CONTROL_PANEL: {
			D_MESSAGE((" -> M_NODE_START_CONTROL_PANEL\n"));
			_startControlPanelsForSelection();
			break;
		}
		case M_GROUP_SET_LOCKED:
		{
			D_MESSAGE(("MediaRoutingView::MessageReceived(M_GROUP_SET_LOCKED)\n"));
			int32 groupID;
			if(message->FindInt32("groupID", &groupID) < B_OK)
				break;
			bool locked;
			if(message->FindBool("locked", &locked) < B_OK)
				break;
			NodeGroup* group;
			if(manager->findGroup(groupID, &group) < B_OK)
				break;
			uint32 f = locked ?
				group->groupFlags() | NodeGroup::GROUP_LOCKED :
				group->groupFlags() & ~NodeGroup::GROUP_LOCKED;
			group->setGroupFlags(f);
			break;
		}
		case M_BROADCAST_SELECTION: {
			D_MESSAGE((" -> M_BROADCAST_SELECTION\n"));
			_broadcastSelection();
			break;
		}
		case InfoWindowManager::M_INFO_WINDOW_REQUESTED:
		{
			D_MESSAGE(("MediaRoutingView::MessageReceived(InfoView::M_INFO_WINDOW_REQUESTED)\n"));
			type_code type;
			int32 count;
			if (message->GetInfo("input", &type, &count) == B_OK)
			{
				for (int32 i = 0; i < count; i++)
				{
					media_input input;
					const void *data;
					ssize_t dataSize;
					if (message->FindData("input", B_RAW_TYPE, i, &data, &dataSize) == B_OK)
					{
						input = *reinterpret_cast<const media_input *>(data);
						InfoWindowManager *manager = InfoWindowManager::Instance();
						if (manager && manager->Lock()) {
							manager->openWindowFor(input);
							manager->Unlock();
						}
					}
				}
			}
			else if (message->GetInfo("output", &type, &count) == B_OK)
			{
				for (int32 i = 0; i < count; i++)
				{
					media_output output;
					const void *data;
					ssize_t dataSize;
					if (message->FindData("output", B_RAW_TYPE, i, &data, &dataSize) == B_OK)
					{
						output = *reinterpret_cast<const media_output *>(data);
						InfoWindowManager *manager = InfoWindowManager::Instance();
						if (manager && manager->Lock()) {
							manager->openWindowFor(output);
							manager->Unlock();
						}
					}
				}
			}
			else
			{
				_openInfoWindowsForSelection();
			}
			break;
		}
		case NodeManager::M_RELEASED:
		{
			D_MESSAGE(("MediaRoutingView::MessageReceived(NodeManager::M_RELEASED)\n"));
			remove_observer(this, manager);
			const_cast<RouteAppNodeManager*&>(manager) = 0;	
			// +++++ disable view!
			break;
		}			
		case NodeRef::M_RELEASED:
		{
			D_MESSAGE(("MediaRoutingView::MessageReceived(NodeRef::M_RELEASED)\n"));
			// only relevant on shutdown; do nothing
			break;
		}
		default:
		{
			DiagramView::MessageReceived(message);
		}
	}
}
Esempio n. 11
0
void SDL_StartTicks(void)
{
	/* Set first ticks value */
	start = system_time();
}
 bool timed_wait(unique_lock<mutex>& m,xtime const& wait_until,predicate_type pred)
 {
     return timed_wait(m,system_time(wait_until),pred);
 }
 bool timed_wait(unique_lock<mutex>& m,xtime const& wait_until)
 {
     return timed_wait(m,system_time(wait_until));
 }
Esempio n. 14
0
void
MainWin::MouseDown(BMessage *msg)
{
	BPoint screen_where;
	uint32 buttons = msg->FindInt32("buttons");

	// On Zeta, only "screen_where" is relyable, "where" and "be:view_where"
	// seem to be broken
	if (B_OK != msg->FindPoint("screen_where", &screen_where)) {
		// Workaround for BeOS R5, it has no "screen_where"
		fVideoView->GetMouse(&screen_where, &buttons, false);
		fVideoView->ConvertToScreen(&screen_where);
	}

//	msg->PrintToStream();

//	if (1 == msg->FindInt32("buttons") && msg->FindInt32("clicks") == 1) {

	if (1 == buttons && msg->FindInt32("clicks") % 2 == 0) {
		BRect r(screen_where.x - 1, screen_where.y - 1, screen_where.x + 1,
			screen_where.y + 1);
		if (r.Contains(fMouseDownMousePos)) {
			PostMessage(M_TOGGLE_FULLSCREEN);
			return;
		}
	}

	if (2 == buttons && msg->FindInt32("clicks") % 2 == 0) {
		BRect r(screen_where.x - 1, screen_where.y - 1, screen_where.x + 1,
			screen_where.y + 1);
		if (r.Contains(fMouseDownMousePos)) {
			PostMessage(M_TOGGLE_NO_BORDER_NO_MENU);
			return;
		}
	}

/*
		// very broken in Zeta:
		fMouseDownMousePos = fVideoView->ConvertToScreen(
			msg->FindPoint("where"));
*/
	fMouseDownMousePos = screen_where;
	fMouseDownWindowPos = Frame().LeftTop();

	if (buttons == 1 && !fIsFullscreen) {
		// start mouse tracking
		fVideoView->SetMouseEventMask(B_POINTER_EVENTS | B_NO_POINTER_HISTORY
			/* | B_LOCK_WINDOW_FOCUS */);
		fMouseDownTracking = true;
	}

	// pop up a context menu if right mouse button is down for 200 ms

	if ((buttons & 2) == 0)
		return;
	bigtime_t start = system_time();
	bigtime_t delay = 200000;
	BPoint location;
	do {
		fVideoView->GetMouse(&location, &buttons);
		if ((buttons & 2) == 0)
			break;
		snooze(1000);
	} while (system_time() - start < delay);

	if (buttons & 2)
		ShowContextMenu(screen_where);
}
Esempio n. 15
0
static int32
keyboard_handle_int(ps2_dev *dev)
{
	enum emergency_keys {
		EMERGENCY_LEFT_ALT	= 0x01,
		EMERGENCY_RIGHT_ALT	= 0x02,
		EMERGENCY_SYS_REQ	= 0x04,
	};
	static int emergencyKeyStatus = 0;
	at_kbd_io keyInfo;
	uint8 scancode = dev->history[0].data;

	if (atomic_and(&sKeyboardOpenMask, 1) == 0)
		return B_HANDLED_INTERRUPT;

	// TODO: Handle braindead "pause" key special case

	if (scancode == EXTENDED_KEY) {
		sIsExtended = true;
//		TRACE("Extended key\n");
		return B_HANDLED_INTERRUPT;
	}

//	TRACE("scancode: %x\n", scancode);

	if ((scancode & 0x80) != 0) {
		keyInfo.is_keydown = false;
		scancode &= 0x7f;
	} else
		keyInfo.is_keydown = true;

	if (sIsExtended) {
		scancode |= 0x80;
		sIsExtended = false;
	}

	// Handle emergency keys
	if (scancode == LEFT_ALT_KEY || scancode == RIGHT_ALT_KEY) {
		// left or right alt-key pressed
		if (keyInfo.is_keydown) {
			emergencyKeyStatus |= scancode == LEFT_ALT_KEY
				? EMERGENCY_LEFT_ALT : EMERGENCY_RIGHT_ALT;
		} else {
			emergencyKeyStatus &= ~(scancode == LEFT_ALT_KEY
				? EMERGENCY_LEFT_ALT : EMERGENCY_RIGHT_ALT);
		}
	} else if (scancode == SYS_REQ_KEY) {
		if (keyInfo.is_keydown)
			emergencyKeyStatus |= EMERGENCY_SYS_REQ;
		else
			emergencyKeyStatus &= EMERGENCY_SYS_REQ;
	} else if (emergencyKeyStatus > EMERGENCY_SYS_REQ
		&& debug_emergency_key_pressed(kUnshiftedKeymap[scancode])) {
		static const int kKeys[] = {LEFT_ALT_KEY, RIGHT_ALT_KEY, SYS_REQ_KEY};
		int i;

		// we probably have lost some keys, so reset our key states
		emergencyKeyStatus = 0;

		// send key ups for alt-sysreq
		keyInfo.timestamp = system_time();
		keyInfo.is_keydown = false;
		for (i = 0; i < sizeof(kKeys) / sizeof(kKeys[0]); i++) {
			keyInfo.scancode = kKeys[i];
			if (packet_buffer_write(sKeyBuffer, (uint8 *)&keyInfo,
					sizeof(keyInfo)) != 0)
				release_sem_etc(sKeyboardSem, 1, B_DO_NOT_RESCHEDULE);
		}

		return B_HANDLED_INTERRUPT;
	}

	keyInfo.timestamp = dev->history[0].time;
	keyInfo.scancode = scancode;

	if (packet_buffer_write(sKeyBuffer, (uint8 *)&keyInfo,
			sizeof(keyInfo)) == 0) {
		// If there is no space left in the buffer, we drop this key stroke. We
		// avoid dropping old key strokes, to not destroy what already was
		// typed.
		return B_HANDLED_INTERRUPT;
	}

	release_sem_etc(sKeyboardSem, 1, B_DO_NOT_RESCHEDULE);

	return B_INVOKE_SCHEDULER;
}
Esempio n. 16
0
static status_t
callout_thread(void* /*data*/)
{
	status_t status = B_OK;

	do {
		bigtime_t timeout = B_INFINITE_TIMEOUT;

		if (status == B_TIMED_OUT || status == B_OK) {
			// scan timers for new timeout and/or execute a timer
			mutex_lock(&sLock);

			while (true) {
				struct callout* c = (callout*)list_get_next_item(&sTimers, c);
				if (c == NULL)
					break;

				if (c->due < system_time()) {
					struct mtx *mutex = c->c_mtx;

					// execute timer
					list_remove_item(&sTimers, c);
					c->due = -1;
					sCurrentCallout = c;

					mutex_unlock(&sLock);

					if (mutex != NULL)
						mtx_lock(mutex);
				
					c->c_func(c->c_arg);
				
					if (mutex != NULL)
						mtx_unlock(mutex);

					mutex_lock(&sLock);

					sCurrentCallout = NULL;
					c = NULL;
						// restart scanning as we unlocked the list
				} else {
					// calculate new timeout
					if (c->due < timeout)
						timeout = c->due;
				}
			}

			sTimeout = timeout;
			mutex_unlock(&sLock);
		}

		status = acquire_sem_etc(sWaitSem, 1, B_ABSOLUTE_TIMEOUT, timeout);
			// the wait sem normally can't be acquired, so we
			// have to look at the status value the call returns:
			//
			// B_OK - a new timer has been added or canceled
			// B_TIMED_OUT - look for timers to be executed
			// B_BAD_SEM_ID - we are asked to quit
	} while (status != B_BAD_SEM_ID);

	return B_OK;
}
Esempio n. 17
0
static status_t
ext2_create(fs_volume* _volume, fs_vnode* _directory, const char* name,
	int openMode, int mode, void** _cookie, ino_t* _vnodeID)
{
	Volume* volume = (Volume*)_volume->private_volume;
	Inode* directory = (Inode*)_directory->private_node;

	TRACE("ext2_create()\n");

	if (volume->IsReadOnly())
		return B_READ_ONLY_DEVICE;

	if (!directory->IsDirectory())
		return B_BAD_TYPE;

	TRACE("ext2_create(): Creating cookie\n");

	// Allocate cookie
	file_cookie* cookie = new(std::nothrow) file_cookie;
	if (cookie == NULL)
		return B_NO_MEMORY;
	ObjectDeleter<file_cookie> cookieDeleter(cookie);

	cookie->open_mode = openMode;
	cookie->last_size = 0;
	cookie->last_notification = system_time();

	TRACE("ext2_create(): Starting transaction\n");

	Transaction transaction(volume->GetJournal());

	TRACE("ext2_create(): Creating inode\n");

	Inode* inode;
	bool created;
	status_t status = Inode::Create(transaction, directory, name,
		S_FILE | (mode & S_IUMSK), openMode, EXT2_TYPE_FILE, &created, _vnodeID,
		&inode, &gExt2VnodeOps);
	if (status != B_OK)
		return status;

	TRACE("ext2_create(): Created inode\n");

	if ((openMode & O_NOCACHE) != 0) {
		status = inode->DisableFileCache();
		if (status != B_OK)
			return status;
	}

	entry_cache_add(volume->ID(), directory->ID(), name, *_vnodeID);

	status = transaction.Done();
	if (status != B_OK) {
		entry_cache_remove(volume->ID(), directory->ID(), name);
		return status;
	}

	*_cookie = cookie;
	cookieDeleter.Detach();

	if (created)
		notify_entry_created(volume->ID(), directory->ID(), name, *_vnodeID);

	return B_OK;
}
Esempio n. 18
0
status_t
SeekSlider::Invoke(BMessage* message)
{
	fLastTrackTime = system_time();
	return BSlider::Invoke(message);
}
Esempio n. 19
0
		TimeT Timer::time () const {
			TimeT current = system_time();
			this->_total += current - this->_last;
			this->_last = current;
			return this->_total;
		}
Esempio n. 20
0
AboutView::AboutView()
	: BView("aboutview", B_WILL_DRAW | B_PULSE_NEEDED),
	fLastActionTime(system_time()),
	fScrollRunner(NULL)
{
	// Begin Construction of System Information controls

	system_info systemInfo;
	get_system_info(&systemInfo);

	// Create all the various labels for system infomation

	// OS Version

	char string[1024];
	strlcpy(string, B_TRANSLATE("Unknown"), sizeof(string));

	// the version is stored in the BEOS:APP_VERSION attribute of libbe.so
	BPath path;
	if (find_directory(B_BEOS_LIB_DIRECTORY, &path) == B_OK) {
		path.Append("libbe.so");

		BAppFileInfo appFileInfo;
		version_info versionInfo;
		BFile file;
		if (file.SetTo(path.Path(), B_READ_ONLY) == B_OK
			&& appFileInfo.SetTo(&file) == B_OK
			&& appFileInfo.GetVersionInfo(&versionInfo,
				B_APP_VERSION_KIND) == B_OK
			&& versionInfo.short_info[0] != '\0')
			strlcpy(string, versionInfo.short_info, sizeof(string));
	}

	// Add system revision
	const char* haikuRevision = __get_haiku_revision();
	if (haikuRevision != NULL) {
		strlcat(string, " (", sizeof(string));
		strlcat(string, B_TRANSLATE("Revision"), sizeof(string));
		strlcat(string, " ", sizeof(string));
		strlcat(string, haikuRevision, sizeof(string));
		strlcat(string, ")", sizeof(string));
	}

	BStringView* versionView = new BStringView("ostext", string);
	versionView->SetExplicitAlignment(BAlignment(B_ALIGN_LEFT,
		B_ALIGN_VERTICAL_UNSET));

	// GCC version
	BEntry gccFourHybrid("/boot/system/lib/gcc2/libstdc++.r4.so");
	BEntry gccTwoHybrid("/boot/system/lib/gcc4/libsupc++.so");
	bool isHybrid = gccFourHybrid.Exists() || gccTwoHybrid.Exists();

	if (isHybrid) {
		snprintf(string, sizeof(string), B_TRANSLATE("GCC %d Hybrid"),
			__GNUC__);
	} else
		snprintf(string, sizeof(string), "GCC %d", __GNUC__);

	BStringView* gccView = new BStringView("gcctext", string);
	gccView->SetExplicitAlignment(BAlignment(B_ALIGN_LEFT,
		B_ALIGN_VERTICAL_UNSET));

#if __GNUC__ == 2
	if (isHybrid) {
		// do now show the GCC version if it's the default
		gccView->Hide();
	}
#endif

	// CPU count, type and clock speed
	char processorLabel[256];
	if (systemInfo.cpu_count > 1) {
		snprintf(processorLabel, sizeof(processorLabel),
			B_TRANSLATE("%ld Processors:"), systemInfo.cpu_count);
	} else
		strlcpy(processorLabel, B_TRANSLATE("Processor:"),
			sizeof(processorLabel));

	BString cpuType;
	cpuType << get_cpu_vendor_string(systemInfo.cpu_type)
		<< " " << get_cpu_model_string(&systemInfo);

	BStringView* cpuView = new BStringView("cputext", cpuType.String());
	cpuView->SetExplicitAlignment(BAlignment(B_ALIGN_LEFT,
		B_ALIGN_VERTICAL_UNSET));

	int32 clockSpeed = get_rounded_cpu_speed();
	if (clockSpeed < 1000)
		snprintf(string, sizeof(string), B_TRANSLATE("%ld MHz"), clockSpeed);
	else
		snprintf(string, sizeof(string), B_TRANSLATE("%.2f GHz"),
			clockSpeed / 1000.0f);

	BStringView* frequencyView = new BStringView("frequencytext", string);
	frequencyView->SetExplicitAlignment(BAlignment(B_ALIGN_LEFT,
		B_ALIGN_VERTICAL_UNSET));

	// RAM
	BStringView *memSizeView = new BStringView("ramsizetext",
		MemSizeToString(string, sizeof(string), &systemInfo));
	memSizeView->SetExplicitAlignment(BAlignment(B_ALIGN_LEFT,
		B_ALIGN_VERTICAL_UNSET));
	fMemView = new BStringView("ramtext",
		MemUsageToString(string, sizeof(string), &systemInfo));
	fMemView->SetExplicitAlignment(BAlignment(B_ALIGN_LEFT,
		B_ALIGN_VERTICAL_UNSET));

	// Kernel build time/date
	snprintf(string, sizeof(string), "%s %s",
		systemInfo.kernel_build_date, systemInfo.kernel_build_time);

	BStringView* kernelView = new BStringView("kerneltext", string);
	kernelView->SetExplicitAlignment(BAlignment(B_ALIGN_LEFT,
		B_ALIGN_VERTICAL_UNSET));

	// Uptime
	fUptimeView = new BTextView("uptimetext");
	fUptimeView->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
	fUptimeView->MakeEditable(false);
	fUptimeView->MakeSelectable(false);
	fUptimeView->SetWordWrap(true);

	fUptimeView->SetText(UptimeToString(string, sizeof(string)));

	const float offset = 5;

	SetLayout(new BGroupLayout(B_HORIZONTAL, 0));
	SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));

	BLayoutBuilder::Group<>((BGroupLayout*)GetLayout())
		.AddGroup(B_VERTICAL, 0)
			.Add(new LogoView())
			.AddGroup(B_VERTICAL, 0)
				.Add(_CreateLabel("oslabel", B_TRANSLATE("Version:")))
				.Add(versionView)
				.Add(gccView)
				.AddStrut(offset)
				.Add(_CreateLabel("cpulabel", processorLabel))
				.Add(cpuView)
				.Add(frequencyView)
				.AddStrut(offset)
				.Add(_CreateLabel("memlabel", B_TRANSLATE("Memory:")))
				.Add(memSizeView)
				.Add(fMemView)
				.AddStrut(offset)
				.Add(_CreateLabel("kernellabel", B_TRANSLATE("Kernel:")))
				.Add(kernelView)
				.AddStrut(offset)
				.Add(_CreateLabel("uptimelabel",
					B_TRANSLATE("Time running:")))
				.Add(fUptimeView)
				.SetInsets(5, 5, 5, 5)
			.End()
			// TODO: investigate: adding this causes the time to be cut
			//.AddGlue()
		.End()
		.Add(_CreateCreditsView());

	float min = fMemView->MinSize().width * 1.1f;
	fCreditsView->SetExplicitMinSize(BSize(min, min));
}
Esempio n. 21
0
		bool IsActive() const { return fActiveUntil >= system_time(); }
Esempio n. 22
0
status_t
FormatManager::MakeFormatFor(const media_format_description* descriptions,
	int32 descriptionCount, media_format& format, uint32 flags, void* _reserved)
{
	BAutolock locker(fLock);

	int codec = fNextCodecID;
	switch (format.type) {
		case B_MEDIA_RAW_AUDIO:
		case B_MEDIA_RAW_VIDEO:
			// no marker
			break;
		case B_MEDIA_ENCODED_AUDIO:
			if (format.u.encoded_audio.encoding == 0) {
				format.u.encoded_audio.encoding
					= (media_encoded_audio_format::audio_encoding)
						fNextCodecID++;
			} else {
				UNIMPLEMENTED();
				// TODO: Check the encoding and the format passed in for
				// compatibility and return B_MISMATCHED_VALUES if incompatible
				// or perhaps something else based on flags?
			}
			break;
		case B_MEDIA_ENCODED_VIDEO:
			if (format.u.encoded_video.encoding == 0) {
				format.u.encoded_video.encoding
					= (media_encoded_video_format::video_encoding)
						fNextCodecID++;
			} else {
				UNIMPLEMENTED();
				// TODO: Check the encoding and the format passed in for
				// compatibility and return B_MISMATCHED_VALUES if incompatible
				// or perhaps something else based on flags?
			}
			break;
		case B_MEDIA_MULTISTREAM:
			if (format.u.multistream.format == 0) {
				format.u.multistream.format = fNextCodecID++;
			} else {
				UNIMPLEMENTED();
				// TODO: Check the encoding and the format passed in for
				// compatibility and return B_MISMATCHED_VALUES if incompatible
				// or perhaps something else based on flags?
			}
			break;
		default:
			// nothing to do
			return B_OK;
	}
	fLastUpdate = system_time();

	status_t result = B_OK;
	// TODO: Support "flags" (B_SET_DEFAULT, B_EXCLUSIVE, B_NO_MERGE)!
	for (int32 i = 0; i < descriptionCount; i++) {
		meta_format* metaFormat = new(std::nothrow) meta_format(
			descriptions[i], format, codec);
		if (metaFormat == NULL
			|| !fList.BinaryInsert(metaFormat, meta_format::Compare)) {
			delete metaFormat;
			result = B_NO_MEMORY;
			break;
		}
	}

	return B_OK;
}
static void *_out_buf_thread_func(void *context)
{
    struct astream_out *out = (struct astream_out *)context;

    pthread_mutex_lock(&out->buf_lock);

    while(!out->buf_thread_exit) {
        size_t frames;

        frames = _out_frames_ready_locked(out);
        while (frames && !out->buf_thread_exit) {
            int retries = MAX_WRITE_RETRIES;
            uint64_t now;
            uint32_t elapsed_us;

            while (frames > 0 && !out->buf_thread_exit) {
                int ret;
                uint32_t buffer_duration_us;
                /* PCM format is always 16bit stereo */
                size_t bytes = frames * sizeof(uint32_t);
                if (bytes > out->buffer_size) {
                    bytes = out->buffer_size;
                }

                pthread_mutex_lock(&out->lock);
                if (out->standby) {
                    /* abort and clear all pending frames if standby requested */
                    pthread_mutex_unlock(&out->lock);
                    frames = _out_frames_ready_locked(out);
                    _out_inc_rd_idx_locked(out, frames);
                    goto wait;
                }
                /* indicate to out_standby_stream_locked() that a2dp_write() is active */
                out->write_busy = true;
                pthread_mutex_unlock(&out->lock);
                pthread_mutex_unlock(&out->buf_lock);

                ret = a2dp_write(out->data, out->buf + out->buf_rd_idx, bytes);

                /* clear write_busy condition */
                pthread_mutex_lock(&out->buf_lock);
                pthread_mutex_lock(&out->lock);
                out->write_busy = false;
                pthread_cond_signal(&out->write_cond);
                pthread_mutex_unlock(&out->lock);

                if (ret < 0) {
                    LOGE("%s: a2dp_write failed (%d)\n", __func__, ret);
                    /* skip pending frames in case of write error */
                    _out_inc_rd_idx_locked(out, frames);
                    break;
                } else if (ret == 0) {
                    if (retries-- == 0) {
                        /* skip pending frames in case of multiple time out */
                        _out_inc_rd_idx_locked(out, frames);
                        break;
                    }
                    continue;
                }
                ret /= sizeof(uint32_t);
                _out_inc_rd_idx_locked(out, ret);
                frames -= ret;

                /* XXX: PLEASE FIX ME!!!! */

                /* if A2DP sink runs abnormally fast, sleep a little so that
                 * audioflinger mixer thread does no spin and starve other threads. */
                /* NOTE: It is likely that the A2DP headset is being disconnected */
                now = system_time();
                elapsed_us = (now - out->last_write_time) / 1000UL;
                buffer_duration_us = ((ret * 1000) / out->sample_rate) * 1000;

                if (elapsed_us < (buffer_duration_us / 4)) {
                    LOGV("A2DP sink runs too fast");
                    usleep(buffer_duration_us - elapsed_us);
                }
                out->last_write_time = now;

            }
            frames = _out_frames_ready_locked(out);
        }
wait:
        if (!out->buf_thread_exit) {
            pthread_cond_wait(&out->buf_cond, &out->buf_lock);
        }
    }
    pthread_mutex_unlock(&out->buf_lock);
    return NULL;
}
Esempio n. 24
0
void SnowView::Calc()
{
	int i;
	uint32 cw = fCurrentWorkspace;

	/* check if the parent changed size */
	BRect pFrame = fCachedParent->Frame();
	if (fCachedWsWidth != pFrame.Width() || fCachedWsHeight != pFrame.Height()) {
		fCachedWsWidth = pFrame.IntegerWidth();
		fCachedWsHeight = pFrame.IntegerHeight();
		printf("BSnow: Parent resized to %" B_PRId32 " %" B_PRId32 "\n", fCachedWsWidth, fCachedWsHeight);
		fFallenReg->MakeEmpty(); /* remove all the fallen snow */
		ResizeTo(pFrame.IntegerWidth(), pFrame.IntegerHeight());
		fDragger->MoveTo(pFrame.IntegerWidth()-7, pFrame.IntegerHeight()-7);
	}

	/* make new flakes */
	for (i=0; i<fNumFlakes; i++) {
		if (fFlakes[cw][i].weight == 0) {
			fFlakes[cw][i].weight = ((float)(rand() % WEIGHT_SPAN)) / WEIGHT_GRAN;
			fFlakes[cw][i].weight = MAX(fFlakes[cw][i].weight, 0.5);
			fFlakes[cw][i].pos.y = rand() % 5 - 2;
			fFlakes[cw][i].pos.x = (rand()%(fCachedWsWidth+2*fCachedWsHeight))-fCachedWsHeight;
			if (fFlakes[cw][i].pos.x < -10) {
				fFlakes[cw][i].pos.y = -fFlakes[cw][i].pos.x;
				if (fWind > 0)
					fFlakes[cw][i].pos.x = 0;
				else
					fFlakes[cw][i].pos.x = fCachedWsWidth;
			}
			if (fFlakes[cw][i].pos.x > fCachedWsWidth+10) {
				fFlakes[cw][i].pos.y = fFlakes[cw][i].pos.x - fCachedWsWidth;
				if (fWind > 0)
					fFlakes[cw][i].pos.x = 0;
				else
					fFlakes[cw][i].pos.x = fCachedWsWidth;
			}
		}
	}
	
	/* like a candle in the wind... */
	if (fWindDuration < system_time()) {
		fWindDuration = system_time() + ((((bigtime_t)rand())*1000) % WIND_MAX_DURATION);
		fWind = (rand() % WIND_SPAN) - WIND_SPAN/2;
		printf("BSnow: wind change: %f\n", fWind);
	}
	

//	if (fFallenView->LockLooperWithTimeout(5000)) {
//	if (fFallenBmp) {
//		uint8 *fallenBits = (uint8 *)fFallenBmp->Bits();
		
		BRegion desktopReg;
		GetClippingRegion(&desktopReg);

		/* let's add some gravity and wind */
		for (i=0; i<fNumFlakes; i++) {
			float yinc;
			if (fFlakes[cw][i].weight == 0)
				continue;
			fFlakes[cw][i].opos = fFlakes[cw][i].pos;
			
			yinc = fFlakes[cw][i].weight - (rand() % 3);
			yinc = MAX(yinc, 0.5);
			fFlakes[cw][i].pos.y += yinc;

//			if (fFlakes[cw][i].pos.y > (fCachedWsHeight-FALLEN_HEIGHT)) {

			bool fallen = false;
			bool keepfalling = false;
			
			/* fallen on the flour */
			if (fFlakes[cw][i].pos.y > fCachedWsHeight-2)
				fallen = true;
			/* fallon on another fallen flake */
			else if (fFallenReg->Intersects(BRect(fFlakes[cw][i].pos - BPoint(0,1), 
											fFlakes[cw][i].pos + BPoint(0,1)))) {
				/* don't accumulate too much */
				if ((fFlakes[cw][i].pos.y > fCachedWsHeight-30) || 
									!desktopReg.Intersects(
									BRect(fFlakes[cw][i].pos + BPoint(0,6), 
									fFlakes[cw][i].pos + BPoint(0,10))))
					fallen = true;
			/* fallen on a window */
			} else if (!desktopReg.Intersects(
							BRect(fFlakes[cw][i].pos + BPoint(-1,-1-2), 
							fFlakes[cw][i].pos + BPoint(1,1-1))) && 
					desktopReg.Intersects(
							BRect(fFlakes[cw][i].pos + BPoint(-1,-1-3), 
							fFlakes[cw][i].pos + BPoint(1,1-3)))) {
				//printf("fallen3 @ %f %f\n", fFlakes[cw][i].pos.x, fFlakes[cw][i].pos.y);
				fFlakes[cw][i].pos = fFlakes[cw][i].opos;
				fallen = true;
				keepfalling = true; /* but keep one falling */
			}
			
/*			else if (fallenBits[ (long)(fFlakes[cw][i].pos.y
					 * fFallenBmp->BytesPerRow()
					 + fFlakes[cw][i].pos.y
					 - (fCachedWsHeight-FALLEN_HEIGHT)) ] != B_TRANSPARENT_MAGIC_CMAP8) {
				fallen = true;
			}*/

//			if (fallen) {
//				int pat = (fFlakes[cw][i].weight>3)?1:0;
//				if (fFlakes[cw][i].pos.y > fCachedWsHeight-1)
//					fFlakes[cw][i].pos.y = fCachedWsHeight-(rand()%4);
				//fFallenView->DrawBitmap(fFlakeBitmaps[pat], fFlakes[cw][i].pos-BPoint(PAT_HOTSPOT));
//				fallenBits[ (long)(fFlakes[cw][i].pos.y * fFallenBmp->BytesPerRow()
//					+ fFlakes[cw][i].pos.y-(fCachedWsHeight-FALLEN_HEIGHT)) ] = 0x56;
//				printf("fallen @ %f, %f\n", fFlakes[cw][i].pos.x, fFlakes[cw][i].pos.y);
//			}
			if (fallen) {
				if (!keepfalling)
					fFlakes[cw][i].weight = 0;
				fFallenReg->Include(BRect(fFlakes[cw][i].pos - BPoint(2,0), 
										fFlakes[cw][i].pos + BPoint(2,2)));
				if (keepfalling) {
					fFlakes[cw][i].pos += BPoint(0,10);
					/* except if under the desktop */
					if (fFlakes[cw][i].pos.y > fCachedWsHeight-1)
						fFlakes[cw][i].weight = 0;
				}
			}
			
			/* cleanup, when a window hides the snow */
			fFallenReg->IntersectWith(&desktopReg);
			
			/* cleanup, when a window is moved */
			/* seems to lockup Tracker */
/*
			int32 cnt = fFallenReg->CountRects();
			for (i=0; i<cnt; i++) {
				BRect r = fFallenReg->RectAt(i);
				if (desktopReg.Intersects(r.OffsetByCopy(0,15))) {
					fFallenReg->Exclude(r);
					cnt--;
				}
			}
*/			
			/* add the effect of the wind */
			fFlakes[cw][i].pos.x += fWind + (rand() % 6 - 3);
			if ((fFlakes[cw][i].pos.x > fCachedWsWidth+50)||(fFlakes[cw][i].pos.x < -50))
				fFlakes[cw][i].weight = 0;
		}
//		fFallenView->UnlockLooper();
//	}
#if 0
	for (i=0; i<10; i++)
		printf("f[%d] = {%f, %f}, {%f, %f}, %d\n", i,
			fFlakes[cw][i].opos.x, fFlakes[cw][i].opos.y,
			fFlakes[cw][i].pos.x, fFlakes[cw][i].pos.y,
			fFlakes[cw][i].weight);
#endif
}
Esempio n. 25
0
 bool timed_wait(lock_type& m,xtime const& wait_until)
 {
     return timed_wait(m,system_time(wait_until));
 }
Esempio n. 26
0
uint32
real_time_clock(void)
{
	return (__arch_get_system_time_offset(sRealTimeData) + system_time())
		/ 1000000;
}
Esempio n. 27
0
bool
RemoteEventStream::EventReceived(RemoteMessage& message)
{
	uint16 code = message.Code();
	uint32 what = 0;
	switch (code) {
		case RP_MOUSE_MOVED:
			what = B_MOUSE_MOVED;
			break;
		case RP_MOUSE_DOWN:
			what = B_MOUSE_DOWN;
			break;
		case RP_MOUSE_UP:
			what = B_MOUSE_UP;
			break;
		case RP_MOUSE_WHEEL_CHANGED:
			what = B_MOUSE_WHEEL_CHANGED;
			break;
		case RP_KEY_DOWN:
			what = B_KEY_DOWN;
			break;
		case RP_KEY_UP:
			what = B_KEY_UP;
			break;
		case RP_MODIFIERS_CHANGED:
			what = B_MODIFIERS_CHANGED;
			break;
	}

	if (what == 0)
		return false;

	BMessage* event = new BMessage(what);
	if (event == NULL)
		return false;

	event->AddInt64("when", system_time());

	switch (code) {
		case RP_MOUSE_MOVED:
		case RP_MOUSE_DOWN:
		case RP_MOUSE_UP:
		{
			message.Read(fMousePosition);
			if (code != RP_MOUSE_MOVED)
				message.Read(fMouseButtons);

			event->AddPoint("where", fMousePosition);
			event->AddInt32("buttons", fMouseButtons);
			event->AddInt32("modifiers", fModifiers);

			if (code == RP_MOUSE_DOWN) {
				int32 clicks;
				if (message.Read(clicks) == B_OK)
					event->AddInt32("clicks", clicks);
			}

			if (code == RP_MOUSE_MOVED)
				fLatestMouseMovedEvent = event;
			break;
		}

		case RP_MOUSE_WHEEL_CHANGED:
		{
			float xDelta, yDelta;
			message.Read(xDelta);
			message.Read(yDelta);
			event->AddFloat("be:wheel_delta_x", xDelta);
			event->AddFloat("be:wheel_delta_y", yDelta);
			break;
		}

		case RP_KEY_DOWN:
		case RP_KEY_UP:
		{
			int32 numBytes;
			if (message.Read(numBytes) != B_OK)
				break;

			char* bytes = (char*)malloc(numBytes + 1);
			if (bytes == NULL)
				break;

			if (message.ReadList(bytes, numBytes) != B_OK)
				break;

			for (int32 i = 0; i < numBytes; i++)
				event->AddInt8("byte", (int8)bytes[i]);

			bytes[numBytes] = 0;
			event->AddData("bytes", B_STRING_TYPE, bytes, numBytes + 1, false);
			event->AddInt32("modifiers", fModifiers);

			int32 rawChar;
			if (message.Read(rawChar) == B_OK)
				event->AddInt32("raw_char", rawChar);

			int32 key;
			if (message.Read(key) == B_OK)
				event->AddInt32("key", key);

			break;
		}

		case RP_MODIFIERS_CHANGED:
		{
			event->AddInt32("be:old_modifiers", fModifiers);
			message.Read(fModifiers);
			event->AddInt32("modifiers", fModifiers);
			break;
		}
	}

	BAutolock lock(fEventListLocker);
	fEventList.AddItem(event);
	if (fWaitingOnEvent) {
		fWaitingOnEvent = false;
		lock.Unlock();
		release_sem(fEventNotification);
	}

	return true;
}
Esempio n. 28
0
bigtime_t
real_time_clock_usecs(void)
{
	return __arch_get_system_time_offset(sRealTimeData) + system_time();
}
Esempio n. 29
0
void timer_current_time(tm_time_t &t)
{
	t = system_time();
}
Esempio n. 30
0
void
BStopWatch::Resume()
{
	if (fSuspendTime)
		fStart = system_time() - fSuspendTime - fStart;
}