Esempio n. 1
0
void SeqToolBarView::MouseDown(BPoint where)
{
	AM_LOG("\nSeqToolBarView::MouseDown() 1\n");
	mDraggingRect = invalid_rect();
	mMouseDownButtonHack = 0;
	for (uint32 k = 0; k < mCachedData.size(); k++) mCachedData[k].mButton = 0;
	bool				hitPropertyMenu;
	mMouseDownTool = CachedToolAt(where, &hitPropertyMenu);
	if (mMouseDownTool) {
		AM_LOG("SeqToolBarView::MouseDown() 2\n");
		if (hitPropertyMenu) {
			AM_LOG("SeqToolBarView::MouseDown() 2a\n");
			// READ TOOL BLOCK
			AmToolRef		toolRef = mMouseDownTool->ToolRef();
			const AmTool*	tool = toolRef.ReadLock();
			if (tool) ShowPropertyMenu(tool, where);
			toolRef.ReadUnlock(tool);
			// END READ TOOL BLOCK
		} else {
			AM_LOG("SeqToolBarView::MouseDown() 2b\n");
			uint32			button = 0;
			Window()->CurrentMessage()->FindInt32("buttons", (int32*)&button);
#ifdef AM_LOGGING
			BString			str("\tbuttons: ");
			str << button << "\n";
			AM_BLOG(str);
#endif
			mMouseDownTool->mButton = button;
			mMouseDownButtonHack = button;
			Invalidate();
		}
	}
	AM_LOG("SeqToolBarView::MouseDown() 3 (end)\n");
}
Esempio n. 2
0
int get_valid_url_index(unsigned long instance_id) {
    int i, value = 0;
    struct am_log *log = AM_LOG();

    if (log == NULL) {
        return value;
    }

#ifdef _WIN32
    WaitForSingleObject(am_log_lck.lock, INFINITE);
#else
    pthread_mutex_lock(&log->lock);
#endif
    for (i = 0; i < AM_MAX_INSTANCES; i++) {
        if (log->valid[i].instance_id == instance_id) {
            value = log->valid[i].url_index;

            break;
        }
    }
#ifdef _WIN32
    ReleaseMutex(am_log_lck.lock);
#else
    pthread_mutex_unlock(&log->lock);
#endif
    return value;
}
Esempio n. 3
0
void am_agent_init_set_value(unsigned long instance_id, char lock, int val) {
    int i;
    struct am_log *log = AM_LOG();

    if (log == NULL) {
        return;
    }

    if (lock) {
        am_agent_instance_init_lock();
    }
    for (i = 0; i < AM_MAX_INSTANCES; i++) {
        if (val == AM_UNKNOWN) {
            /* find first empty slot */
            if (log->init[i].instance_id == 0) {
                log->init[i].in_progress = 0;
                log->init[i].instance_id = instance_id;
                break;
            }
        } else {
            /* set/reset status value */
            if (log->init[i].instance_id == instance_id) {
                log->init[i].in_progress = val;
                break;
            }
        }
    }
    if (lock) {
        am_agent_instance_init_unlock();
    }
}
Esempio n. 4
0
void SeqToolBarView::MouseMoved(BPoint where,
								uint32 code,
								const BMessage *a_message)
{
	AM_LOG("SeqToolBarView::MouseMoved()\n");
	/* Sometimes, this view might not receive a mouse up for
	 * whatever reason
	 */
	uint32			button = 0;
	Window()->CurrentMessage()->FindInt32("buttons", (int32*)&button);
	if (button == 0) PostMouseUp();
#ifdef AM_LOGGING
	BString			str("\tbutton: ");
	str << button << "\n";
	AM_BLOG(str);
#endif

	BRect		invalidate = invalid_rect();
	BRect		b( Bounds() );
	/* If the dragging area has changed, merge it into the invalidate.
	 */
	BRect		oldDraggingRect(mDraggingRect);
	mDraggingRect = invalid_rect();
	if (b.Contains(where) && a_message && a_message->what == AM_DRAG_TOOL_MSG) {
		if (mCachedData.size() < 1) mDraggingRect = b;
		else mDraggingRect = DraggingRectFor(where);
	}
	if (oldDraggingRect != mDraggingRect) {
		invalidate = merge_rects(invalidate, oldDraggingRect);
		invalidate = merge_rects(invalidate, mDraggingRect);
	}
		
	Invalidate();
}
Esempio n. 5
0
void SeqToolBarView::MouseUp(BPoint where)
{
	AM_LOG("\nSeqToolBarView::MouseUp() 1\n");
	if (mMouseDownTool) {
		AM_LOG("SeqToolBarView::MouseUp() 2\n");
		_SeqCachedTool*		cachedTool = CachedToolAt(where);
		if (mMouseDownTool == cachedTool) {
			AM_LOG("SeqToolBarView::MouseUp() 3\n");
			if (cachedTool->mToolKey.Length() > 0) {
				AM_LOG("SeqToolBarView::MouseUp() 4\n");
				uint32		button = 0;
				if (cachedTool->mButton&B_PRIMARY_MOUSE_BUTTON) button = B_PRIMARY_MOUSE_BUTTON;
				else if (cachedTool->mButton&B_SECONDARY_MOUSE_BUTTON) button = B_SECONDARY_MOUSE_BUTTON;
				else if (cachedTool->mButton&B_TERTIARY_MOUSE_BUTTON) button = B_TERTIARY_MOUSE_BUTTON;
				/* This is a hack because the WACOM graphics tablet driver seems
				 * to always report that no button is held down during mouse move.
				 */
				if (button == 0 && mMouseDownButtonHack != 0) {
					if (mMouseDownButtonHack&B_PRIMARY_MOUSE_BUTTON) button = B_PRIMARY_MOUSE_BUTTON;
					else if (mMouseDownButtonHack&B_SECONDARY_MOUSE_BUTTON) button = B_SECONDARY_MOUSE_BUTTON;
					else if (mMouseDownButtonHack&B_TERTIARY_MOUSE_BUTTON) button = B_TERTIARY_MOUSE_BUTTON;
				}
#ifdef AM_LOGGING
				BString			str("\tbutton: ");
				str << button << ", cachedTool button: " << cachedTool->mButton << "\n";
				AM_BLOG(str);
#endif
				if (button) AmGlobals().SetTool(cachedTool->mToolKey, button, modifiers());
			}
		}
	}
	PostMouseUp();
	mMouseDownButtonHack = 0;
	Invalidate();
	AM_LOG("SeqToolBarView::MouseUp() 5 (end)\n");
}
Esempio n. 6
0
int am_log_get_current_owner() {
    int rv = 0;
    struct am_log *log = AM_LOG();

    if (log == NULL) {
        return rv;
    }

#ifdef _WIN32
    WaitForSingleObject(am_log_lck.lock, INFINITE);
#else
    pthread_mutex_lock(&log->lock);
#endif
    rv = log->owner;
#ifdef _WIN32
    ReleaseMutex(am_log_lck.lock);
#else
    pthread_mutex_unlock(&log->lock);
#endif
    return rv;
}
Esempio n. 7
0
void am_log_re_init(int status) {
    struct am_log *log = AM_LOG();
    if (log != NULL && status == AM_RETRY_ERROR) {
#ifdef _WIN32
        WaitForSingleObject(am_log_lck.lock, INFINITE);
#else
        pthread_mutex_lock(&log->lock);
#endif
        log->owner = getpid();
#ifdef _WIN32
        am_log_handle->reader_thr = CreateThread(NULL, 0,
                (LPTHREAD_START_ROUTINE) am_log_worker, NULL, 0, NULL);
#else
        pthread_create(&am_log_handle->reader_thr, NULL, am_log_worker, NULL);
#endif
#ifdef _WIN32
        ReleaseMutex(am_log_lck.lock);
#else
        pthread_mutex_unlock(&log->lock);
#endif
    }
}
Esempio n. 8
0
int am_agent_init_get_value(unsigned long instance_id, char lock) {
    int i, status = AM_FALSE;
    struct am_log *log = AM_LOG();

    if (log == NULL) {
        return status;
    }

    if (lock) {
        am_agent_instance_init_lock();
    }
    for (i = 0; i < AM_MAX_INSTANCES; i++) {
        /* get status value */
        if (log->init[i].instance_id == instance_id) {
            status = log->init[i].in_progress;
            break;
        }
    }
    if (lock) {
        am_agent_instance_init_unlock();
    }
    return status;
}
Esempio n. 9
0
void set_valid_url_index(unsigned long instance_id, int value) {
    int i, set = AM_FALSE;
    struct am_log *log = AM_LOG();

    if (log == NULL) {
        return;
    }

#ifdef _WIN32
    WaitForSingleObject(am_log_lck.lock, INFINITE);
#else
    pthread_mutex_lock(&log->lock);
#endif
    for (i = 0; i < AM_MAX_INSTANCES; i++) {
        if (log->valid[i].instance_id == instance_id) {
            log->valid[i].url_index = value;
            set = AM_TRUE;
            break;
        }
    }
    if (!set) {
        for (i = 0; i < AM_MAX_INSTANCES; i++) {
            /* find first empty slot */
            if (log->valid[i].instance_id == 0) {
                log->valid[i].url_index = value;
                log->valid[i].instance_id = instance_id;
                break;
            }
        }
    }
#ifdef _WIN32
    ReleaseMutex(am_log_lck.lock);
#else
    pthread_mutex_unlock(&log->lock);
#endif
}
Esempio n. 10
0
void am_log_register_instance(unsigned long instance_id, const char *debug_log, int log_level, int log_size,
        const char *audit_log, int audit_level, int audit_size) {
    int i, exist = AM_NOT_FOUND;
    struct am_log *log = AM_LOG();
    struct log_files *f = NULL;

    if (log == NULL || instance_id == 0 || ISINVALID(debug_log) || ISINVALID(audit_log)) {
        return;
    }

#ifdef _WIN32
    WaitForSingleObject(am_log_lck.lock, INFINITE);
#else
    pthread_mutex_lock(&log->lock);
#endif
    for (i = 0; i < AM_MAX_INSTANCES; i++) {
        f = &log->files[i];
        if (f->instance_id == instance_id) {
            exist = AM_SUCCESS;
            break;
        }
    }
    if (exist == AM_NOT_FOUND) {
        for (i = 0; i < AM_MAX_INSTANCES; i++) {
            f = &log->files[i];
            if (!f->used) {
                f->instance_id = instance_id;
                snprintf(f->name_debug, sizeof (f->name_debug), "%s", debug_log);
                snprintf(f->name_audit, sizeof (f->name_audit), "%s", audit_log);
                f->used = AM_TRUE;

#define DEFAULT_LOG_SIZE (1024 * 1024 * 5) /* 5MB */

                f->max_size_debug = log_size > 0 && log_size < DEFAULT_LOG_SIZE ? DEFAULT_LOG_SIZE : log_size;
                f->max_size_audit = audit_size > 0 && audit_size < DEFAULT_LOG_SIZE ? DEFAULT_LOG_SIZE : audit_size;
                f->level_debug = log_level;
                f->level_audit = audit_level;
                f->created_debug = f->created_audit = 0;
                f->owner = 0;
                exist = AM_DONE;
                break;
            }
        }
    } else {
        /* update instance logging level configuration */
        f->max_size_debug = log_size > 0 && log_size < DEFAULT_LOG_SIZE ? DEFAULT_LOG_SIZE : log_size;
        f->max_size_audit = audit_size > 0 && audit_size < DEFAULT_LOG_SIZE ? DEFAULT_LOG_SIZE : audit_size;
        f->level_debug = log_level;
        f->level_audit = audit_level;
    }
#ifdef _WIN32
    ReleaseMutex(am_log_lck.lock);
#else
    pthread_mutex_unlock(&log->lock);
#endif
    if (exist == AM_DONE) {
#define AM_LOG_HEADER "\r\n\r\n\t######################################################\r\n\t# %-51s#\r\n\t# Version: %-42s#\r\n\t# %-51s#\r\n\t# Build date: %s %-27s#\r\n\t######################################################\r\n"

        AM_LOG_ALWAYS(instance_id, AM_LOG_HEADER, DESCRIPTION, VERSION,
                VERSION_VCS, __DATE__, __TIME__);

        am_agent_init_set_value(instance_id, AM_TRUE, AM_UNKNOWN);
    }
}
Esempio n. 11
0
void am_log_shutdown(int id) {
    static const char *thisfunc = "am_log_shutdown():";
    int i;
    int pid = getpid();
    struct am_log *log = AM_LOG();

    if (log == NULL) {
        return;
    }

    /* notify the logger exit */
    for (i = 0; i < AM_MAX_INSTANCES; i++) {
        struct log_files *f = &log->files[i];
        if (f->instance_id > 0 && f->owner == pid) {
            AM_LOG_ALWAYS(f->instance_id, "%s exiting", thisfunc);
        }
    }

#ifdef _WIN32
    SetEvent(am_log_lck.exit);
    WaitForSingleObject(am_log_handle->reader_thr, INFINITE);
    CloseHandle(am_log_lck.exit);
    CloseHandle(am_log_lck.new_data_cond);
    CloseHandle(am_log_lck.new_space_cond);

    WaitForSingleObject(am_log_lck.lock, INFINITE);
    /* close log file(s) */
    for (i = 0; i < AM_MAX_INSTANCES; i++) {
        struct log_files *f = &log->files[i];
        if (f->owner == pid) {
            if (f->fd_debug != -1) {
                _close(f->fd_debug);
                f->fd_debug = -1;
            }
            if (f->fd_audit != -1) {
                _close(f->fd_audit);
                f->fd_audit = -1;
            }
            f->used = AM_FALSE;
            f->instance_id = 0;
            f->level_debug = f->level_audit = AM_LOG_LEVEL_NONE;
            f->max_size_debug = f->max_size_audit = 0;
        }
    }
    ReleaseMutex(am_log_lck.lock);
    CloseHandle(am_log_lck.lock);
    UnmapViewOfFile(am_log_handle->area);
    CloseHandle(am_log_handle->area_file_id);
#else
    pthread_mutex_unlock(&log->exit);
    pthread_join(am_log_handle->reader_thr, NULL);
    pthread_mutex_destroy(&log->exit);
    pthread_mutex_destroy(&log->lock);
    pthread_cond_destroy(&log->new_data_cond);
    pthread_cond_destroy(&log->new_space_cond);
    /* close log file(s) */
    for (i = 0; i < AM_MAX_INSTANCES; i++) {
        struct log_files *f = &log->files[i];
        if (f->fd_debug != -1) {
            close(f->fd_debug);
            f->fd_debug = -1;
        }
        if (f->fd_audit != -1) {
            close(f->fd_audit);
            f->fd_audit = -1;
        }
        f->used = AM_FALSE;
        f->instance_id = 0;
        f->level_debug = f->level_audit = AM_LOG_LEVEL_NONE;
        f->max_size_debug = f->max_size_audit = 0;
    }
    if (munmap((char *) am_log_handle->area, am_log_handle->area_size) == -1) {
        fprintf(stderr, "am_log_shutdown() munmap failed (%d)\n", errno);
    }
    close(am_log_handle->area_file_id);
    if (shm_unlink(am_log_handle->area_file_name) == -1) {
        fprintf(stderr, "am_log_shutdown() shm_unlink failed (%d)\n", errno);
    }
#endif

    am_agent_instance_init_release(id, AM_TRUE);

    free(am_log_handle);
    am_log_handle = NULL;
}
Esempio n. 12
0
/**
 * This routine is primarily responsible for all logging within this application.
 *   instance_id: the instance that has something to log
 *   level: the level we want to log at, see constants AM_LOG_LEVEL_* in am.h
 *   header: a header consisting of various time information and the current logging level as a string
 *   header_sz: header string length
 *   format: the printf style format string telling us about the variadic arguments
 *   args: the variadic arguments themselves.
 *
 * Normally, this routine logs into a block of shared memory, which is subsequently written to a file.
 * However if we're running a unit test, this block of memory won't have been set up, even though we
 * would still like to log something somewhere.  If test cases ensure that instance_id is set to zero,
 * then logging messages are written to the standard error.
 *
 * Note that if you're calling this function from one of the macros in log.h, then the function
 * perform_logging will already have been called.  If you're not, then consider calling that function
 * first as it will save you a lot of work figuring out you didn't really want to log a message at
 * your current logging level.
 */
void am_log_write(unsigned long instance_id, int level, const char* header, int header_sz, const char *format, ...) {
    struct am_log *log = AM_LOG();
    va_list args;
    unsigned int index;

    /**
     * An instance id of zero indicates that we are running in unit test mode, shared memory is not
     * initialised and so our only option, if we want to log, is to write to the standard error.
     * Note that we ALWAYS log, no matter what the level.
     */
    if (instance_id == 0) {
        va_start(args, format);
        fprintf(stderr, "%s", header);
        vfprintf(stderr, format, args);
        fputs("\n", stderr);
        va_end(args);
        return;
    }

    if (log == NULL || header_sz <= 0) {
        return;
    }

#ifdef _WIN32
    WaitForSingleObject(am_log_lck.lock, INFINITE);
    while (log->read_count + log->write_count >= log->bucket_count) {
        ReleaseMutex(am_log_lck.lock);
        WaitForSingleObject(am_log_lck.new_space_cond, INFINITE);
        WaitForSingleObject(am_log_lck.lock, INFINITE);
    }
#else
    pthread_mutex_lock(&log->lock);
    while (log->read_count + log->write_count >= log->bucket_count) {
        pthread_cond_wait(&log->new_space_cond, &log->lock);
    }
#endif

    index = log->in;
    log->in = AM_LOG_BUFFER_MASK(log->in + 1, log->bucket_count);
    log->write_count++;

#ifdef _WIN32
    ReleaseMutex(am_log_lck.lock);
#else
    pthread_mutex_unlock(&log->lock);
#endif

    /* copy header into the bucket */
    if (strncpy(log->bucket[index].data, header, log->bucket_size - 1) != NULL) {
        va_start(args, format);
        /* and the rest of the message */
        log->bucket[index].size = vsnprintf(log->bucket[index].data + header_sz,
                log->bucket_size - header_sz, format, args) + header_sz;
        log->bucket[index].data[log->bucket[index].size] = '\0';
        va_end(args);
    }

    log->bucket[index].instance_id = instance_id;
    log->bucket[index].level = level;

#ifdef _WIN32
    WaitForSingleObject(am_log_lck.lock, INFINITE);
#else
    pthread_mutex_lock(&log->lock);
#endif

    log->read_count++;
    log->write_count--;
    log->bucket[index].ready_to_read = AM_TRUE;

#ifdef _WIN32
    SetEvent(am_log_lck.new_data_cond);
    ReleaseMutex(am_log_lck.lock);
#else
    pthread_cond_signal(&log->new_data_cond);
    pthread_mutex_unlock(&log->lock);
#endif
}
Esempio n. 13
0
/**
 * This function simply returns true or false depending on whether "level" specifies we
 * need to log given the logger level settings for this instance.  Note that the function
 * should return an am_bool_t, but because of a circular dependency between am.h (which
 * defines that type) and log.h (which needs that type), I'm changing it to "int".
 */
int perform_logging(unsigned long instance_id, int level) {
    int i;
    struct am_log *log = AM_LOG();
    int log_level = AM_LOG_LEVEL_NONE;
    int audit_level = AM_LOG_LEVEL_NONE;

    /* If the instance id is zero, we are either running a test case, or installing something */
    if (instance_id == 0) {
        return zero_instance_logging_is_wanted;
    }

    /* We simply cannot log if the shared memory segment is not initialised */
    if (log == NULL) {
        return AM_FALSE;
    }

#ifdef _WIN32
    WaitForSingleObject(am_log_lck.lock, INFINITE);
#else
    pthread_mutex_lock(&log->lock);
#endif

    for (i = 0; i < AM_MAX_INSTANCES; i++) {
        if (log->files[i].instance_id == instance_id) {
            log_level = log->files[i].level_debug;
            audit_level = log->files[i].level_audit;
            break;
        }
    }

#ifdef _WIN32
    ReleaseMutex(am_log_lck.lock);
#else
    pthread_mutex_unlock(&log->lock);
#endif

    /* Do not log in the following cases:
     *
     * requested log level is set to LEVEL_NONE
     *  or
     * selected (in a configuration) log level is LEVEL_NONE and requested log level is not LEVEL_AUDIT
     *  or
     * selected audit level is LEVE_NONE and requested log level is LEVEL_AUDIT
     */
    if (level == AM_LOG_LEVEL_NONE ||
            (log_level == AM_LOG_LEVEL_NONE && (level & AM_LOG_LEVEL_AUDIT) != AM_LOG_LEVEL_AUDIT) ||
            (audit_level == AM_LOG_LEVEL_NONE && (level & AM_LOG_LEVEL_AUDIT) == AM_LOG_LEVEL_AUDIT)) {
        return AM_FALSE;
    }

    /* In case requested log level is not LEVEL_AUDIT (as we must log audit message in case we
     * got past the previous check) and its not LEVEL_ALWAYS (which must be logged too)
     * and requested log level is "higher" than selected log level according to
     * "DEBUG > INFO > WARNING > ERROR" schema - do not log.
     */
    if ((level & AM_LOG_LEVEL_AUDIT) != AM_LOG_LEVEL_AUDIT &&
            (level & AM_LOG_LEVEL_ALWAYS) != AM_LOG_LEVEL_ALWAYS && level > log_level) {
        return AM_FALSE;
    }

    return AM_TRUE;
}
Esempio n. 14
0
static void *am_log_worker(void *arg) {
    struct am_log *log = AM_LOG();
    int i, level, is_audit;
    unsigned int index;
    char *data;
    size_t data_sz;
    unsigned long instance_id;
    struct stat st;
    struct log_files *f;

    if (log == NULL) {
        return NULL;
    }

#ifdef _WIN32
    WaitForSingleObject(am_log_lck.lock, INFINITE);
#else
    pthread_mutex_lock(&log->lock);
#endif

    for (;;) {
        index = log->out;

#ifdef _WIN32
        while (log->read_count == 0 || !log->bucket[index].ready_to_read) {
            ReleaseMutex(am_log_lck.lock);
            if (WaitForSingleObject(am_log_lck.new_data_cond, 1000) == WAIT_TIMEOUT) {
                if (WaitForSingleObject(am_log_lck.exit, 0) == WAIT_OBJECT_0) {
                    return NULL;
                }
            }
            WaitForSingleObject(am_log_lck.lock, INFINITE);
        }
#else
        while (log->read_count == 0 || !log->bucket[index].ready_to_read) {
            struct timeval now = {0, 0};
            struct timespec ts = {0, 0};
            gettimeofday(&now, NULL);
            ts.tv_sec = now.tv_sec + 1;
            ts.tv_nsec = now.tv_usec * 1000;
            if (pthread_cond_timedwait(&log->new_data_cond, &log->lock, &ts) == ETIMEDOUT) {
                if (should_exit(&log->exit)) {
                    pthread_mutex_unlock(&log->lock);
                    return NULL;
                }
            }
        }
#endif  /* _WIN32 */

        log->bucket[index].ready_to_read = AM_FALSE;
#ifdef _WIN32
        ReleaseMutex(am_log_lck.lock);
#else
        pthread_mutex_unlock(&log->lock);
#endif  /* _WIN32 */

        data = log->bucket[index].data;
        data_sz = log->bucket[index].size;
        level = log->bucket[index].level;
        is_audit = (level & AM_LOG_LEVEL_AUDIT) != 0;
        instance_id = log->bucket[index].instance_id;

        f = NULL;

        for (i = 0; i < AM_MAX_INSTANCES; i++) {
            f = &log->files[i];
            if (f->used && f->instance_id == instance_id) {
                break;
            }
        }

        if (f != NULL) {
            
            if (ISINVALID(f->name_debug)) {
                fprintf(stderr, "am_log_worker(): the debug file name is invalid (i.e. empty or null)\n");
                f->fd_debug = -1;
                f->fd_audit = -1;
                return NULL;
            }
            
            if (ISINVALID(f->name_audit)) {
                fprintf(stderr, "am_log_worker(): the audit file name is invalid (i.e. empty or null)\n");
                f->fd_debug = -1;
                f->fd_audit = -1;
                return NULL;
            }
            
            /* log files are not opened yet, do it now */
            if (f->fd_audit == -1 && f->fd_debug == -1) {
#ifdef _WIN32
                f->fd_debug = _open(f->name_debug, _O_CREAT | _O_WRONLY | _O_APPEND | _O_BINARY,
                        _S_IREAD | _S_IWRITE);
                f->fd_audit = _open(f->name_audit, _O_CREAT | _O_WRONLY | _O_APPEND | _O_BINARY,
                        _S_IREAD | _S_IWRITE);
                if (f->fd_debug != -1 && stat(f->name_debug, &st) == 0) {
                    f->created_debug = st.st_ctime;
                    f->owner = getpid();
                }
                if (f->fd_audit != -1 && stat(f->name_audit, &st) == 0) {
                    f->created_audit = st.st_ctime;
                    f->owner = getpid();
                }
#else
                f->fd_debug = open(f->name_debug, O_CREAT | O_WRONLY | O_APPEND, S_IWUSR | S_IRUSR);
                f->fd_audit = open(f->name_audit, O_CREAT | O_WRONLY | O_APPEND, S_IWUSR | S_IRUSR);
                if (f->fd_debug != -1 && stat(f->name_debug, &st) == 0) {
                    f->node_debug = st.st_ino;
                    f->created_debug = st.st_ctime;
                    f->owner = getpid();
                }
                if (f->fd_audit != -1 && stat(f->name_audit, &st) == 0) {
                    f->node_audit = st.st_ino;
                    f->created_audit = st.st_ctime;
                    f->owner = getpid();
                }
#endif
            }

            if (f->fd_debug == -1) {
                fprintf(stderr, "am_log_worker() failed to open log file %s: error: %d", f->name_debug, errno);
                f->fd_debug = f->fd_audit = -1;
            } else if (f->fd_audit == -1) {
                fprintf(stderr, "am_log_worker() failed to open audit file %s: error: %d", f->name_audit, errno);
                f->fd_debug = f->fd_audit = -1;
            } else {
                int file_handle = is_audit ? f->fd_audit : f->fd_debug;
                char *file_name = is_audit ? f->name_audit : f->name_debug;
                int max_size = is_audit ? f->max_size_audit : f->max_size_debug;
                time_t file_created = is_audit ? f->created_audit : f->created_debug;
#ifdef _WIN32
                int wrote;
#else 
                ssize_t wrote;
                ino_t file_inode = is_audit ? f->node_audit : f->node_debug;
#endif
                wrote = write(file_handle, data, (unsigned int) data_sz);
#ifdef _WIN32
                wrote = write(file_handle, "\r\n", 2);
                _commit(file_handle);

                /* check file timestamp; rotate by date if set so */
                if (max_size == -1 && should_rotate_time(file_created)) {
                    HANDLE fh = (HANDLE) _get_osfhandle(file_handle);
                    unsigned int idx = 1;
                    static char tmp[AM_PATH_SIZE];
                    do {
                        snprintf(tmp, sizeof (tmp), "%s.%d", file_name, idx);
                        idx++;
                    } while (_access(tmp, 0) == 0);
                    if (CopyFileA(file_name, tmp, FALSE)) {
                        SetFilePointer(fh, 0, NULL, FILE_BEGIN);
                        SetEndOfFile(fh);
                        if (is_audit) {
                            f->created_audit = time(NULL);
                        } else {
                            f->created_debug = time(NULL);
                        }
                    } else {
                        fprintf(stderr, "could not rotate log file %s (error: %d)\n",
                                file_name, GetLastError());
                    }
                }

                /* check file size; rotate by size if set so */
                if (max_size > 0) {
                    BY_HANDLE_FILE_INFORMATION info;
                    uint64_t fsz = 0;
                    HANDLE fh = (HANDLE) _get_osfhandle(file_handle);
                    if (GetFileInformationByHandle(fh, &info)) {
                        fsz = ((DWORDLONG) (((DWORD) (info.nFileSizeLow)) |
                                (((DWORDLONG) ((DWORD) (info.nFileSizeHigh))) << 32)));
                    }
                    if ((fsz + 1024) > max_size) {
                        unsigned int idx = 1;
                        static char tmp[AM_PATH_SIZE];
                        do {
                            snprintf(tmp, sizeof (tmp), "%s.%d", file_name, idx);
                            idx++;
                        } while (_access(tmp, 0) == 0);
                        if (CopyFileA(file_name, tmp, FALSE)) {
                            SetFilePointer(fh, 0, NULL, FILE_BEGIN);
                            SetEndOfFile(fh);
                            if (is_audit) {
                                f->created_audit = time(NULL);
                            } else {
                                f->created_debug = time(NULL);
                            }
                        } else {
                            fprintf(stderr, "could not rotate log file %s (error: %d)\n",
                                    file_name, GetLastError());
                        }
                    }
                }
#else
                wrote = write(file_handle, "\n", 1);
                fsync(file_handle);

                /* check file timestamp; rotate by date if set so */
                if (max_size == -1 && should_rotate_time(file_created)) {
                    rename_file(file_name);
                }

                /* check file size; rotate by size if set so */
                if (max_size > 0 && stat(file_name, &st) == 0 && (st.st_size + 1024) > max_size) {
                    rename_file(file_name);
                }

                /* reset file inode number (in case it has changed as a result of rename_file) */
                if (stat(file_name, &st) != 0 || st.st_ino != file_inode) {
                    close(file_handle);
                    if (is_audit) {
                        f->fd_audit = open(f->name_audit, O_CREAT | O_WRONLY | O_APPEND, S_IWUSR | S_IRUSR);
                        f->node_audit = st.st_ino;
                        f->created_audit = st.st_ctime;
                        f->owner = getpid();
                    } else {
                        f->fd_debug = open(f->name_debug, O_CREAT | O_WRONLY | O_APPEND, S_IWUSR | S_IRUSR);
                        f->node_debug = st.st_ino;
                        f->created_debug = st.st_ctime;
                        f->owner = getpid();
                    }
                    if (f->fd_debug == -1 || f->fd_audit == -1) {
                        fprintf(stderr, "am_log_worker() log file re-open failed with error: %d", errno);
                        f->fd_debug = f->fd_audit = -1;
                    }
                }
#endif                            
            }
        }

        log->out = AM_LOG_BUFFER_MASK(log->out + 1, log->bucket_count);
#ifdef _WIN32
        WaitForSingleObject(am_log_lck.lock, INFINITE);
#else
        pthread_mutex_lock(&log->lock);
#endif
        log->read_count--;
#ifdef _WIN32
        SetEvent(am_log_lck.new_space_cond);
#else
        pthread_cond_broadcast(&log->new_space_cond);
#endif
    }
    return NULL;
}
Esempio n. 15
0
void SeqToolBarView::PostMouseUp()
{
	AM_LOG("\nSeqToolBarView::PostMouseUp()\n");
	for (uint32 k = 0; k < mCachedData.size(); k++) mCachedData[k].mButton = 0;
	mDraggingRect = invalid_rect();
}