示例#1
0
// Register server as available
void* DSPServer::registration(void* arg) 
{
    DSPServer* serv = (DSPServer*)arg;
    
    char host_name[256];
    gethostname(host_name, sizeof(host_name));
    
#ifdef LLVM_DSP_FACTORY
    string target = getDSPMachineTarget();
#else
    string target = "Interpreter";
#endif
    
    stringstream name_service;
    name_service << searchIP() << ":" << serv->fPort << ":" << host_name << ":" << target;
    lo_address adress = lo_address_new("224.0.0.1", "7770");
    
    while (true) {
    #ifdef WIN32
        Sleep(1);
    #else
        usleep(1000000);
    #endif
        pthread_testcancel();
        string res = name_service.str();
        lo_send(adress, "/faustcompiler", "is", getpid(), res.c_str());
    }
    
    pthread_exit(NULL);
}
static void get_address_from_ip(const char *text, std::string &ipstr, std::string &address)
{
    GMatchInfo *match_info;
    GRegex *regex = g_regex_new ("(((\\d{1,2})|(1\\d{2})|(2[0-4]\\d)|(25[0-5]))\\.){3}((\\d{1,2})|(1\\d{2})|(2[0-4]\\d)|(25[0-5]))", (GRegexCompileFlags)0, (GRegexMatchFlags)0, NULL);
    g_regex_match (regex, text, (GRegexMatchFlags)0, &match_info);
    if (g_match_info_matches(match_info)) {
        gchar *word = g_match_info_fetch (match_info, 0);
        ipstr = word;
        g_free (word);
    }
    g_match_info_free (match_info);
    g_regex_unref (regex);
    if (ipstr.empty())
        return;
    std::string datafilename = plugin_info->datadir;
    datafilename += G_DIR_SEPARATOR_S "data" G_DIR_SEPARATOR_S "QQWry.Dat";
    FILE *fp = g_fopen(datafilename.c_str(), "rb");
    if (!fp) {
        gchar *msg = g_strdup_printf(_("Error: Open file %s failed!"), datafilename.c_str());
        address = msg;
        g_free(msg);
        return;
    }
    unsigned long index_start,index_end;
    getHead(fp,&index_start,&index_end);
    unsigned long ip = getIP(ipstr.c_str());
    unsigned long current=searchIP(fp,index_start,index_end,ip);
    std::string country,location;
    getAddress(fp,getValue(fp,current+4,3),country,location);
    gchar *c = g_convert(country.c_str(), -1, "UTF-8", "GB18030", NULL, NULL, NULL);
    if (c) {
        address += c;
        address += ' ';
        g_free(c);
    }
    gchar *l = g_convert(location.c_str(), -1, "UTF-8", "GB18030", NULL, NULL, NULL);
    if (l) {
        address += l;
        g_free(l);
    }
    fclose(fp);
}
示例#3
0
// Register server as available
void* Server::registration(void* arg){
    
    printf("SERVICE REGISTRATION\n");
    
    char host_name[256];
    gethostname(host_name, sizeof(host_name));
    
    Server* serv = (Server*)arg;
    
    stringstream p;
    p<<serv->fPort;
    
    string nameRegisterService = "._";
    
    nameRegisterService += searchIP();
    nameRegisterService += ":";
    nameRegisterService += p.str();
    nameRegisterService += "._";
    nameRegisterService += host_name;

    lo_address t = lo_address_new("224.0.0.1", "7770");
    
    while (true) {
#ifdef WIN32
        Sleep(1);
#else
        usleep(1000000);
#endif
        pthread_testcancel();
        
        int pid = getpid();
        lo_send(t, "/faustcompiler", "is", pid, nameRegisterService.c_str());
    }
    
    pthread_exit(NULL);
}
示例#4
0
// Init remote dsp instance sends a POST request to a remote server
// The URL extension used is /CreateInstance
// The datas to send are NetJack parameters & the factory index it is create from
// A NetJack master is created to open a connection with the slave opened on the server's side
bool remote_dsp_aux::init(int argc, const char *argv[], int sampling_rate, int buffer_size, RemoteDSPErrorCallback error_callback, void* error_callback_arg, int& error){
    
    fBufferSize = buffer_size;
    
    fErrorCallback = error_callback;
    fErrorCallbackArg = error_callback_arg;
     
// Init Control Buffers

    fOutControl = new float[buffer_size];
    fInControl = new float[buffer_size];

    fControlInputs[0] = new float[8192];
    fControlOutputs[0] = new float[8192];
 
    memset(fOutControl, 0, sizeof(float)*buffer_size);
    memset(fInControl, 0, sizeof(float)*buffer_size);
    
    memset(fControlInputs[0], 0, sizeof(float)*8192);
    memset(fControlOutputs[0], 0, sizeof(float)*8192);
    
    // To be sure fCounterIn and fCounterOut are set before 'compute' is called, even if no 'buildUserInterface' is called by the client
    ControlUI dummy_ui;
    buildUserInterface(&dummy_ui);
    
    bool partial_cycle = atoi(getValueFromKey(argc, argv, "--NJ_partial", "0"));
    
    const char* port = getValueFromKey(argc, argv, "--NJ_port", "19000");
    
// PREPARE URL TO SEND TO SERVER
    
// Parse NetJack Parameters
    string finalRequest = "NJ_ip=";
    finalRequest += string(getValueFromKey(argc, argv, "--NJ_ip", searchIP().c_str()));
  
    finalRequest += "&NJ_port=";
    finalRequest += string(port);
    
    finalRequest += "&NJ_compression=";
    finalRequest += string(getValueFromKey(argc, argv, "--NJ_compression", "-1"));
    
    finalRequest += "&NJ_latency=";
    finalRequest += string(getValueFromKey(argc, argv, "--NJ_latency", "2"));
    
    finalRequest += "&NJ_mtu=";
    finalRequest += string(getValueFromKey(argc, argv, "--NJ_mtu", "1500"));
    
    finalRequest += "&factoryKey=";
    finalRequest += fFactory->key();
    
    finalRequest += "&instanceKey=";
    
    stringstream s;
    s<<this;
    
    finalRequest += s.str();
    
    printf("finalRequest = %s\n", finalRequest.c_str());
    
    bool isInitSuccessfull = false;
        
    string ip = fFactory->serverIP();
    ip += "/CreateInstance";
        
    string response("");
    int errorCode = -1;

// OPEN NET JACK CONNECTION
    if(send_request(ip, finalRequest, response, errorCode)){
        printf("BS & SR = %i | %i\n", buffer_size, sampling_rate);
        
        jack_master_t request = { -1, -1, -1, -1, static_cast<jack_nframes_t>(buffer_size), static_cast<jack_nframes_t>(sampling_rate), "test_master", 5, partial_cycle};
        jack_slave_t result;
        fNetJack = jack_net_master_open(DEFAULT_MULTICAST_IP, atoi(port), "net_master", &request, &result); 
        
        if (fNetJack) {
            isInitSuccessfull = true;
        } else {
            error = ERROR_NETJACK_NOTSTARTED;
        }
    } else {
        error = errorCode;
    }
    
    printf("remote_dsp_aux::init = %p || inputs = %i || outputs = %i\n", this, fFactory->numInputs(), fFactory->numOutputs());
    
    return isInitSuccessfull;
}