Esempio n. 1
0
File: pdh.c Progetto: 40a/sigar
JNIEXPORT jstring SIGAR_JNI(win32_Pdh_pdhGetDescription)
(JNIEnv *env, jclass cur, jlong counter)
{
    HCOUNTER h_counter = (HCOUNTER)counter;
    PDH_COUNTER_INFO *info = NULL;
    jstring retval = NULL;
    DWORD size = 0;
    PDH_STATUS status;

    status = PdhGetCounterInfo(h_counter, TRUE, &size, NULL);
    if (status != PDH_MORE_DATA) {
        win32_throw_exception(env, get_error_message(status));
        return NULL;
    }

    info = malloc(size);

    status = PdhGetCounterInfo(h_counter, 1, &size, info);
    if (status == ERROR_SUCCESS) {
        if (info->szExplainText) {
            retval = JENV->NewString(env, info->szExplainText,
                                     lstrlen(info->szExplainText));
        }
    }
    else {
        win32_throw_exception(env, get_error_message(status));
    }

    free(info);
    return retval;
}
Esempio n. 2
0
File: pdh.c Progetto: 40a/sigar
JNIEXPORT jdouble SIGAR_JNI(win32_Pdh_pdhGetValue)
(JNIEnv *env, jclass cur, jlong query, jlong counter, jboolean fmt)
{
    HCOUNTER              h_counter      = (HCOUNTER)counter;
    HQUERY                h_query        = (HQUERY)query;
    PDH_STATUS            status;
    PDH_RAW_COUNTER raw_value;
    PDH_FMT_COUNTERVALUE fmt_value;
    DWORD type;

    status = PdhCollectQueryData(h_query);
   
    if (status != ERROR_SUCCESS) {
        win32_throw_exception(env, get_error_message(status));
        return 0;
    }

    if (fmt) {
        /* may require 2 counters, see msdn docs */
        int i=0;
        for (i=0; i<2; i++) {
            status = PdhGetFormattedCounterValue(h_counter,
                                                 PDH_FMT_DOUBLE,
                                                 (LPDWORD)NULL,
                                                 &fmt_value);
            if (status == ERROR_SUCCESS) {
                break;
            }

            PdhCollectQueryData(h_query);
        }
    }
    else {
        status = PdhGetRawCounterValue(h_counter, &type, &raw_value);
    }

    if (status != ERROR_SUCCESS) {
        win32_throw_exception(env, get_error_message(status));
        return 0;
    }

    if (fmt) {
        return fmt_value.doubleValue;
    }
    else {
        return (jdouble)raw_value.FirstValue;
    }
}
Esempio n. 3
0
File: pdh.c Progetto: 40a/sigar
JNIEXPORT jlong SIGAR_JNI(win32_Pdh_pdhAddCounter)
(JNIEnv *env, jclass cur, jlong query, jstring cp)
{
    HCOUNTER   h_counter;
    HQUERY     h_query = (HQUERY)query;
    PDH_STATUS status;
    LPCTSTR    counter_path = JENV->GetStringChars(env, cp, NULL);

    /* Add the counter that created the data in the log file. */
    status = PdhAddCounter(h_query, counter_path, 0, &h_counter);

    if (status == PDH_CSTATUS_NO_COUNTER) {
        /* if given counter does not exist,
         * try the same name w/ "/sec" appended
         */
        TCHAR counter_sec[MAX_PATH];
        lstrcpy(counter_sec, counter_path);
        lstrcat(counter_sec, _T("/sec"));
        status = PdhAddCounter(h_query, counter_sec, 0, &h_counter);
    }

    JENV->ReleaseStringChars(env, cp, counter_path);

    if (status != ERROR_SUCCESS) {
        win32_throw_exception(env, get_error_message(status));
        return 0;
    }

    return (jlong)h_counter;
}
Esempio n. 4
0
char const* soci_error::what() const throw()
{
    if (info_)
        return info_->get_full_message(get_error_message());

    return std::runtime_error::what();
}
Esempio n. 5
0
void die_with_error(meta_error e, const char *fmt, ...)
{
    va_list ap;
    int rc;

    va_start(ap, fmt);

    if (is_tcpip_error(e))
        syslog(LOG_ERR, "A tcp/ip error has occured");
    else if (is_protocol_error(e))
        syslog(LOG_ERR, "A protocol error has occured");
    else if (is_app_error(e))
        syslog(LOG_ERR, "A application error has occured");
    else if (is_os_error(e))
        syslog(LOG_ERR, "A os error has occured");
    else if (is_db_error(e))
        syslog(LOG_ERR, "A database error has occured");
    else if (is_other_error(e))
        syslog(LOG_ERR, "An unknown error has occured");

    if (has_error_message(e))
        syslog(LOG_ERR, "Error message: %s", get_error_message(e));
    else if ((rc = get_error_code(e)) != 0)
        syslog(LOG_ERR, "Possible error: %d %s\n", rc, strerror(rc));

    meta_vsyslog(LOG_ERR, fmt, ap);
    va_end(ap);

    exit(EXIT_FAILURE);
}
Esempio n. 6
0
    PacketInfo Client::receivePacket( bool is_nonblocking )
    {
        if ( udp_socket < 0 )
            openSocket();

        int flags = 0;
        if ( is_nonblocking )
            flags |= MSG_DONTWAIT;

        sockaddr_in          peer_address;
        socklen_t            peer_address_size = sizeof( peer_address );
        std::vector<uint8_t> receive_buffer( UDP_RECEIVE_BUFFER_SIZE );
        int                  recv_size = recvfrom( udp_socket,
						   receive_buffer.data(),
						   UDP_RECEIVE_BUFFER_SIZE,
						   flags,
						   reinterpret_cast<sockaddr *>( &peer_address ),
						   &peer_address_size );
        if ( recv_size < 0 ) {
            int error_num = errno;
            if ( error_num == EAGAIN ) {
                PacketInfo info;
                return info;
            }
            std::perror( "cannot recv" );
            throw SocketError( get_error_message( "cannot recv packet", error_num ) );
        }

        PacketInfo info;
        info.source_address = convertAddressBinaryToString( peer_address.sin_addr );
        info.source_port    = ntohs( peer_address.sin_port );
        info.payload        = receive_buffer;
        return info;
    }
	void GL3FrameBufferProvider::check_framebuffer_complete()
	{
		FrameBufferStateTracker tracker(bind_target, handle, gc_provider);

		int error_code = glCheckFramebufferStatus(GL_FRAMEBUFFER);
		if (error_code != GL_FRAMEBUFFER_COMPLETE)
			throw Exception(string_format("FrameBuffer is : %1", get_error_message(error_code)));
	}
Esempio n. 8
0
		void handle(int status_code, lua_State *state)
		{
			function_type handler = getHandler(state);
			if (handler)
			{
				handler(status_code, get_error_message(state));
			}
		}
Esempio n. 9
0
JNIEXPORT void JNICALL Java_org_hyperic_hq_plugin_mssql_PDH_PdhCollectQueryData(JNIEnv * env, jclass, jlong query) {
   HQUERY h_query = (HQUERY)query;

    PDH_STATUS status = PdhCollectQueryData(h_query);
   
    if (status != ERROR_SUCCESS) {
        plugin_throw_exception(env, get_error_message(status));
    }
}
Esempio n. 10
0
JNIEXPORT void JNICALL Java_org_hyperic_hq_plugin_mssql_PDH_pdhRemoveCounter(JNIEnv *env, jclass, jlong counter) {
    HCOUNTER   h_counter = (HCOUNTER)counter;
    PDH_STATUS status;
    
    status = PdhRemoveCounter(h_counter);

    if (status != ERROR_SUCCESS) {
        plugin_throw_exception(env, get_error_message(status));
    }
}
Esempio n. 11
0
bool GPRSHTTP::init(int timeout)
{
    if(timeout > 1000 || timeout < 30)
    {
        _error_condition = SIM900_ERROR_INVALID_HTTP_TIMEOUT;
        if(SIM900_DEBUG_OUTPUT)
        {
            SIM900_DEBUG_OUTPUT_STREAM->println(get_error_message(SIM900_ERROR_INVALID_HTTP_TIMEOUT));
        }
        return false;
    }
    int connected = isCGATT();
    if(connected == -1)
    {
        return false;
    }
    delay(1000);

    if(connected == 1) {
        stopBearer(1, 0);
    }

    if(!startBearer(5, 2000))
    {
        return false;
    }

    initialized = HTTPINIT(5, 2000);
    if(!initialized)
    {
        return false;
    }

    //Set the CID
    if(!setParam("CID", _cid))
    {
        return false;
    }

    //Set the URL
    if(!setParam("URL", url))
    {
        return false;
    }

    //Set the HTTP Timeout
    if(!setParam("TIMEOUT", timeout))
    {
        return false;
    }

    Serial.print("URL: ");
    Serial.println(url);
    return true;
}
Esempio n. 12
0
JNIEXPORT jlong JNICALL Java_org_hyperic_hq_plugin_mssql_PDH_pdhOpenQuery(JNIEnv *env, jclass jc) {
    HQUERY     h_query;
    PDH_STATUS status;

    status = PdhOpenQuery(NULL, 0, &h_query);
    if (status != ERROR_SUCCESS) {
        plugin_throw_exception(env, get_error_message(status));
        return 0;
    }
    return (jlong)h_query;
}
Esempio n. 13
0
    uint16_t Client::sendPacket( const uint8_t *data, uint16_t size )
    {
        if ( udp_socket < 0 )
            openSocket();

        int sent_size = send( udp_socket, data, size, 0 );
        if ( sent_size < 0 ) {
            std::string msg = "cannot send to " + parameters.address + ":" + boost::lexical_cast<std::string>( parameters.port );
            throw SocketError( get_error_message( msg, errno ) );
        }
        return sent_size;
    }
Esempio n. 14
0
void Dialog::on_saveBtn_clicked() //TODO check for emty or just space and restrict the lenght of the file name
{
    QString error_message;
    QMessageBox messageBox;
    messageBox.setFixedSize(500,200);
    messageBox.setWindowTitle("Message");
    //messageBox.setWindowFlags(Qt::WindowContextHelpButtonHint);
    int error_code = SaveLevelSystem(ui->fileNameEdit->text(), false);
    if(error_code == NO_ERROR) {
        error_message = get_error_message(error_code);
        messageBox.setText(error_message);
        this->hide();
        messageBox.exec();
    }else{
         error_message = get_error_message(error_code);
         messageBox.setText(error_message);
         messageBox.exec();
    }


}
Esempio n. 15
0
// pdo error handler for the dbh context.
bool pdo_sqlsrv_handle_dbh_error( sqlsrv_context& ctx, unsigned int sqlsrv_error_code, bool warning TSRMLS_DC, 
                                  va_list* print_args )
{
    pdo_dbh_t* dbh = reinterpret_cast<pdo_dbh_t*>( ctx.driver());
    SQLSRV_ASSERT( dbh != NULL, "pdo_sqlsrv_handle_dbh_error: Null dbh passed" );

    sqlsrv_error_auto_ptr error;

    if( sqlsrv_error_code != SQLSRV_ERROR_ODBC ) {
        
        core_sqlsrv_format_driver_error( ctx, get_error_message( sqlsrv_error_code ), error, SEV_ERROR TSRMLS_CC, print_args );
    }
    else {
        bool err = core_sqlsrv_get_odbc_error( ctx, 1, error, SEV_ERROR TSRMLS_CC );
        SQLSRV_ASSERT( err == true, "No ODBC error was found" );
    }

    SQLSRV_STATIC_ASSERT( sizeof( error->sqlstate ) <= sizeof( dbh->error_code ));
    strcpy_s( dbh->error_code, sizeof( dbh->error_code ), reinterpret_cast<const char*>( error->sqlstate ));

    switch( dbh->error_mode ) {
        case PDO_ERRMODE_EXCEPTION:
            if( !warning ) {

                pdo_sqlsrv_throw_exception( error TSRMLS_CC );
            }
            ctx.set_last_error( error );
            break;
        case PDO_ERRMODE_WARNING:
            if( !warning ) {
                unsigned int msg_len = strlen( reinterpret_cast<const char*>( error->native_message )) + SQL_SQLSTATE_BUFSIZE 
                    + MAX_DIGITS + 1;
                sqlsrv_malloc_auto_ptr<char> msg;
                msg = static_cast<char*>( sqlsrv_malloc( msg_len ));
                core_sqlsrv_format_message( msg, msg_len, WARNING_TEMPLATE, error->sqlstate, error->native_code, 
                                            error->native_message );
                php_error( E_WARNING, msg );
                sqlsrv_free( msg );
            }
            ctx.set_last_error( error );
            break;
        case PDO_ERRMODE_SILENT:
            ctx.set_last_error( error );
            break;
        default:
            DIE( "Unknown error mode. %1!d!", dbh->error_mode );
            break;
    }

    // return error ignored = true for warnings.
    return ( warning ? true : false );
}
Esempio n. 16
0
File: pdh.c Progetto: 40a/sigar
JNIEXPORT void SIGAR_JNI(win32_Pdh_pdhRemoveCounter)
(JNIEnv *env, jclass cur, jlong counter)
{
    HCOUNTER   h_counter = (HCOUNTER)counter;
    PDH_STATUS status;
    
    status = PdhRemoveCounter(h_counter);

    if (status != ERROR_SUCCESS) {
        win32_throw_exception(env, get_error_message(status));
        return;
    }
}
Esempio n. 17
0
File: pdh.c Progetto: 40a/sigar
JNIEXPORT jlong JNICALL SIGAR_JNI(win32_Pdh_pdhOpenQuery)
(JNIEnv *env, jobject cur)
{
    HQUERY     h_query;
    PDH_STATUS status;

    status = PdhOpenQuery(NULL, 0, &h_query);
    if (status != ERROR_SUCCESS) {
        win32_throw_exception(env, get_error_message(status));
        return 0;
    }
    return (jlong)h_query;
}
Esempio n. 18
0
JNIEXPORT jdouble JNICALL Java_org_hyperic_hq_plugin_mssql_PDH_PdhGetFormattedCounterValue(JNIEnv *env, jclass, jlong counter) {
    HCOUNTER  h_counter = (HCOUNTER)counter;
    PDH_FMT_COUNTERVALUE fmt_value;

	PDH_STATUS status = PdhGetFormattedCounterValue(h_counter, PDH_FMT_DOUBLE, (LPDWORD)NULL, &fmt_value);

    if (status != ERROR_SUCCESS) {
        plugin_throw_exception(env, get_error_message(status));
        return 0;
    }

    return fmt_value.doubleValue;
}
Esempio n. 19
0
File: pdh.c Progetto: 40a/sigar
JNIEXPORT void SIGAR_JNI(win32_Pdh_pdhConnectMachine)
(JNIEnv *env, jobject cur, jstring jhost)
{
    PDH_STATUS status;
    LPCTSTR host = JENV->GetStringChars(env, jhost, NULL);

    status = PdhConnectMachine(host);
    JENV->ReleaseStringChars(env, jhost, host);

    if (status != ERROR_SUCCESS) {
        win32_throw_exception(env, get_error_message(status));
    }
}
Esempio n. 20
0
    void Client::openSocket()
    {
        if ( udp_socket > 0 ) {
            closeSocket();
        }

        udp_socket = socket( AF_INET, SOCK_DGRAM, IPPROTO_UDP );
        if ( udp_socket < 0 ) {
            std::string msg = get_error_message( "cannot create socket", errno );
            throw SocketError( msg );
        }
        sockaddr_in socket_address;
        std::memset( &socket_address, 0, sizeof( socket_address ) );
        socket_address.sin_family = AF_INET;
        socket_address.sin_addr   = convertAddressStringToBinary( parameters.address );
        socket_address.sin_port   = htons( parameters.port );
        if ( connect( udp_socket, reinterpret_cast<const sockaddr *>( &socket_address ), sizeof( socket_address ) ) <
             0 ) {
            closeSocket();
            std::string msg = "cannot connect to " + parameters.address + ":" + boost::lexical_cast<std::string>( parameters.port );
            throw SocketError( get_error_message( msg, errno ) );
        }
    }
Esempio n. 21
0
JNIEXPORT jdouble JNICALL Java_org_hyperic_hq_plugin_mssql_PDH_pdhGetRawCounterValue(JNIEnv *env, jclass, jlong counter) {
    HCOUNTER  h_counter = (HCOUNTER)counter;
    PDH_RAW_COUNTER raw_value;
	DWORD type;

	PDH_STATUS status = PdhGetRawCounterValue(h_counter, &type, &raw_value);

    if (status != ERROR_SUCCESS) {
        plugin_throw_exception(env, get_error_message(status));
        return 0;
    }

	return (jdouble)raw_value.FirstValue;
}
Esempio n. 22
0
File: pdh.c Progetto: 40a/sigar
JNIEXPORT void SIGAR_JNI(win32_Pdh_pdhCloseQuery)
(JNIEnv *env, jclass cur, jlong query)
{
    HQUERY     h_query    = (HQUERY)query;
    PDH_STATUS status;

    // Close the query and the log file.
    status = PdhCloseQuery(h_query);

    if (status != ERROR_SUCCESS) {
        win32_throw_exception(env, get_error_message(status));
        return;
    }
}
Esempio n. 23
0
 void SharedData::audit_node_name(std::string name) const {
   if (name.empty()) {
     IMP_RMF_THROW("Empty key name", UsageException);
   }
   static const char *illegal="\"";
   const char *cur=illegal;
   while (*cur != '\0') {
     if (name.find(*cur) != std::string::npos) {
       IMP_RMF_THROW(get_error_message("Node names names can't contain \"",
                                       *cur,
                                       "\", but \"", name, "\" does."),
                     UsageException);
     }
     ++cur;
   }
 }
Esempio n. 24
0
File: pdh.c Progetto: 40a/sigar
JNIEXPORT jlong SIGAR_JNI(win32_Pdh_pdhGetCounterType)
(JNIEnv *env, jclass cur, jlong counter)
{
    HCOUNTER h_counter = (HCOUNTER)counter;
    PDH_COUNTER_INFO info;
    DWORD size = sizeof(info);
    PDH_STATUS status;

    status = PdhGetCounterInfo(h_counter, FALSE, &size, &info);
    if (status != ERROR_SUCCESS) {
        win32_throw_exception(env, get_error_message(status));
        return -1;
    }

    return info.dwType;
}
Esempio n. 25
0
File: pdh.c Progetto: 40a/sigar
JNIEXPORT jstring SIGAR_JNI(win32_Pdh_pdhLookupPerfName)
(JNIEnv *env, jclass cur, jint index)
{
    TCHAR path[MAX_PATH + 1];
    DWORD len = sizeof(path) / sizeof(TCHAR); /* len is number of TCHAR's, not sizeof(path) */
    PDH_STATUS status =
        PdhLookupPerfNameByIndex(NULL, index, path, &len);

    if (status == ERROR_SUCCESS) {
        return JENV->NewString(env, (const jchar *)path, len);
    }
    else {
        win32_throw_exception(env, get_error_message(status));
        return NULL;
    }
}
Esempio n. 26
0
JNIEXPORT jlong JNICALL Java_org_hyperic_hq_plugin_mssql_PDH_pdhAddCounter(JNIEnv *env, jclass, jlong query, jstring path) {
    HCOUNTER   h_counter;
    HQUERY     h_query = (HQUERY)query;
    PDH_STATUS status;
    LPCTSTR    counter_path = (LPCTSTR)env->GetStringChars(path, NULL);

    status = PdhAddCounter(h_query, counter_path, 0, &h_counter);

    env->ReleaseStringChars(path, (const jchar *)counter_path);

	if (status != ERROR_SUCCESS) {
        plugin_throw_exception(env, get_error_message(status));
        return 0;
    }

    return (jlong)h_counter;
}
Esempio n. 27
0
void MetaLogger::meta_logger_main() {
  LOG(INFO) << "Meta-logger started";
  while (!stop_requested_) {
    {
      uint64_t demand = control_block_->logger_wakeup_.acquire_ticket();
      if (!stop_requested_ && !control_block_->has_waiting_log()) {
        VLOG(0) << "Meta-logger going to sleep";
        control_block_->logger_wakeup_.timedwait(demand, 100000ULL);
      }
    }
    VLOG(0) << "Meta-logger woke up";
    if (stop_requested_) {
      break;
    } else if (!control_block_->has_waiting_log()) {
      continue;
    }

    // we observed buffer_used_ > 0 BEFORE the fence. Now we can read buffer_ safely.
    assorted::memory_fence_acq_rel();
    ASSERT_ND(control_block_->buffer_used_ > 0);
    uint32_t write_size = sizeof(control_block_->buffer_);
    ASSERT_ND(control_block_->buffer_used_ <= write_size);
    LOG(INFO) << "Meta-logger got a log (" << control_block_->buffer_used_ << " b) to write out";
    FillerLogType* filler = reinterpret_cast<FillerLogType*>(
      control_block_->buffer_ + control_block_->buffer_used_);
    filler->populate(write_size - control_block_->buffer_used_);
    ErrorCode er = current_file_->write_raw(write_size, control_block_->buffer_);
    if (er != kErrorCodeOk) {
      LOG(FATAL) << "Meta-logger couldn't write a log. error=" << get_error_message(er)
        << ", os_error=" << assorted::os_error();
    }

    // also fsync on the file and parent. every, single, time.
    // we don't care performance on metadata logger. just make it simple and robust.
    bool synced = fs::fsync(current_file_->get_path(), true);
    if (!synced) {
      LOG(FATAL) << "Meta-logger couldn't fsync. os_error=" << assorted::os_error();
    }
    assorted::memory_fence_release();
    control_block_->buffer_used_ = 0;
    assorted::memory_fence_release();
    control_block_->durable_offset_ += write_size;
  }
  LOG(INFO) << "Meta-logger terminated";
}
Esempio n. 28
0
 void SharedData::audit_key_name(std::string name) const {
   if (name.empty()) {
     IMP_RMF_THROW("Empty key name", UsageException);
   }
   static const char *illegal="\\:=()[]{}\"'";
   const char *cur=illegal;
   while (*cur != '\0') {
     if (name.find(*cur) != std::string::npos) {
       IMP_RMF_THROW(get_error_message("Key names can't contain ",
                                       *cur), UsageException);
     }
     ++cur;
   }
   if (name.find("  ") != std::string::npos) {
     IMP_RMF_THROW("Key names can't contain two consecutive spaces",
                   UsageException);
   }
 }
Esempio n. 29
0
File: pdh.c Progetto: 40a/sigar
JNIEXPORT jint SIGAR_JNI(win32_Pdh_pdhLookupPerfIndex)
(JNIEnv *env, jclass cur, jstring jname)
{
    DWORD index;
    LPCTSTR name =
        JENV->GetStringChars(env, jname, NULL);
    PDH_STATUS status =
        PdhLookupPerfIndexByNameW(NULL, name, &index);

    JENV->ReleaseStringChars(env, jname, name);

    if (status == ERROR_SUCCESS) {
        return index;
    }
    else {
        win32_throw_exception(env, get_error_message(status));
        return -1;
    }
}
Esempio n. 30
0
// PDO error handler for the environment context.
bool pdo_sqlsrv_handle_env_error( sqlsrv_context& ctx, unsigned int sqlsrv_error_code, bool warning TSRMLS_DC, 
                                  va_list* print_args )
{
    SQLSRV_ASSERT(( ctx != NULL ), "pdo_sqlsrv_handle_env_error: sqlsrv_context was null" );
    pdo_dbh_t* dbh = reinterpret_cast<pdo_dbh_t*>( ctx.driver());    
    SQLSRV_ASSERT(( dbh != NULL ), "pdo_sqlsrv_handle_env_error: pdo_dbh_t was null" );
    
    sqlsrv_error_auto_ptr error;

    if( sqlsrv_error_code != SQLSRV_ERROR_ODBC ) {

        core_sqlsrv_format_driver_error( ctx, get_error_message( sqlsrv_error_code ), error, SEV_ERROR TSRMLS_CC, print_args );
    }
    else {

        bool err = core_sqlsrv_get_odbc_error( ctx, 1, error, SEV_ERROR TSRMLS_CC );
        SQLSRV_ASSERT( err == true, "No ODBC error was found" );
    }

    strcpy_s( dbh->error_code, sizeof( pdo_error_type ), reinterpret_cast<const char*>( error->sqlstate ));

    switch( dbh->error_mode ) {

        case PDO_ERRMODE_EXCEPTION:
            if( !warning ) {

                pdo_sqlsrv_throw_exception( error TSRMLS_CC );
            }
            ctx.set_last_error( error );
            break;

        default:
            DIE( "pdo_sqlsrv_handle_env_error: Unexpected error mode. %1!d!", dbh->error_mode );
            break;
    }
    
    // we don't transfer the zval_auto_ptr since set_last_error increments the zval ref count
    // return error ignored = true for warnings.
    return ( warning ? true : false );

}