コード例 #1
0
int obtain_server()
{
    int status;
    char buffer[MAXBUFSIZE];
    socklen_t sock_len = sizeof(struct sockaddr_in);

    while(1)
    {
        // receive from multicast channel
        status = recvfrom(client_listen_sock, buffer, MAXBUFSIZE, 0, (struct sockaddr *)&server_addr, &sock_len);

        if(status <= 0)
        {
            LOGINF(1, "Timeout waiting for broadcast packet\n");fflush(stdout);
        }
        else
        {
            char *ip = inet_ntoa(server_addr.sin_addr);

            LOGINF(1, "Got a broadcast packet, setting configuration\n");
            LOGINF(1, "%s\n", ip);fflush(stdout);

            break;
        }
    }
}
コード例 #2
0
ファイル: uisthread.c プロジェクト: 383530895/linux
void
uisthread_stop(struct uisthread_info *thrinfo)
{
	int ret;
	int stopped = 0;

	if (thrinfo->id == 0)
		return;		/* thread not running */

	LOGINF("uisthread_stop stopping id:%d\n", thrinfo->id);
	thrinfo->should_stop = 1;
	ret = KILL(thrinfo->id, SIGHUP, 1);
	if (ret) {
		LOGERR("unable to signal thread %d\n", ret);
	} else {
		/* give up if the thread has NOT died in 1 minute */
		if (wait_for_completion_timeout(&thrinfo->has_stopped, 60 * HZ))
			stopped = 1;
		else
			LOGERR("timed out trying to signal thread\n");
	}
	if (stopped) {
		LOGINF("uisthread_stop stopped id:%d\n", thrinfo->id);
		thrinfo->id = 0;
	}
}
コード例 #3
0
/*
 * Handles the following signals: SIGINT, SIGTERM, SIGABRT
 * Safetly cleans up opens files and resets all system calls.
 */
void signal_handler(int param)
{
    LOGINF(2, "\nSmartlet Simulator is shutting down, cleaning up...\n");

    if(client_tcp_sock != -1) close(client_tcp_sock);
    if(client_listen_sock != -1) close(client_listen_sock);

    LOGINF(2, "Done!\n");
    exit(EXIT_SUCCESS);
}
コード例 #4
0
ファイル: main.cpp プロジェクト: ewatc/pacattack
int main(int argc, char **argv)
{
    // Initialize Engine
    if (ewatceInitialize()) {
        // Start the Game
        LOGINF("Starting Game....");
        StartGame();
        LOGINF("Game Finished....");
    }

    // Shutdown Engine
    ewatceShutdown();

	return 0;
}
コード例 #5
0
ファイル: media.cpp プロジェクト: piesbert/nameless
bool Media::init() {
    bool retval {true};

    if (SDL_Init(SDL_INIT_EVERYTHING) < 0) {
        LOGERR(SDL_GetError());
        retval = false;
    }

    if (retval) {
        setGlAttributes();
        createWindow();

        if (m_window != nullptr) {
            LOGINF("Creating OpenGL context.");
            m_glContext = SDL_GL_CreateContext(m_window);
            SDL_GL_MakeCurrent(m_window, m_glContext);
        }
    }

    if (m_glContext == 0) {
        LOGERR(SDL_GetError());
        retval = false;
    }
    else {
        glewExperimental = GL_TRUE;
        glewInit();

        glClearColor(0.0, 0.0, 0.0, 1.0);
        glClear(GL_COLOR_BUFFER_BIT);
        SDL_GL_SwapWindow(m_window);
    }

    return retval;
}
コード例 #6
0
ファイル: media.cpp プロジェクト: piesbert/nameless
Media::~Media() {
    if (m_glContext) {
        LOGINF("Removing OpenGL context");
        SDL_GL_DeleteContext(m_glContext);
    }

    SDL_Quit();
}
コード例 #7
0
int connectTCP()
{
    // Variable and structure definitions
    int rc;
    char *ip;
    struct hostent *hostp;

    ip = inet_ntoa(server_addr.sin_addr);

    // Get a socket descriptor
    client_tcp_sock = socket(AF_INET, SOCK_STREAM, 0);
    if(client_tcp_sock < 0)
    {
        LOGERRNO("socket", "Unable to create TCP socket to server %s\n", ip);
        return -1;
    }
    else
        LOGINF(1, "TCP socket created\n");

    server_addr.sin_family = AF_INET;
    server_addr.sin_port = htons(SMARTLET_PORT);

    if(server_addr.sin_addr.s_addr == (unsigned long)INADDR_NONE)
    {
        LOGERR("Server IP address is invalid: %s\n", ip);
        return -1;
    }

    // Attempt to connect to server on TCP socket
    rc = connect(client_tcp_sock, (struct sockaddr *)&server_addr, sizeof(server_addr));
    if(rc < 0)
    {
        LOGERRNO("connect", "Unable to connect to server\n");
        return -1;
    }
    else
        LOGINF(1, "Connection established...\n");

    return 1;
}
コード例 #8
0
ファイル: sdlinput.cpp プロジェクト: piesbert/nameless
int SdlInput::handleEvents() {
    int eventCnt {0};

    while(SDL_PollEvent(&m_event)) {
        eventCnt++;

        if (m_event.type == SDL_QUIT) {
            m_signal.kill();
        }
    }

    LOGINF("Input events: " << eventCnt);

    return eventCnt;
}
コード例 #9
0
int deliverMessage(char* in, int size, int i)
{
    int rc;
    rc = write(client_tcp_sock, in,size);//strlen(in)+1);

    if(rc <= 0)
    {
        LOGERRNO("write", "Unable to send packet to TCP server\n");
        return -1;
    }
    else
    {
        LOGINF(1, "Write success\n");
        return 1;
    }
}
コード例 #10
0
ファイル: uisthread.c プロジェクト: 383530895/linux
/* returns 0 for failure, 1 for success */
int
uisthread_start(struct uisthread_info *thrinfo,
		int (*threadfn)(void *), void *thrcontext, char *name)
{
	thrinfo->should_stop = 0;
	/* used to stop the thread */
	init_completion(&thrinfo->has_stopped);
	thrinfo->task = kthread_create(threadfn, thrcontext, name, NULL);
	if (IS_ERR(thrinfo->task)) {
		thrinfo->id = 0;
		return 0;	/* failure */
	}
	thrinfo->id = thrinfo->task->pid;
	wake_up_process(thrinfo->task);
	LOGINF("started thread pid:%d\n", thrinfo->id);
	return 1;

}
コード例 #11
0
ファイル: SReqListener.cpp プロジェクト: q1kim/personness
// The example code of organize virtual method
bool SReqListener::organize(ReqMsg &msgRcv, ReqMsg &msgSnd) {
	LOGINF("%s: %p", mName.c_str(), msgRcv.u.push_message.data);

	if (!mName.compare("t1") && msgRcv.u.push_message.data == (void *)0x1) {
		LOGVBS("t1 sends a message to t2");

		ReqMsg msg;

		msg.type = ReqMsg::PUSH;
		msg.u.push_message.data = (void *)0xbaad;

		AudienceMap::iterator it = mReqAudience.find("t2");
		if (it != mReqAudience.end()) {
			SReqListener *listener = it->second;
			listener->request(msg);
		}
	}

	// just copy the orignal message
	msgSnd = msgRcv;

	return true;
}
コード例 #12
0
ファイル: signal.cpp プロジェクト: piesbert/nameless
void Signal::kill() const {
    LOGINF("Signal: KILL");
    m_kernel.kill();
}
コード例 #13
0
ファイル: engine.cpp プロジェクト: piesbert/nameless
Engine::~Engine() {
    LOGINF("Slowing down...");
}
コード例 #14
0
ファイル: engine.cpp プロジェクト: piesbert/nameless
Engine::Engine() {
    LOGINF("Start your engine!");
}
コード例 #15
0
/*
 * Handles all command line arguments
 */
void handle_args(int argc, char *argv[], int config_pass)
{
    char *p;
    int ret = 0;

    // Preserve name for myself
    progname = ((p = strrchr (argv[0], '/')) ? ++p : argv[0]);

    // Check parameters
    if (argc < 1)
        usage(0);

    // Parse command line
    optind = 1;
    opterr = 1;
    if(config_pass) opterr = 0;
    while (ret != -1)
    {
        ret = getopt_long (argc, argv, "hds:n:t:v::", longopts, 0);

        // Pass through until a configure file option is found
        if (config_pass && ret !='f' && ret != 'h') continue;

        switch (ret)
        {
        case -1 :
            break;
        case 'h':
            usage(0);
            break;
        case 'd':
            daemonize = 1;
            break;
        case 'v':
            if(optarg)
                verbose = atoi(optarg);
            else
                ++verbose;
            break;
        case 'n':
            num_clients = atoi(optarg);
            if(num_clients > MAX_CLIENTS)
            {
                LOGERR("Number of desired clients is too large (%d), setting to maximum (%d)\n", num_clients, MAX_CLIENTS);
                num_clients = MAX_CLIENTS;
            }
            else
                LOGINF(2, "Number of clients set to %d\n", num_clients);
            break;
        case 't':
            update_time = atoi(optarg);
            LOGINF(2, "Update timer set to %d\n", update_time);
            break;
        case 's':
            if(!inet_pton(AF_INET, optarg, &(server_addr.sin_addr)))
            {
                LOGERR("Option '-s' (%s) does not represent a valid network address\n", optarg);
                usage(optopt);
            }
            break;
        case ':':
            printf("Option -%c requires an operand\n", optopt);
        case '?':	// unknown option
            usage(optopt);
            break;
        }
    }
}