void IPNDAgent::raiseEvent(const Event *evt) throw ()
		{
			try {
				const dtn::net::P2PDialupEvent &dialup = dynamic_cast<const dtn::net::P2PDialupEvent&>(*evt);

				switch (dialup.type)
				{
					case dtn::net::P2PDialupEvent::INTERFACE_UP:
					{
						// add the interface to the stored set
						{
							ibrcommon::MutexLock l(_interface_lock);

							// only add the interface once
							if (_interfaces.find(dialup.iface) != _interfaces.end()) break;

							// store the new interface in the list of interfaces
							_interfaces.insert(dialup.iface);
						}

						// subscribe to NetLink events on our interfaces
						ibrcommon::LinkManager::getInstance().addEventListener(dialup.iface, this);

						// listen to the new interface
						listen(dialup.iface);

						// join to all multicast addresses on this interface
						join_interface(dialup.iface);
						break;
					}

					case dtn::net::P2PDialupEvent::INTERFACE_DOWN:
					{
						// check if the interface is bound by us
						{
							ibrcommon::MutexLock l(_interface_lock);

							// only remove the interface if it exists
							if (_interfaces.find(dialup.iface) == _interfaces.end()) break;

							// remove the interface from the stored set
							_interfaces.erase(dialup.iface);
						}

						// subscribe to NetLink events on our interfaces
						ibrcommon::LinkManager::getInstance().removeEventListener(dialup.iface, this);

						// leave the multicast groups on the interface
						leave_interface(dialup.iface);

						// remove all sockets on this interface
						unlisten(dialup.iface);
						break;
					}
				}
			} catch (std::bad_cast&) {

			}
		}
void device::close_file(int device, int secondary_address)
{
    DMSG("> iec_close_file");
    listen( device );
    close_cmd( secondary_address );
    unlisten();
    DMSG("< iec_close_file");
}
		void IPNDAgent::eventNotify(const ibrcommon::LinkEvent &evt)
		{
			// check first if we are really bound to the interface
			{
				ibrcommon::MutexLock l(_interface_lock);
				if (_interfaces.find(evt.getInterface()) == _interfaces.end()) return;
			}

			switch (evt.getAction())
			{
				case ibrcommon::LinkEvent::ACTION_ADDRESS_ADDED:
				{
					const ibrcommon::vaddress &bindaddr = evt.getAddress();
					ibrcommon::udpsocket *sock = new ibrcommon::udpsocket(bindaddr);
					try {
						sock->up();
						_send_socket.add(sock, evt.getInterface());
						join_interface(evt.getInterface());
					} catch (const ibrcommon::socket_exception&) {
						delete sock;
					}
					break;
				}

				case ibrcommon::LinkEvent::ACTION_ADDRESS_REMOVED:
				{
					ibrcommon::socketset socks = _send_socket.get(evt.getInterface());
					for (ibrcommon::socketset::iterator iter = socks.begin(); iter != socks.end(); ++iter) {
						ibrcommon::udpsocket *sock = dynamic_cast<ibrcommon::udpsocket*>(*iter);
						if (sock->get_address().address() == evt.getAddress().address()) {
							// leave interfaces if a interface is totally gone
							if (socks.size() == 1) {
								leave_interface(evt.getInterface());
							}

							_send_socket.remove(sock);
							sock->down();
							delete sock;
							break;
						}
					}
					break;
				}

				case ibrcommon::LinkEvent::ACTION_LINK_DOWN:
				{
					// leave the multicast groups on the interface
					leave_interface(evt.getInterface());

					// remove all sockets on this interface
					unlisten(evt.getInterface());
					break;
				}

				default:
					break;
			}
		}
size_t device::send_data(const std::vector<unsigned char>& data_buf,
			    int device_number,
			    int channel )
{
    listen( device_number );
    data_listen( channel );

    size_t sent = 0;
    try
    {
	sent = send_to_bus(data_buf);
    }
    catch (raspbiec_error &e)
    {
	unlisten();
	throw;
    }
    unlisten();


    return sent;
}
void device::open_file( const char *name,
			int device,
			int secondary_address )
{
    DMSG("> iec_open_file");
    listen( device );
    open_cmd( secondary_address );

    send_byte_buffered_init();
    for ( ; *name != '\0'; ++name )
    {
        send_byte_buffered( ascii2petscii(*name) );
    }
    send_last_byte();

    unlisten();
    DMSG("< iec_open_file");
}
Exemple #6
0
uint8 IEC::OutATN(uint8 byte)
{
	received_cmd = sec_addr = 0;	// Command is sent with secondary address
	switch (byte & 0xf0) {
		case ATN_LISTEN:
			listening = true;
			return listen(byte & 0x0f);
		case ATN_UNLISTEN:
			listening = false;
			return unlisten();
		case ATN_TALK:
			listening = false;
			return talk(byte & 0x0f);
		case ATN_UNTALK:
			listening = false;
			return untalk();
	}
	return ST_TIMEOUT;
}
Exemple #7
0
		Receiver<T>::~Receiver()
		{
			for(auto emitter : emitters)
				unlisten(*emitter);
			emitters.clear();
		}