If the idea suits you, check out the gazebo/physics/Gripper.cc example where fix joints are created. For detecting the contact use a contact sensor, here is a tutorial.