Exemple #1
0
inline status wait_children(Children &cs) 
{ 
    BOOST_ASSERT(cs.size() >= 2); 

    typename Children::iterator it = cs.begin(); 
    while (it != cs.end()) 
    { 
        const status s = it->wait(); 
        ++it; 
        if (it == cs.end()) 
            return s; 
        else if (!s.exited() || s.exit_status() != EXIT_SUCCESS) 
        { 
            while (it != cs.end()) 
            { 
                it->wait(); 
                ++it; 
            } 
            return s; 
        } 
    } 

    BOOST_ASSERT(false); 
    return cs.begin()->wait(); 
} 
Exemple #2
0
void Panel::RemoveAllChildren()
{
    Children aspChildren = m_aspChildren;
    for ( Children::iterator it = aspChildren.begin(); it != aspChildren.end(); ++it )
    {
        GuiObjectPtr spChild = *it;
        DeinitChild( spChild );
    }
    m_aspChildren.clear();
    
    if ( GetSizeModeX() == SIZE_MODE_CONTENT ||
         GetSizeModeY() == SIZE_MODE_CONTENT )
    {
        UpdateSize();
    }
     
    // Dispatch events   
    for ( Children::iterator it = aspChildren.begin(); it != aspChildren.end(); ++it )
    {
        GuiObjectPtr spChild = *it;
        DispatchEvent( EVENT_PANEL_CHILD_REMOVED, GetSharedPtr< Panel >(), spChild );
        DispatchEvent( EVENT_PANEL_CHILDREN_CHANGED, GetSharedPtr< Panel >(), spChild );
    }
}
Exemple #3
0
 void findAllUnresolvedSymbols(std::vector<ParseItem>* pItems) const
 {
    // Get the unresolved symbols at this node
    std::set<ParseItem> unresolved = getUnresolvedSymbols();
    pItems->insert(pItems->end(), unresolved.begin(), unresolved.end());
    
    // Apply this over all children on the node
    Children children = getChildren();
    
    for (Children::iterator it = children.begin();
         it != children.end();
         ++it)
    {
       (**it).findAllUnresolvedSymbols(pItems);
    }
 }
Exemple #4
0
void InstanceArray::bindToMasterView(const ViewSharedPtr& inMaster, bool inMapPortReferences)
	throw (Error) {
	typedef std::vector<InstanceSharedPtr> Children;
	Children children;
	getChildren(children);
	Children::iterator child = children.begin();
	Children::iterator cEnd = children.end();
	for(; child != cEnd; ++child) {
		try {
			(*child)->bindToMasterView(inMaster);
		} catch(Error& e) {
			e.setCurrentLocation(__FUNCTION__, __FILE__, __LINE__);
			throw;
		}
	}
	Instance::bindToMasterView(inMaster, false);
}
void FontSizeComboBox::setActiveFontSize(int value)
{
	if (value == 0)
	{
		unset_active();
		return;
	}
	
    typedef Gtk::TreeModel::Children Children;
    Children children = font_size_tree_model_->children();
    for (Children::iterator iter = children.begin(); iter != children.end(); ++iter)
	{
		Gtk::TreeModel::Row row = *iter;
		if (row[columns_.font_size] == value)
		{
			set_active (iter);
			break;
		}
	}
}
Exemple #6
0
int main () {
    Component* composite1 = new Composite();

    composite1->add( GET("LeafA") );
    composite1->add( GET("LeafA") );
    
    Component* composite2 = new Composite();
    composite2->add( GET("LeafB") );
    composite2->add( GET("LeafA") );
    composite2->add( composite1 );
    composite2->draw(10);

    Children* children = composite2->getChildren();

    std::cout << std::endl;
    int i = 11;
    for(typename Children::iterator it = children->begin(); it != children->end(); ++it) {
        (*it)->draw(i);
        i += 11;
    }
    return 0;
}
Exemple #7
0
void Entity::onObjectLoaded()
{
    __super::onObjectLoaded();

    if ( m_parent )
    {
        onAttached( *m_parent );
    }

    // copy the managed children to the runtime children array
    unsigned int count = m_managedChildren.size();
    m_children.resize( count );
    for( unsigned int i = 0; i < count; ++i )
    {
        m_children[i] = m_managedChildren[i];
    }

    // inform that the children have been attached
    Children children = m_children;
    for ( Children::iterator it = children.begin(); it != children.end(); ++it )
    {
        onChildAttached( **it );
    }
}
Exemple #8
0
void start()
{
    std::ofstream pidfile(SC_PID);
    if (!pidfile.good()) {
        std::cerr << "cannot open PID file " << SC_PID << ": " << strerror(errno) << std::endl;
        exit(errno);
    }
    pidfile << getpid() << std::endl;
    pidfile.close();

    std::ofstream log;

    log.open(SC_LOG, std::ofstream::app);
    log << "\n"
        << logPrefix() << "starting shoutcast daemon" << std::endl;
    log << logPrefix() << "reading shoutcast configuration files from " << SC_CONFIG << std::endl;
    log.close();

    // Enumerate config files in shoutcast config dir.
    DIR *dir;
    struct dirent *ent;
    dir = opendir (SC_CONFIG);
    if (dir == NULL) {
        log.open(SC_LOG, std::ofstream::app);
        log << logPrefix() << "cannot read scd configuration direcoty " << SC_CONFIG << ": " << strerror(errno) << std::endl;
        log.close();
        exit(errno);
    }

    for (; ent = readdir(dir); ent != NULL) {
        std::string cfgfile = ent->d_name;
        if (cfgfile == "." || cfgfile == "..") {
            continue;
        }
        std::string cfgpath = SC_CONFIG;
        cfgpath += "/";
        cfgpath += cfgfile;
        Child c;
        c.pid = 0;
        c.config = cfgpath;
        size_t idx = cfgfile.find(".");
        c.log = SC_LOGDIR"sc_stream_";
        c.log += cfgfile.substr(0, idx);
        c.log += ".log";
        g_children.push_back(c);

        log.open(SC_LOG, std::ofstream::app);
        log << logPrefix() << "found shoutcast configuration: " << cfgpath << std::endl;
        log.close();
    }
    closedir(dir);

    // Start respawn loop.
    while (g_running) {
        // Respawn all children with zero pid.
        for (Children::iterator i = g_children.begin();
                i != g_children.end(); ++i) {
            if (i->pid == 0) {
                i->pid = fork();
                if (i->pid == 0) {
                    // Open log file and redirect stdout, stderr.
                    FILE *f = fopen(i->log.c_str(), "a");
                    int r1 = dup2(fileno(f), 1);
                    int r2 = dup2(fileno(f), 2);
                    fclose(f);

                    // Start child process.
                    std::cout << timeStr()
                              << "[" << getpid() << "] started"
                              << std::endl;
                    if (execl(SC_EXEC, SC_EXEC, i->config.c_str(),
                            (char*)0) < 0) {
                        exit(1);
                    }
                } else {
                    log.open(SC_LOG, std::ofstream::app);
                    log << logPrefix() << "spawned server for config " << i->config << ", server pid is [" << i->pid << "]" << std::endl;
                    log.close();
                }
            }
        }

        // Wait for any failed children.
        int status;
        pid_t pid = wait(&status);
        if (!g_running)
            break;

        // Mark a failed child to restart.
        for (Children::iterator i = g_children.begin(); i != g_children.end(); ++i) {
            if (i->pid == pid) {
                log.open(SC_LOG, std::ofstream::app);
                log << logPrefix() << "server with pid [" << pid << "] (" << i->config << ") failed with status " << status << std::endl;
                log.close();
                i->pid = 0;
                break;
            }
        }
    }

    log.open(SC_LOG, std::ofstream::app);
    log << logPrefix() << "terminated" << "\n" << std::endl;
    log.close();
}