Example #1
0
// This function inititalize the freenect library, selects the motor and camera subdevices and begins the event processing loop.
// Event processing occurs in a go routine that will be terminated upon a call to Shutdown()
func Initialize() (*Freenect, int) {
	if _freenect != nil {
		return nil, -999
	}

	var ctx *C.freenect_context
	rc := int(C.freenect_init(&ctx, nil))

	if rc != 0 {
		return nil, rc
	}

	C.freenect_select_subdevices(ctx, (C.freenect_device_flags)(C.FREENECT_DEVICE_MOTOR|C.FREENECT_DEVICE_CAMERA))

	d := int(C.freenect_num_devices(ctx))
	_freenect = &Freenect{ctx, nil, make([]Device, d)}

	for x := 0; x < d; x++ {
		_freenect.Devices[x].index = x
		_freenect.Devices[x].freenect = _freenect
	}

	go func() {
		var to C.struct_timeval
		to.tv_sec = 0
		to.tv_usec = 0
		rc := C.int(0)
		for _freenect != nil && rc >= 0 {
			rc = C.freenect_process_events_timeout(_freenect.ctx, &to)
		}
	}()

	return _freenect, 0
}
Example #2
0
// Result()
// take care to free LdapMessage result with MsgFree()
//
func (self *Ldap) Result() (*LdapMessage, error) {

	var msgid int = 1
	var all int = 1

	var tv C.struct_timeval
	tv.tv_sec = 30

	var msg *C.LDAPMessage

	// API: int ldap_result( LDAP *ld, int msgid, int all, struct timeval *timeout, LDAPMessage **result );
	rv := C.ldap_result(self.conn, C.int(msgid), C.int(all), &tv, &msg)

	if rv != LDAP_OPT_SUCCESS {
		return nil, errors.New(fmt.Sprintf("LDAP::Result() error :  %d (%s)", rv, ErrorToString(int(rv))))
	}

	_msg := new(LdapMessage)
	_msg.ldap = self
	_msg.errno = int(rv)
	_msg.msg = msg

	return _msg, nil
}