当前位置: 编程技术>综合
本页文章导读:
▪ubuntu下通过wine安装source insight 最近在用宿主机Windows中的source insight看disksim的源代码,然后大部分操作又需要在Ubuntu里面完成,切换有点不方便,然后就在网上找Linux中源代码的查看工具,先是在Ubuntu中安装了一个Source-Navig.........
▪linux ioctl使用实验 本文是我在andoid实验的ioctl的功能,如双向传递参数。贴出来希望对学习ioctl的人很有帮助。
linux的ioctl功能是很强大的,android显示模块还有camera模块都离不开ioctl.........
▪org.hibernate.NonUniqueObjectException 今天在为项目进行单元测试时,使用hibernate的update方法,出现如下异常:
org.hibernate.NonUniqueObjectException: a different object with the same identifier value was already associated with the session:
org.hibernate.engine.i.........
[1]ubuntu下通过wine安装source insight
来源: 互联网 发布时间: 2013-11-10
最近在用宿主机Windows中的source insight看disksim的源代码,然后大部分操作又需要在Ubuntu里面完成,切换有点不方便,然后就在网上找Linux中源代码的查看工具,先是在Ubuntu中安装了一个Source-Navigator,但是感觉界面看起来没有Source-insight看得舒服,但是遗憾的是Ubuntu里面好像没有Source-insight这个工具,只能通过在wine里面安装。以下是安装步骤:
1、sudo apt-get install wine
2、将Windows中的InsightSetup.exe以及keygen.exe拷贝到Ubuntu中(存放在/home/hs/下载/Source-insight)
3、wine /home/hs/下载/Source-insight/InsightSetup.exe,然后安装步骤与在Windows中相同
4、wine /home/hs/下载/Source-insight/keygen.exe,生成一个序列号
OK.That is all.
作者:hs794502825 发表于2013-1-12 15:45:59 原文链接
阅读:44 评论:0 查看评论
[2]linux ioctl使用实验
来源: 互联网 发布时间: 2013-11-10
本文是我在andoid实验的ioctl的功能,如双向传递参数。贴出来希望对学习ioctl的人很有帮助。
linux的ioctl功能是很强大的,android显示模块还有camera模块都离不开ioctl让上层和内核交互。
board中添加platform_devce
static struct ioctl_test_platform_data ioctl_pdata = {
static struct ioctl_test_platform_data ioctl_pdata = {
.gpio=17,
};
static struct platform_device msm_device_ioctl = {
.name = "gpio_test",
.id = -1,
.dev = {
.platform_data = &ioctl_pdata,
},
};
头文件:
ioctl_test.h
#ifndef IOCTL_TEST_H
#define IOCTL_TEST_H
/* platform data from board file */
struct ioctl_test_platform_data{
u16 gpio;
};
struct gpio_priv_t {
int gpio;
int state0;
int state1;
int state2;
int state3;
};
#define GPIO_TEST_IOC_MAGIC 0x92
#define GPIO_TEST_SET_HIGH _IO(GPIO_TEST_IOC_MAGIC, 1)
#define GPIO_TEST_SET_LOW _IO(GPIO_TEST_IOC_MAGIC, 2)
#define GPIO_TEST_WRITE_STRUCT _IOW(GPIO_TEST_IOC_MAGIC, 3,struct gpio_priv_t *)
#define GPIO_TEST_WRITE_INT _IOW(GPIO_TEST_IOC_MAGIC, 4,unsigned int *)
#define GPIO_TEST_READ_STRUCT _IOR(GPIO_TEST_IOC_MAGIC, 5,struct gpio_priv_t *)
#define GPIO_TEST_READ_INT _IOR(GPIO_TEST_IOC_MAGIC, 6,unsigned int *)
#endif
driver:
生成设备节点:/dev/gpio_test
ioctl_test.c
#define pr_fmt(fmt) "%s: " fmt, __func__
#include <linux/init.h>
#include <linux/module.h>
#include <linux/fs.h>
#include <linux/slab.h>
#include <linux/miscdevice.h>
#include <linux/delay.h>
#include <linux/io.h>
#include <linux/uaccess.h>
#include <linux/regulator/consumer.h>
#include <linux/platform_device.h>
#include <linux/mutex.h>
#include <mach/gpio.h>
#include<linux/ioctl_test.h>
static struct gpio_priv_t *gpio_priv;
static int gpio_test_open(struct inode *inode, struct file *filp)
{
if (gpio_priv == NULL)
return -ENODEV;
filp->private_data = gpio_priv;
return 0;
}
static int gpio_test_release(struct inode *inode, struct file *filp)
{
filp->private_data = NULL;
return 0;
}
static long
gpio_test_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
{
int err = 0;
void __user *argp = (void __user *)arg;
int value0;
int value1 ;
/* Verify user arguments. */
if (_IOC_TYPE(cmd) != GPIO_TEST_IOC_MAGIC)
return -ENOTTY;
switch (cmd) {
case GPIO_TEST_SET_HIGH:
printk("GPIO_TEST_SET_HIGH\n");
if (arg == 0) {
pr_err("user space arg not supplied\n");
err = -EFAULT;
break;
}
gpio_set_value(17,1);
break;
case GPIO_TEST_SET_LOW:
printk("GPIO_TEST_SET_LOW\n");
if (arg == 0) {
pr_err("user space arg not supplied\n");
err = -EFAULT;
break;
}
gpio_set_value(17,0);
break;
case GPIO_TEST_WRITE_STRUCT:
printk("GPIO_TEST_WRITE\n");
if (copy_from_user(gpio_priv, argp, sizeof(struct gpio_priv_t)))
return -EFAULT;
printk("gpio_priv->state0=%d\n",gpio_priv->state0);
printk("gpio_priv->state1=%d\n",gpio_priv->state1);
printk("gpio_priv->state2=%d\n",gpio_priv->state2);
break;
case GPIO_TEST_READ_STRUCT:
printk("GPIO_TEST_READ\n");
gpio_priv->state0=1;
gpio_priv->state1=2;
gpio_priv->state2=3;
if (copy_to_user(argp, gpio_priv, sizeof(struct gpio_priv_t)))
return -EFAULT;
break;
case GPIO_TEST_WRITE_INT:
printk("GPIO_TEST_WRITE_INT\n");
if(copy_from_user(&value0,argp,sizeof(int)))
return -EFAULT;
printk("value0 = %d\n",value0);
break;
case GPIO_TEST_READ_INT:
printk("GPIO_TEST_READ_INT\n");
value1=101;
if (copy_to_user(argp, &value1, sizeof(int)))
return -EFAULT;
break;
default:
pr_err("Invalid ioctl command.\n");
return -ENOTTY;
}
return err;
}
static const struct file_operations gpio_test_fops = {
.owner = THIS_MODULE,
.unlocked_ioctl = gpio_test_ioctl,
.open = gpio_test_open,
.release = gpio_test_release
};
static struct miscdevice gpio_test_dev = {
.minor = MISC_DYNAMIC_MINOR,
.name = "gpio_test",
.fops = &gpio_test_fops
};
static int gpio_test_probe(struct platform_device *pdev)
{
int ret = 0;
printk("gpio_test_probe 0\n");
/* Initialize */
gpio_priv = kzalloc(sizeof(struct gpio_priv_t), GFP_KERNEL);
if (gpio_priv == NULL) {
pr_alert("Not enough memory to initialize device\n");
return -ENOMEM;
}
ret = misc_register(&gpio_test_dev);
if (ret < 0)
goto err;
return 0;
err:
printk("gpio_test register failed\n");
kfree(gpio_priv);
gpio_priv = NULL;
return ret;
}
static int __devexit gpio_test_remove(struct platform_device *plat)
{
kfree(gpio_priv);
gpio_priv = NULL;
misc_deregister(&gpio_test_dev);
printk("gpio_test remove\n");
return 0;
}
static struct platform_driver gpio_test_driver = {
.probe = gpio_test_probe,
.remove = gpio_test_remove,
.driver = {
.name = "gpio_test",
.owner = THIS_MODULE,
},
};
static int __init gpio_test_init(void)
{
printk("
linux的ioctl功能是很强大的,android显示模块还有camera模块都离不开ioctl让上层和内核交互。
board中添加platform_devce
static struct ioctl_test_platform_data ioctl_pdata = {
static struct ioctl_test_platform_data ioctl_pdata = {
.gpio=17,
};
static struct platform_device msm_device_ioctl = {
.name = "gpio_test",
.id = -1,
.dev = {
.platform_data = &ioctl_pdata,
},
};
头文件:
ioctl_test.h
#ifndef IOCTL_TEST_H
#define IOCTL_TEST_H
/* platform data from board file */
struct ioctl_test_platform_data{
u16 gpio;
};
struct gpio_priv_t {
int gpio;
int state0;
int state1;
int state2;
int state3;
};
#define GPIO_TEST_IOC_MAGIC 0x92
#define GPIO_TEST_SET_HIGH _IO(GPIO_TEST_IOC_MAGIC, 1)
#define GPIO_TEST_SET_LOW _IO(GPIO_TEST_IOC_MAGIC, 2)
#define GPIO_TEST_WRITE_STRUCT _IOW(GPIO_TEST_IOC_MAGIC, 3,struct gpio_priv_t *)
#define GPIO_TEST_WRITE_INT _IOW(GPIO_TEST_IOC_MAGIC, 4,unsigned int *)
#define GPIO_TEST_READ_STRUCT _IOR(GPIO_TEST_IOC_MAGIC, 5,struct gpio_priv_t *)
#define GPIO_TEST_READ_INT _IOR(GPIO_TEST_IOC_MAGIC, 6,unsigned int *)
#endif
driver:
生成设备节点:/dev/gpio_test
ioctl_test.c
#define pr_fmt(fmt) "%s: " fmt, __func__
#include <linux/init.h>
#include <linux/module.h>
#include <linux/fs.h>
#include <linux/slab.h>
#include <linux/miscdevice.h>
#include <linux/delay.h>
#include <linux/io.h>
#include <linux/uaccess.h>
#include <linux/regulator/consumer.h>
#include <linux/platform_device.h>
#include <linux/mutex.h>
#include <mach/gpio.h>
#include<linux/ioctl_test.h>
static struct gpio_priv_t *gpio_priv;
static int gpio_test_open(struct inode *inode, struct file *filp)
{
if (gpio_priv == NULL)
return -ENODEV;
filp->private_data = gpio_priv;
return 0;
}
static int gpio_test_release(struct inode *inode, struct file *filp)
{
filp->private_data = NULL;
return 0;
}
static long
gpio_test_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
{
int err = 0;
void __user *argp = (void __user *)arg;
int value0;
int value1 ;
/* Verify user arguments. */
if (_IOC_TYPE(cmd) != GPIO_TEST_IOC_MAGIC)
return -ENOTTY;
switch (cmd) {
case GPIO_TEST_SET_HIGH:
printk("GPIO_TEST_SET_HIGH\n");
if (arg == 0) {
pr_err("user space arg not supplied\n");
err = -EFAULT;
break;
}
gpio_set_value(17,1);
break;
case GPIO_TEST_SET_LOW:
printk("GPIO_TEST_SET_LOW\n");
if (arg == 0) {
pr_err("user space arg not supplied\n");
err = -EFAULT;
break;
}
gpio_set_value(17,0);
break;
case GPIO_TEST_WRITE_STRUCT:
printk("GPIO_TEST_WRITE\n");
if (copy_from_user(gpio_priv, argp, sizeof(struct gpio_priv_t)))
return -EFAULT;
printk("gpio_priv->state0=%d\n",gpio_priv->state0);
printk("gpio_priv->state1=%d\n",gpio_priv->state1);
printk("gpio_priv->state2=%d\n",gpio_priv->state2);
break;
case GPIO_TEST_READ_STRUCT:
printk("GPIO_TEST_READ\n");
gpio_priv->state0=1;
gpio_priv->state1=2;
gpio_priv->state2=3;
if (copy_to_user(argp, gpio_priv, sizeof(struct gpio_priv_t)))
return -EFAULT;
break;
case GPIO_TEST_WRITE_INT:
printk("GPIO_TEST_WRITE_INT\n");
if(copy_from_user(&value0,argp,sizeof(int)))
return -EFAULT;
printk("value0 = %d\n",value0);
break;
case GPIO_TEST_READ_INT:
printk("GPIO_TEST_READ_INT\n");
value1=101;
if (copy_to_user(argp, &value1, sizeof(int)))
return -EFAULT;
break;
default:
pr_err("Invalid ioctl command.\n");
return -ENOTTY;
}
return err;
}
static const struct file_operations gpio_test_fops = {
.owner = THIS_MODULE,
.unlocked_ioctl = gpio_test_ioctl,
.open = gpio_test_open,
.release = gpio_test_release
};
static struct miscdevice gpio_test_dev = {
.minor = MISC_DYNAMIC_MINOR,
.name = "gpio_test",
.fops = &gpio_test_fops
};
static int gpio_test_probe(struct platform_device *pdev)
{
int ret = 0;
printk("gpio_test_probe 0\n");
/* Initialize */
gpio_priv = kzalloc(sizeof(struct gpio_priv_t), GFP_KERNEL);
if (gpio_priv == NULL) {
pr_alert("Not enough memory to initialize device\n");
return -ENOMEM;
}
ret = misc_register(&gpio_test_dev);
if (ret < 0)
goto err;
return 0;
err:
printk("gpio_test register failed\n");
kfree(gpio_priv);
gpio_priv = NULL;
return ret;
}
static int __devexit gpio_test_remove(struct platform_device *plat)
{
kfree(gpio_priv);
gpio_priv = NULL;
misc_deregister(&gpio_test_dev);
printk("gpio_test remove\n");
return 0;
}
static struct platform_driver gpio_test_driver = {
.probe = gpio_test_probe,
.remove = gpio_test_remove,
.driver = {
.name = "gpio_test",
.owner = THIS_MODULE,
},
};
static int __init gpio_test_init(void)
{
printk("
[3]org.hibernate.NonUniqueObjectException
今天在为项目进行单元测试时,使用hibernate的update方法,出现如下异常:
org.hibernate.NonUniqueObjectException: a different object with the same identifier value was already associated with the session:
org.hibernate.engine.internal.StatefulPersistenceContext.checkUniqueness(StatefulPersistenceContext.java:689)
at org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.performUpdate(DefaultSaveOrUpdateEventListener.java:293)
at org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.entityIsDetached(DefaultSaveOrUpdateEventListener.java:239)
at org.hibernate.event.internal.DefaultUpdateEventListener.performSaveOrUpdate(DefaultUpdateEventListener.java:55)
at org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:90)
at org.hibernate.internal.SessionImpl.fireUpdate(SessionImpl.java:775)
at org.hibernate.internal.SessionImpl.update(SessionImpl.java:767)
at org.hibernate.internal.SessionImpl.update(SessionImpl.java:763)
……
根据异常信息,我们可以知道在hibernate中,同一个session中存在两个不同的实体,但是这两个实体的标识却是相同的。也就是说:在session中有两个不同的对象关联了同一个标识。
解决方案一:
在使用update方法之前,创建另一个session或者使用evice方法删除持久化对象,使其状态转变为游离态
注:效率不高
解决方案二:
即然是根据标识更新对象,那么我们只需要修改我们需要修改的字段。既使用同一个对象。
已有 0 人发表留言,猛击->>这里<<-参与讨论
ITeye推荐
org.hibernate.NonUniqueObjectException: a different object with the same identifier value was already associated with the session:
org.hibernate.engine.internal.StatefulPersistenceContext.checkUniqueness(StatefulPersistenceContext.java:689)
at org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.performUpdate(DefaultSaveOrUpdateEventListener.java:293)
at org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.entityIsDetached(DefaultSaveOrUpdateEventListener.java:239)
at org.hibernate.event.internal.DefaultUpdateEventListener.performSaveOrUpdate(DefaultUpdateEventListener.java:55)
at org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:90)
at org.hibernate.internal.SessionImpl.fireUpdate(SessionImpl.java:775)
at org.hibernate.internal.SessionImpl.update(SessionImpl.java:767)
at org.hibernate.internal.SessionImpl.update(SessionImpl.java:763)
……
根据异常信息,我们可以知道在hibernate中,同一个session中存在两个不同的实体,但是这两个实体的标识却是相同的。也就是说:在session中有两个不同的对象关联了同一个标识。
解决方案一:
在使用update方法之前,创建另一个session或者使用evice方法删除持久化对象,使其状态转变为游离态
注:效率不高
解决方案二:
即然是根据标识更新对象,那么我们只需要修改我们需要修改的字段。既使用同一个对象。
已有 0 人发表留言,猛击->>这里<<-参与讨论
ITeye推荐
- —软件人才免语言低担保 赴美带薪读研!—
最新技术文章: