We theoretically investigate selective coupling of superconducting charge qubits mediated by a superconducting stripline cavity with a tunable resonance frequency. The frequency control is provided by a flux biased dc-SQUID attached to the cavity. Selective entanglement of the qubit states is achieved by sweeping the cavity frequency through the qubit-cavity resonances. The circuit is able to accommodate several qubits and allows to keep the qubits at their optimal points with respect to decoherence during the whole operation. We derive an effective quantum Hamiltonian for the basic, two-qubit-cavity system, and analyze appropriate circuit parameters. We present a protocol for performing Bell inequality measurements, and discuss a composite pulse sequence generating a universal control-phase gate.Coherent coupling of superconducting qubits has been experimentally demonstrated for all major qubit types (charge 1,2 , flux 3,4,5 , and phase 6,7 qubits) using permanent direct qubit-qubit coupling, capacitive or inductive. A major challenge is to implement a tunable coupling of qubits required for any useful gate operation. Numerous suggestions in this direction have been discussed in recent literature together with related quantum gate protocols (for a review see, e.g. Ref. 8).There are two conceptually different approaches to the tunable coupling. The first approach is to employ direct coupling schemes using Josephson junctions in the non-resonant regime as passive controllable elements, either capacitive, 9 or inductive. 10,11,12,13,14 The second approach, which we adopt in this paper, suggests qubit coupling via a dynamic intermediate element, e.g., LCoscillator or Josephson junction, which becomes entangled with a qubit during a two-qubit operation. In this scheme, the entanglement is achieved by tuning the qubit and the mediator in resonance, and then transferring the entanglement to another qubit by tuning the mediator and the second qubit in the resonance. Such coupling method has been first suggested 15 and experimentally tested 16 for the ion trap qubits. For superconducting qubits, qubit-oscillator entanglement has been demonstrated experimentally for a charge qubit coupled to a microwave stripline cavity, 17 and a flux qubit coupled to a SQUID oscillator;18,19 the gate protocols based on controllable qubit-oscillator coupling have been theoretically discussed in Refs. 20,21.The experimental setup with the qubit coupling to a distributed oscillator -stripline cavity 17,22 possesses potential for scalability -several qubits can be coupled to the cavity. In this paper we investigate the possibility to use this setup for implementation of tunable qubit-qubit coupling and simple gate operations. Tunable qubitcavity coupling is achieved by varying the cavity frequency by controlling magnetic flux through a dc-SQUID attached to the cavity (see Fig. 1). An advantage of this method is the possibility to keep the qubits at the optimal points with respect to decoherence during the whole two-qubit operation. The qubi...