Example #1
0
 STDMETHODIMP voice_token::OpenKey(LPCWSTR pszSubKeyName,ISpDataKey **ppSubKey)
 {
   if(pszSubKeyName==0)
     return E_INVALIDARG;
   if(ppSubKey==0)
     return E_POINTER;
   *ppSubKey=0;
   try
     {
       if(!str_equal(pszSubKeyName,L"Attributes"))
         return SPERR_NOT_FOUND;
       com::object<ISpDataKeyImpl > obj;
       for(attribute_map::const_iterator it=attributes.begin();it!=attributes.end();++it)
         {
           obj->set(it->first,it->second);
         }
       com::interface_ptr<ISpDataKey> int_ptr(obj);
       *ppSubKey=int_ptr.get();
       return S_OK;
     }
   catch(const std::bad_alloc&)
     {
       return E_OUTOFMEMORY;
     }
   catch(...)
     {
       return E_UNEXPECTED;
     }
 }
TEST_F( Factory_TEST
      , StoreAndGetObjectWithoutAGroupWith1Param__ObjectToStoreAndGetAreEqual )
{
    typedef Factory< Models::IModel
                   , int > ModelFactory1;

    EXPECT_CALL( *model__
               , checkArgs( 5
                          , 0 ) );

    std::shared_ptr< int > int_ptr( new int( 5 ) );

    ModelFactory1::store( "testArgs0"
                        , Models::MockModel::createMockModelWithArg );

    std::shared_ptr< Models::IModel > returned_object =
                                      ModelFactory1::get( "testArgs0"
                                                        , int_ptr );

    EXPECT_EQ( static_cast< Models::IModel* >( model__ )
             , returned_object.get() );
}
Example #3
0
int main(int argc, char *argv[]) {
    struct sockaddr_in serv;
    struct sockaddr_in client;
    //    struct in_addr *aux;

    short port = 4000;

    //    char *host = "193.136.19.131";

    char buf[1024];
    wchar_t wbuf[1024];
    size_t n;
    unsigned int size = sizeof(client);
    int zbr = 1;
    FILE *f = NULL;

    init_locale();

    if (argc != 2) {
	printf("Usage: nat-server <config-file>\n");
	return 0;
    }

    CORPORA = g_hash_table_new(g_int_hash, g_int_equal);

    /* CONFIGURATION FILE */
    LOG("Loading configuration file");
    f = fopen(argv[1], "rb");
    if (f) {
	CorpusInfo *tmp_corpus;
	while(!feof(f)) {
	    fgets(buf, 1024, f);
	    if (!feof(f)) {
		if (buf[0] == '\n' || buf[0] == '#' || buf[0] == ' ') continue;

                // strip newline if there is one
                while (buf[strlen(buf) - 1] == ' ' || buf[strlen(buf) - 1] == '\n' ||
                       buf[strlen(buf) - 1] == '/' || buf[strlen(buf) - 1] == '\t')
                    buf[strlen(buf) - 1] = '\0';

		LOG("Loading corpus from %s [%d]", buf, ++LAST_CORPORA);
		tmp_corpus = corpus_info_new(buf); 
		g_hash_table_insert(CORPORA, int_ptr(LAST_CORPORA), tmp_corpus);
	    }
	}
	fclose(f);
    } else {
	report_error("Can't find '%s'", argv[1]);
    }
    
    /* SERVER CODE */
    /*-------------*/

    signal(SIGALRM, handle_sigalrm);
    signal(SIGINT, handle_sigint);
    signal(SIGPIPE, handle_sigpipe);

    memset(&serv, 0, sizeof(serv));

    serv.sin_family = AF_INET;
    serv.sin_port = htons(port);
    serv.sin_addr.s_addr = htonl(INADDR_ANY);
 
    if (( sockfd = socket(AF_INET, SOCK_STREAM, 0) ) < 0 ) {
	LOG("couldn't create socket!");
	return -1;
    } else {
	LOG("socket created!");
    }

    setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR, &zbr, sizeof zbr);

    if ((bind(sockfd, (struct sockaddr *) &serv, sizeof(serv))) <0 ) {
	LOG("couldn't bind!");
	return -1;
    } else {
	LOG("bind!");
    }

  
    if (listen(sockfd,5) < 0 ) {
	LOG("couldn't listen");
	return -1;
    } else{
	LOG("listen done");
    }

    for(;;) {
	if ((fd = accept(sockfd, (struct sockaddr *) &client, &size)) < 0 ) {
	    LOG("couln't accept connection!");
	    return(-1);
	} else {
#if DEBUG	    
	    LOG("accept connection (from: %s:%d) (fd: %d)",
		inet_ntoa((struct in_addr)client.sin_addr),
		ntohs(client.sin_port),
		fd); 
#endif
	    alarm(50);
	    n = read(fd, buf, 1024);

	    if ( n > 0 ) {
                // buf to wchar_t ?
                swprintf(wbuf, 1024, L"%s", buf);

		parse(fd, wbuf, argv[1]);
		wbuf[0] = L'\0';
		n = 0;
	    }
	    alarm(0);
	    close(fd);  
	}
    }
}