Esempio n. 1
0
// Server side
bool JackFifo::Allocate(const char* name, const char* server_name, int value)
{
    struct stat statbuf;
    BuildName(name, server_name, fName, sizeof(fName));
    jack_log("JackFifo::Allocate name = %s", fName);

    if (stat(fName, &statbuf) < 0) {
        if (errno == ENOENT || errno == EPERM) {
            if (mkfifo(fName, 0666) < 0) {
                jack_error("Cannot create inter-client FIFO name = %s err = %s", name, strerror(errno));
                return false;
            }
        } else {
            jack_error("Cannot check on FIFO %s", name);
            return false;
        }
    } else {
        if (!S_ISFIFO(statbuf.st_mode)) {
            jack_error("FIFO name = %s already exists, but is not a FIFO", name);
            return false;
        }
    }

    if ((fFifo = open(fName, O_RDWR | O_CREAT, 0666)) < 0) {
        jack_error("Cannot open FIFO name = %s err = %s", name, strerror(errno));
        return false;
    } else {
        fPoll.fd = fFifo;
        fPoll.events = POLLERR | POLLIN | POLLHUP | POLLNVAL;
        return true;
    }
}
// Server side : publish the semaphore in the global namespace
bool JackAndroidSemaphore::Allocate(const char* name, const char* server_name, int value)
{
    pthread_mutex_lock (&mutex);
    BuildName(name, server_name, fName, sizeof(fName));
    jack_log("JackAndroidSemaphore::Allocate name = %s val = %ld", fName, value);

	android::sp<android::IAndroidShm> service = android::Shm::getShmService();
	if(service == NULL){
		jack_error("shm service is null");
		return false;
	}
    fSemaphoreMemory = service->InitSemaphore(fName);
    if(fSemaphoreMemory != NULL){
        fSemaphore = (sem_t*)(fSemaphoreMemory->getBase());
    }

    if(fSemaphore == NULL) {
        jack_error("Allocate: can't check in named semaphore name = %s err = %s", fName, strerror(errno));
        pthread_mutex_unlock (&mutex);
        return false;
    } else {
        sem_init(fSemaphore, 1, 0);
        jack_log("sem_init()");
        pthread_mutex_unlock (&mutex);
        return true;
    }
}
OwnerCmdPerception::OwnerCmdPerception( const char *name,
                                        psPETCommandMessage::PetCommand_t command,
                                        gemNPCObject *owner,
                                        gemNPCObject *pet,
                                        gemNPCObject *target ) : Perception(BuildName(command))
{
    this->command = command;
    this->owner = owner;
    this->pet = pet;
    this->target = (gemNPCActor *) target;
}
// Server side : publish the semaphore in the global namespace
bool JackPosixSemaphore::Allocate(const char* name, const char* server_name, int value)
{
    BuildName(name, server_name, fName, sizeof(fName));
    jack_log("JackPosixSemaphore::Allocate name = %s val = %ld", fName, value);

    if ((fSemaphore = sem_open(fName, O_CREAT, 0777, value)) == (sem_t*)SEM_FAILED) {
        jack_error("Allocate: can't check in named semaphore name = %s err = %s", fName, strerror(errno));
        return false;
    } else {
        return true;
    }
}
Esempio n. 5
0
  STIInfo( int ItemType, void *pItemData )
  {
    // default these two..
    m_ItemType = ItemType;
    m_ItemData = pItemData;
    m_iconindices[0] = ICON_CHANNELS;
    m_iconindices[1] = ICON_CHANNELS;
    m_ItemName = NULL; // initialise this one.
    
    switch(ItemType)
    {
      case STI_SERVER:
        m_pServer = (IRCServer *)pItemData;
        m_iconindices[2] = ICON_SERVER;
        m_iconindices[3] = ICON_SERVER;
        m_TIIItem = TII_IRCSERVER;
        break;
      case STI_CHANNEL:
        m_pChannel = (IRCChannel *)pItemData;
        m_iconindices[2] = ICON_CHANNEL;
        m_iconindices[3] = ICON_CHANNEL;
        m_TIIGroup = TII_CHANNELGROUP;
        m_TIIItem = TII_IRCCHANNEL;
        m_GroupName = "Channels";
        m_TreeSortValue = GROUPORDER_ID_CHANNELS;
        break;
      case STI_DCCCHAT:
        m_pServer = (IRCServer *)pItemData;
        m_iconindices[2] = ICON_DCCCHAT;
        m_iconindices[3] = ICON_DCCCHAT;
        m_TIIGroup = TII_DCCCHATGROUP;
        m_TIIItem = TII_DCCCHAT;
        m_GroupName = "DCC Chats";
        m_TreeSortValue = GROUPORDER_ID_DCCCHATS;
        break;
      case STI_QUERY:
        m_pQuery = (IRCQuery *)pItemData;
        m_iconindices[2] = ICON_QUERY;
        m_iconindices[3] = ICON_QUERY;
        m_TIIGroup = TII_QUERYGROUP;
        m_TIIItem = TII_QUERY;
        m_GroupName = "Queries";
        m_TreeSortValue = GROUPORDER_ID_QUERIES;
        break;
#ifdef DEBUG
      default:
        ATLASSERT(0); // Unknown Item!
#endif    
    }
    BuildName();
  }
Esempio n. 6
0
bool CSerializePrxToMap::SerializeImport(int num, const PspLibImport *imp)
{
	char str_import[128];
	int iLoop;
	u32 addr;
	snprintf(str_import, sizeof(str_import), "import%d", num);

	addr = imp->addr;

	if(imp->stub.name != 0)
	{
		PrintOffset(m_fpOut, addr);
		fprintf(m_fpOut, ".word\t%s\t; %s\n", imp->name, BuildName(str_import, "name"));
	}
	else
	{
		PrintOffset(m_fpOut, addr);
		fprintf(m_fpOut, ".word\t%s\t; %s\n", str_import, BuildName(str_import, "name"));
	}

	fprintf(m_fpOut, ".word\t%s\n", BuildName(str_import, "flags"));
	fprintf(m_fpOut, ".word\t%s\n", BuildName(str_import, "counts"));
	fprintf(m_fpOut, ".word\t%s\n", BuildName(str_import, "nids"));
	fprintf(m_fpOut, ".word\t%s\n", BuildName(str_import, "funcs"));

	for(iLoop = 0; iLoop < imp->f_count; iLoop++)
	{
		PrintOffset(m_fpOut, imp->funcs[iLoop].nid_addr);
		fprintf(m_fpOut, ".word\t%s\t; NID %08x\n", BuildName(str_import, imp->funcs[iLoop].name), imp->funcs[iLoop].nid);

		PrintOffset(m_fpOut, imp->funcs[iLoop].addr);
		fprintf(m_fpOut, ".code\t%s\n", imp->funcs[iLoop].name);
	}

	for(iLoop = 0; iLoop < imp->v_count; iLoop++)
	{

		PrintOffset(m_fpOut, imp->funcs[iLoop].nid_addr);
		fprintf(m_fpOut, ".word\t%s\t; NID %08x\n", BuildName(str_import, imp->vars[iLoop].name), imp->vars[iLoop].nid);

		PrintOffset(m_fpOut, imp->vars[iLoop].nid_addr + ((imp->v_count + imp->f_count) * 4));
		fprintf(m_fpOut, ".word\t%s\n", imp->vars[iLoop].name);
	}

	return true;
}
// Server side : publish the semaphore in the global namespace
bool JackMachSemaphore::Allocate(const char* name, const char* server_name, int value)
{
    BuildName(name, server_name, fName, sizeof(fName));
    mach_port_t task = mach_task_self();
    kern_return_t res;

    if (fBootPort == 0) {
        if ((res = task_get_bootstrap_port(task, &fBootPort)) != KERN_SUCCESS) {
            jack_error("Allocate: Can't find bootstrap mach port err = %s", mach_error_string(res));
            return false;
        }
    }

    if ((res = semaphore_create(task, &fSemaphore, SYNC_POLICY_FIFO, value)) != KERN_SUCCESS) {
        jack_error("Allocate: can create semaphore err = %s", mach_error_string(res));
        return false;
    }

    if ((res = bootstrap_register(fBootPort, fName, fSemaphore)) != KERN_SUCCESS) {
        jack_error("Allocate: can't check in mach semaphore name = %s err = %s", fName, mach_error_string(res));

        switch (res) {
            case BOOTSTRAP_SUCCESS :
                /* service not currently registered, "a good thing" (tm) */
                break;
            case BOOTSTRAP_NOT_PRIVILEGED :
                jack_log("bootstrap_register(): bootstrap not privileged");
                break;
            case BOOTSTRAP_SERVICE_ACTIVE :
                jack_log("bootstrap_register(): bootstrap service active");
                break;
            default :
                jack_log("bootstrap_register() err = %s", mach_error_string(res));
                break;
        }

        return false;
    }

    jack_log("JackMachSemaphore::Allocate name = %s", fName);
    return true;
}
// Client side : get the published semaphore from server
bool JackMachSemaphore::ConnectInput(const char* name, const char* server_name)
{
    BuildName(name, server_name, fName, sizeof(fName));
    kern_return_t res;

    if (fBootPort == 0) {
        if ((res = task_get_bootstrap_port(mach_task_self(), &fBootPort)) != KERN_SUCCESS) {
            jack_error("Connect: can't find bootstrap port err = %s", mach_error_string(res));
            return false;
        }
    }

    if ((res = bootstrap_look_up(fBootPort, fName, &fSemaphore)) != KERN_SUCCESS) {
        jack_error("Connect: can't find mach semaphore name = %s err = %s", fName, mach_error_string(res));
        return false;
    }

    jack_log("JackMachSemaphore::Connect name = %s ", fName);
    return true;
}
Esempio n. 9
0
// Client side
bool JackFifo::ConnectAux(const char* name, const char* server_name, int access)
{
    BuildName(name, server_name, fName, sizeof(fName));
    jack_log("JackFifo::ConnectAux name = %s", fName);

    // Temporary...
    if (fFifo >= 0) {
        jack_log("Already connected name = %s", name);
        return true;
    }

    if ((fFifo = open(fName, access)) < 0) {
        jack_error("Connect: can't connect named fifo name = %s err = %s", fName, strerror(errno));
        return false;
    } else {
        fPoll.fd = fFifo;
        fPoll.events = POLLERR | POLLIN | POLLHUP | POLLNVAL;
        return true;
    }
}
// Client side : get the published semaphore from server
bool JackPosixSemaphore::ConnectInput(const char* name, const char* server_name)
{
    BuildName(name, server_name, fName, sizeof(fName));
    jack_log("JackPosixSemaphore::Connect name = %s", fName);

    // Temporary...
    if (fSemaphore) {
        jack_log("Already connected name = %s", name);
        return true;
    }

    if ((fSemaphore = sem_open(fName, O_CREAT)) == (sem_t*)SEM_FAILED) {
        jack_error("Connect: can't connect named semaphore name = %s err = %s", fName, strerror(errno));
        return false;
    } else {
        int val = 0;
        sem_getvalue(fSemaphore, &val);
        jack_log("JackPosixSemaphore::Connect sem_getvalue %ld", val);
        return true;
    }
}
// Client side : get the published semaphore from server
bool JackAndroidSemaphore::ConnectInput(const char* name, const char* server_name)
{
    pthread_mutex_lock (&mutex);
    BuildName(name, server_name, fName, sizeof(fName));
    jack_log("JackAndroidSemaphore::Connect name = %s", fName);

    // Temporary...
    if (fSemaphore) {
        jack_log("Already connected name = %s", name);
        pthread_mutex_unlock (&mutex);
        return true;
    }

	android::sp<android::IAndroidShm> service = android::Shm::getShmService();
	if(service == NULL){
		jack_error("shm service is null");
		return false;
	}

    fSemaphoreMemory = service->InitSemaphore(fName);
    if(fSemaphoreMemory != NULL){
        fSemaphore = (sem_t*)(fSemaphoreMemory->getBase());
    }

    if(fSemaphore == NULL) {
        jack_error("Connect: can't connect named semaphore name = %s err = %s", fName, strerror(errno));
        pthread_mutex_unlock (&mutex);
        return false;
    } else {
        int val = 0;
        sem_getvalue(fSemaphore, &val);
        jack_log("JackAndroidSemaphore::Connect sem_getvalue %ld", val);
        pthread_mutex_unlock (&mutex);
        return true;
    }
}
Esempio n. 12
0
bool CSerializePrxToIdc::SerializeImport(int num, const PspLibImport *imp)
{
	char str_import[128];
	int iLoop;
	u32 addr;
	snprintf(str_import, sizeof(str_import), "import%d", num);

	addr = imp->addr;

	if(imp->stub.name != 0)
	{
		MakeOffset(m_fpOut, str_import, addr);
		MakeString(m_fpOut, BuildName(str_import, "name"), imp->stub.name);
	}
	else
	{
		MakeDword(m_fpOut, str_import, addr);
	}

	MakeDword(m_fpOut, BuildName(str_import, "flags"), addr+4);
	MakeDword(m_fpOut, BuildName(str_import, "counts"), addr+8);
	MakeOffset(m_fpOut, BuildName(str_import, "nids"), addr+12);
	MakeOffset(m_fpOut, BuildName(str_import, "funcs"), addr+16);

	for(iLoop = 0; iLoop < imp->f_count; iLoop++)
	{
		MakeDword(m_fpOut, BuildName(str_import, imp->funcs[iLoop].name), imp->funcs[iLoop].nid_addr);
		MakeFunction(m_fpOut, imp->funcs[iLoop].name, imp->funcs[iLoop].addr);
	}

	for(iLoop = 0; iLoop < imp->v_count; iLoop++)
	{
		MakeDword(m_fpOut, BuildName(str_import, imp->vars[iLoop].name), imp->vars[iLoop].nid_addr);
		MakeOffset(m_fpOut, "", imp->vars[iLoop].nid_addr + ((imp->v_count + imp->f_count) * 4));
	}

	return true;
}
Esempio n. 13
0
static void BuildList( void ) {
    int numDirs, numDemos;
    void **dirlist, **demolist;
    char *cache, *p;
    unsigned flags;
    size_t len;
    int i;

    // this can be a lengthy process
    S_StopAllSounds();
    m_demos.menu.status = "Building list...";
    SCR_UpdateScreen();

    // list files
    flags = ui_listalldemos->integer ? 0 : FS_TYPE_REAL | FS_PATH_GAME;
    dirlist = FS_ListFiles( m_demos.browse, NULL, flags |
        FS_SEARCH_DIRSONLY, &numDirs );
    demolist = FS_ListFiles( m_demos.browse, DEMO_EXTENSIONS, flags |
        FS_SEARCH_EXTRAINFO, &numDemos );

    // alloc entries
    m_demos.list.items = UI_Malloc( sizeof( demoEntry_t * ) * ( numDirs + numDemos + 1 ) );
    m_demos.list.numItems = 0;
    m_demos.list.curvalue = 0;
    m_demos.list.prestep = 0;

    m_demos.widest_map = 3;
    m_demos.widest_pov = 3;
    m_demos.total_bytes = 0;

    // start with minimum size
    m_demos.menu.size( &m_demos.menu );

    if( m_demos.browse[0] ) {
        BuildDir( "..", ENTRY_UP );
    }

    // add directories
    if( dirlist ) {
        for( i = 0; i < numDirs; i++ ) {
            BuildDir( dirlist[i], ENTRY_DN );
        }
        FS_FreeList( dirlist );
    }    

    m_demos.numDirs = m_demos.list.numItems;

    // add demos
    if( demolist ) {
        CalcHash( demolist );
        if( ( cache = LoadCache( demolist ) ) != NULL ) {
            p = cache + 32 + 1;
            for( i = 0; i < numDemos; i++ ) {
                BuildName( demolist[i], &p );
            }
            FS_FreeFile( cache );
        } else {
            for( i = 0; i < numDemos; i++ ) {
                BuildName( demolist[i], NULL );
                if( ( i & 7 ) == 0 ) {
                    m_demos.menu.size( &m_demos.menu );
                    SCR_UpdateScreen();
                }
            }
        }
        WriteCache();
        FS_FreeList( demolist );
    }

    // update status line and sort
    if( m_demos.list.numItems ) {
        Change( &m_demos.list.generic );
        if( m_demos.list.sortdir ) {
            m_demos.list.sort( &m_demos.list, m_demos.list.sortcol );
        }
    }

    // resize columns
    m_demos.menu.size( &m_demos.menu );

    // format our extra status line
    i = m_demos.list.numItems - m_demos.numDirs;
    len = Q_scnprintf( m_demos.status, sizeof( m_demos.status ),
        "%d demo%s, ", i, i == 1 ? "" : "s" );
    Com_FormatSizeLong( m_demos.status + len, sizeof( m_demos.status ) - len,
        m_demos.total_bytes );
        
    SCR_UpdateScreen();
}